Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore unknown command line arguments #201

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/size-limit/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function parseArgs (plugins, argv) {
} else if (arg[0] !== '-') {
args.files.push(arg)
} else if (arg !== '--json') {
throw new SizeLimitError('unknownArg', arg)
++i
}
}
return args
Expand Down
2 changes: 0 additions & 2 deletions packages/size-limit/size-limit-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const MESSAGES = {
noPackage: () =>
'Size Limit didn’t find *package.json*. ' +
'Create npm package and run Size Limit there.',
unknownArg: arg =>
`Unknown argument *${arg}*. Check command for typo and read docs.`,
argWithoutWebpack: arg =>
`Argument *--${arg}* works only with *@size-limit/webpack* plugin` +
(arg === 'why' ? '. You can add Bundle Analyzer to you own bundler.' : ''),
Expand Down
17 changes: 11 additions & 6 deletions packages/size-limit/test/__snapshots__/run.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,6 @@ exports[`run throws on time limit without time plugin 1`] = `
"
`;

exports[`run throws on unknown argument 1`] = `
" ERROR  Unknown argument --unknown.
Check command for typo and read docs.
"
`;

exports[`run throws on unknown option 1`] = `
" ERROR  Unknown option unknown in config.
Check Size Limit docs and version.
Expand Down Expand Up @@ -534,3 +528,14 @@ exports[`run works in integration test with time 1`] = `

"
`;

exports[`run works in integration test with unknown arguments 1`] = `
"
Size limit: 200 B
Size: 31 B  with all dependencies, minified and gzipped
Loading time: 10 ms on slow 3G
Running time: 1 s  on Snapdragon 410
Total time: 1.1 s

"
`;
23 changes: 23 additions & 0 deletions packages/size-limit/test/get-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ it('creates config by CLI arguments', async () => {
})
})

it('creates config from command line with unknown arguments', async () => {
expect(
await check('file', [
'--unknown',
'unknown',
'--limit',
'10',
'a.js',
'/b.js'
])
).toEqual({
cwd: fixture('file'),
checks: [
{
name: 'a.js, /b.js',
limit: '10',
sizeLimit: 10,
files: [fixture('file', 'a.js'), '/b.js']
}
]
})
})

it('supports globby and main field', async () => {
expect(await check('globby')).toEqual({
configPath: 'package.json',
Expand Down
4 changes: 2 additions & 2 deletions packages/size-limit/test/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ describe(`run`, () => {
expect(history.stderr).toMatchSnapshot()
})

it('throws on unknown argument', async () => {
expect(await error('file', ['--unknown'])).toMatchSnapshot()
it('works in integration test with unknown arguments', async () => {
expect(await check('integration', ['--unknown'])).toMatchSnapshot()
})

it('throws on --save-bundle argument without webpack', async () => {
Expand Down