diff --git a/package-lock.json b/package-lock.json index f591d65..7e61003 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.2.0", "license": "MIT", "dependencies": { - "commander": "^12.0.0", + "commander": "^15.0.0", "node-fetch": "^2.6.13" }, "bin": { @@ -548,11 +548,11 @@ } }, "node_modules/commander": { - "version": "12.1.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", - "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-15.0.0.tgz", + "integrity": "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg==", "engines": { - "node": ">=18" + "node": ">=22.12.0" } }, "node_modules/concat-map": { @@ -2094,9 +2094,9 @@ } }, "commander": { - "version": "12.1.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", - "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==" + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-15.0.0.tgz", + "integrity": "sha512-z67u4ZhzCL/Tydu1lJARtEZYWbWaN7oYLHbsuzocr6y4N6WZAagG3RQ4FW61V1/0+jImpj293XfrcYnd1qxtPg==" }, "concat-map": { "version": "0.0.1", diff --git a/package.json b/package.json index f7da7c3..43b4464 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "description": "Shielded.dev JS SDK", "main": "dist/sdk.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "npm run test:flags", "build": "tsc && chmod +x dist/bin.js", - "lint": "npx eslint ." + "lint": "npx eslint .", + "test:flags": "npm run build && node --test dist/flags.test.js" }, "author": { "name": "Jesse G. Donat", @@ -27,7 +28,7 @@ "shielded": "./dist/bin.js" }, "dependencies": { - "commander": "^12.0.0", + "commander": "^15.0.0", "node-fetch": "^2.6.13" } } diff --git a/src/flags.test.ts b/src/flags.test.ts new file mode 100644 index 0000000..4f05a3c --- /dev/null +++ b/src/flags.test.ts @@ -0,0 +1,49 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import path from 'node:path'; +import test from 'node:test'; + +const binPath = path.resolve(__dirname, 'bin.js'); +const CLI_TEST_TIMEOUT = 5000; +const parseErrorPattern = /error:\s+(unknown option|too many arguments|missing required argument)/i; + +const runCli = (args: string[]) => spawnSync(process.execPath, [binPath, ...args], { +encoding: 'utf8', +env: { +...process.env, +SHIELDED_TOKEN: 'test-token' +}, +timeout: CLI_TEST_TIMEOUT +}); + +void test('help output includes all defined flags', () => { +const result = runCli(['--help']); + +assert.equal(result.status, 0); +assert.ok(result.stdout.includes('-e, --endpoint ')); +assert.ok(result.stdout.includes('-c, --color ')); +assert.ok(result.stdout.includes('-T, --title ')); +assert.ok(result.stdout.includes('-x, --text <text>')); +}); + +void test('long-form flags parse without commander errors', () => { +const result = runCli([ +'--endpoint', 'http://127.0.0.1:9', +'--color', '00AA33', +'--title', 'Last Build', +'--text', 'ok' +]); + +assert.doesNotMatch(`${result.stdout}\n${result.stderr}`, parseErrorPattern); +}); + +void test('short-form flags parse without commander errors', () => { +const result = runCli([ +'-e', 'http://127.0.0.1:9', +'-c', '00AA33', +'-T', 'Last Build', +'-x', 'ok' +]); + +assert.doesNotMatch(`${result.stdout}\n${result.stderr}`, parseErrorPattern); +});