diff --git a/scripts/__tests__/verify-i18n-bundle-args.test.mjs b/scripts/__tests__/verify-i18n-bundle-args.test.mjs new file mode 100644 index 000000000..f1340c3d5 --- /dev/null +++ b/scripts/__tests__/verify-i18n-bundle-args.test.mjs @@ -0,0 +1,30 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { test } from 'node:test'; + +const HERE = dirname(fileURLToPath(import.meta.url)); +const SCRIPT = resolve(HERE, '..', 'verify-i18n-bundle.mjs'); + +function run(args) { + return spawnSync(process.execPath, [SCRIPT, ...args], { + encoding: 'utf8', + }); +} + +test('verify-i18n-bundle --dist rejects a missing path before filesystem checks', () => { + const result = run(['--dist']); + + assert.equal(result.status, 2, result.stderr); + assert.match(result.stderr, /--dist requires a path/); + assert.doesNotMatch(result.stderr, /dist directory does not exist/); +}); + +test('verify-i18n-bundle --dist rejects another flag as the path value', () => { + const result = run(['--dist', '--help']); + + assert.equal(result.status, 2, result.stderr); + assert.match(result.stderr, /--dist requires a path/); + assert.doesNotMatch(result.stderr, /dist directory does not exist/); +}); diff --git a/scripts/verify-i18n-bundle.mjs b/scripts/verify-i18n-bundle.mjs index 2e02d0e34..9e124a95f 100644 --- a/scripts/verify-i18n-bundle.mjs +++ b/scripts/verify-i18n-bundle.mjs @@ -10,7 +10,7 @@ for (let i = 2; i < process.argv.length; i += 1) { const arg = process.argv[i]; if (arg === "--dist") { const value = process.argv[i + 1]; - if (!value) { + if (!value || value.startsWith("-")) { console.error("verify-i18n-bundle: --dist requires a path"); process.exit(2); }