-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update pattern for
ignore
paths in config schema (#5)
- Loading branch information
Showing
4 changed files
with
153 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import Ajv, { ErrorObject } from 'ajv'; | ||
import schema from '../../config.schema.json'; | ||
import { Options as ParsedArgs } from '../../src'; | ||
|
||
const ajv = new Ajv(); | ||
|
||
const validate = (data: Partial<ParsedArgs>) => { | ||
ajv.validate(schema, data); | ||
|
||
return ajv.errors ?? []; | ||
}; | ||
|
||
type TestCase = [data: Partial<ParsedArgs>, expectedErrors: ErrorObject[]]; | ||
|
||
describe('config schema', () => { | ||
it.each<string>([ | ||
'|', | ||
'|@commitlint/cli>@commitlint/lint>@commitlint/rules>@commitlint/ensure', | ||
'|@commitlint/cli', | ||
'|meow>@commitlint/cli', | ||
'1|', | ||
'1|>', | ||
'1|a>', | ||
'1|a>b>', | ||
'1|a>>b>>c', | ||
'1|abc> asasdf1|df>asdf>', | ||
'abc|gulp>vinyl-fs>glob-stream>glob>minimatch', | ||
'abc|ember-cli>testem>socket.io>socket.io-parser>debug', | ||
'abc|socket.io>socket.io-parser' | ||
])('fails "%s"', invalidPath => { | ||
const invalidPathError: ErrorObject = { | ||
keyword: 'pattern', | ||
dataPath: '/ignore/0', | ||
schemaPath: '#/properties/ignore/items/pattern', | ||
params: { pattern: expect.any(String) as string }, | ||
message: expect.stringContaining('should match pattern') as string | ||
}; | ||
|
||
expect(validate({ ignore: [invalidPath] })).toStrictEqual([ | ||
invalidPathError | ||
]); | ||
}); | ||
|
||
it.each<string>([ | ||
'1|a', | ||
'1|a>b', | ||
'1|a>b>c', | ||
'1|abc', | ||
'1|abc>a', | ||
'118|gulp>vinyl-fs>glob-stream>glob>minimatch', | ||
'813|css-loader>cssnano>postcss-svgo>svgo>js-yaml', | ||
'1084|webpack>yargs>os-locale>mem', | ||
'1500|webpack>yargs>yargs-parser', | ||
'1523|gulp>vinyl-fs>glob-watcher>gaze>globule>lodash', | ||
'534|ember-cli>testem>socket.io>socket.io-parser>debug', | ||
'577|ember-cli>ember-try>cli-table2>lodash', | ||
'577|ember-cli>ember-try>cli-table2', | ||
'577|cli-table2', | ||
'534|ember-cli>testem>socket.io>socket.io-parser', | ||
'534|socket.io>socket.io-parser', | ||
'534|socket.io-parser', | ||
'1523|@commitlint/cli>@commitlint/lint>@commitlint/rules>@commitlint/ensure', | ||
'1523|@commitlint/cli', | ||
'1523|meow>@commitlint/cli' | ||
])('allows "%s"', validPath => { | ||
expect(validate({ ignore: [validPath] })).toStrictEqual([]); | ||
}); | ||
|
||
// misc cases | ||
it.each<TestCase>([ | ||
[ | ||
// @ts-expect-error this is not a supported value | ||
{ packageManager: 'invalid' }, | ||
[ | ||
{ | ||
keyword: 'enum', | ||
dataPath: '/packageManager', | ||
schemaPath: '#/definitions/SupportedPackageManagerOrAuto/enum', | ||
params: { allowedValues: ['auto', 'npm', 'yarn', 'pnpm'] }, | ||
message: 'should be equal to one of the allowed values' | ||
} | ||
] | ||
] | ||
])('validates as expected', (data, expectedErrors) => { | ||
expect(validate(data)).toStrictEqual(expectedErrors); | ||
}); | ||
}); |