Skip to content

Commit

Permalink
Update test scripts and remove fast-glob dependency for validating pa…
Browse files Browse the repository at this point in the history
…tterns
  • Loading branch information
msudgh committed Mar 2, 2024
1 parent 062fd81 commit c504138
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 39 deletions.
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"build": "rm -rf ./dist && tsc -p tsconfig.build.json",
"build:watch": "tsc -p tsconfig.build.json -w",
"build:type-check": "tsc -p tsconfig.build.json --noEmit",
"test": "node --trace-warnings --experimental-vm-modules 'node_modules/jest/bin/jest.js' .",
"test:watch": "node --trace-warnings --experimental-vm-modules 'node_modules/jest/bin/jest.js' . --watch",
"test:coverage": "node --trace-warnings --experimental-vm-modules 'node_modules/jest/bin/jest.js' . --no-cache --coverage",
"test": "node --trace-warnings --experimental-vm-modules 'node_modules/jest/bin/jest.js'",
"test:watch": "node --trace-warnings --experimental-vm-modules 'node_modules/jest/bin/jest.js' --watch",
"test:coverage": "node --trace-warnings --experimental-vm-modules 'node_modules/jest/bin/jest.js' --no-cache --coverage",
"format": "prettier --write \"**/*.{ts,js,md,json,yaml,yml}\"",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand Down Expand Up @@ -64,21 +64,19 @@
"dependencies": {
"@aws-sdk/client-s3": "3.511.0",
"@aws-sdk/lib-storage": "3.511.0",
"fast-glob": "^3.3.2",
"globby": "^14.0.1",
"mrmime": "2.0.0",
"winston": "^3.11.0",
"zod": "3.22.4"
},
"lint-staged": {
"*.ts": [
"(/test/.*\\.test\\.ts)$": [
"npm run test"
],
"*.{ts,js}": [
"npm run lint",
"npm run format"
"npm run lint"
],
"*.{json,md,yaml}": [
"*.{ts,js,json,md,yaml}": [
"npm run format"
]
}
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions src/schemas/input.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { ObjectCannedACL } from '@aws-sdk/client-s3'
import type { ObjectCannedACL as ObjectCannedACLType } from '@aws-sdk/client-s3'
// import fg from 'fast-glob'
import { z } from 'zod'

// function isGlobbyPattern(pattern: string): boolean {
// return fg.isDynamicPattern(pattern)
// }

type ObjectCannedACLsTuple = [ObjectCannedACLType, ...ObjectCannedACLType[]]

// Cast to ObjectCannedACLsTuple
Expand All @@ -18,14 +13,8 @@ const tags = z.record(z.string(), z.string())

const storage = z.object({
name: z.string(),
// Ref: https://github.com/mrmlnc/fast-glob#pattern-syntax
patterns: z.array(z.string()).min(1),
// .refine((patterns) => patterns.every(isGlobbyPattern), {
// // https://github.com/mrmlnc/fast-glob#pattern-syntax
// // `patterns` is an array of glob patterns. Each pattern must be a valid
// // glob pattern. A glob pattern is a string of literal and special
// // characters used to match file paths.
// message: 'Patterns must be compatible with glob pattern syntax.',
// }),
actions: z.array(z.string()).default(['upload', 'delete']),
prefix: z.string().default(''),
enabled: z.boolean().default(true),
Expand Down
5 changes: 0 additions & 5 deletions test/schemas/input.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ export const createValidInputFileFixture = (): Required<Custom> => {
return baseInputFixture
}

export const createValidInputDirectoryFixture = (): Required<Custom> => {
const baseInputFixture = createBaseInputFixture()
return baseInputFixture
}

export const createInvalidInputFixture = (
additionalProps: DeepPartial<Custom> = {}
) => ({
Expand Down
16 changes: 5 additions & 11 deletions test/schemas/input.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import {
createInvalidInputFixture,
createValidInputDirectoryFixture,
createValidInputFileFixture,
} from './input.fixture'
import { custom } from '../../src/schemas/input'

describe('Input Custom Schema', () => {
it('should validate the generated fake data', () => {
const fileInput = createValidInputFileFixture()
const result1 = custom.safeParse(fileInput)
const input = createValidInputFileFixture()
const result = custom.safeParse(input)

expect(result1.success).toBe(true)

const directoryInput = createValidInputDirectoryFixture()
const result2 = custom.safeParse(directoryInput)

expect(result2.success).toBe(true)
expect(result.success).toBe(true)
})

it('should throw an error if the data is invalid', () => {
const fakeData = createInvalidInputFixture()
const result = custom.safeParse(fakeData)
const invalidInput = createInvalidInputFixture()
const result = custom.safeParse(invalidInput)

expect(result.success).toBe(false)
})
Expand Down

0 comments on commit c504138

Please sign in to comment.