Skip to content

Commit

Permalink
fix: update pattern for ignore paths in config schema (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Feb 15, 2021
1 parent 3d86801 commit 70ced7f
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"type": "array",
"items": {
"type": "string",
"pattern": "^\\d+\\|((?:@[a-z\\d*~-][a-z\\d*._~-]*/)?[a-z\\d~-][a-z\\d._~-]*>)+((?:@[a-z\\d*~-][a-z\\d*._~-]*/)?[a-z\\d~-][a-z\\d._~-]*)$"
"pattern": "^\\d+\\|((?:@[a-z\\d*~-][a-z\\d*._~-]*/)?[a-z\\d~-][a-z\\d._~-]*>)*?((?:@[a-z\\d*~-][a-z\\d*._~-]*/)?[a-z\\d~-][a-z\\d._~-]*)$"
}
}
},
Expand Down
72 changes: 64 additions & 8 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@types/yargs": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"ajv": "^7.1.0",
"eslint": "^7.19.0",
"eslint-config-ackama": "^2.0.1",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand Down
87 changes: 87 additions & 0 deletions test/src/schema.spec.ts
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);
});
});

0 comments on commit 70ced7f

Please # to comment.