-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1823 from openzim/sanitize-double-used-cli-parameter
Stop script and throw error if used same cli parameter twice
- Loading branch information
Showing
4 changed files
with
62 additions
and
2 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
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
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,47 @@ | ||
import { sanitize_all } from '../../src/sanitize-argument.js' | ||
|
||
describe('Sanitize parameters', () => { | ||
test('sanitizing usage of the same parameter more than one time', async () => { | ||
// equivalent to command: node lib/cli.js --verbose --mwUrl="https://en.wikipedia.org" --adminEmail="[email protected]" --verbose=info | ||
const twoVerboseParameters = { | ||
_: [], | ||
verbose: [true, 'info'], | ||
mwUrl: 'https://en.wikipedia.org', | ||
'mw-url': 'https://en.wikipedia.org', | ||
adminEmail: '[email protected]', | ||
'admin-email': '[email protected]', | ||
$0: 'node_modules/ts-node/dist/child/child-entrypoint.js', | ||
} | ||
|
||
await expect(sanitize_all(twoVerboseParameters)).rejects.toThrow(/Parameter '--verbose' can only be used once/) | ||
|
||
// equivalent to command: node lib/cli.js --verbose --mwUrl="https://en.wikipedia.org" --adminEmail="[email protected]" --mwUrl="https://en.wikipedia.org" | ||
const twoUrlParameters = { | ||
_: [], | ||
verbose: true, | ||
mwUrl: ['https://en.wikipedia.org', 'https://en.wikipedia.org'], | ||
'mw-url': ['https://en.wikipedia.org', 'https://en.wikipedia.org'], | ||
adminEmail: '[email protected]', | ||
'admin-email': '[email protected]', | ||
$0: 'node_modules/ts-node/dist/child/child-entrypoint.js', | ||
} | ||
|
||
await expect(sanitize_all(twoUrlParameters)).rejects.toThrow(/Parameter '--mwUrl' can only be used once/) | ||
|
||
// equivalent to command: node lib/cli.js --verbose=info --adminEmail="[email protected]" --articleList="User:Kelson/MWoffliner_CI_reference" --mwUrl="https://en.m.wikipedia.org/" --format=nopic --format=nopdf --format=novid | ||
const threeFormatParameters = { | ||
_: [], | ||
verbose: 'info', | ||
adminEmail: '[email protected]', | ||
'admin-email': '[email protected]', | ||
articleList: 'User:Kelson/MWoffliner_CI_reference', | ||
'article-list': 'User:Kelson/MWoffliner_CI_reference', | ||
mwUrl: 'https://en.m.wikipedia.org/', | ||
'mw-url': 'https://en.m.wikipedia.org/', | ||
format: ['nopic', 'nopdf', 'novid'], | ||
$0: 'node_modules/ts-node/dist/child/child-entrypoint.js', | ||
} | ||
|
||
expect(await sanitize_all(threeFormatParameters)).toBeUndefined() | ||
}) | ||
}) |