Skip to content
Open
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
16 changes: 8 additions & 8 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -27,7 +28,7 @@
"shielded": "./dist/bin.js"
},
"dependencies": {
"commander": "^12.0.0",
"commander": "^15.0.0",
"node-fetch": "^2.6.13"
}
}
49 changes: 49 additions & 0 deletions src/flags.test.ts
Original file line number Diff line number Diff line change
@@ -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 <url>'));
assert.ok(result.stdout.includes('-c, --color <color>'));
assert.ok(result.stdout.includes('-T, --title <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);
});