diff --git a/lib/node-arguments.js b/lib/node-arguments.js index 65da7c5d9..7848a0304 100644 --- a/lib/node-arguments.js +++ b/lib/node-arguments.js @@ -5,7 +5,11 @@ import {tokenizeArgs} from 'args-tokenizer'; export default function normalizeNodeArguments(fromConf = [], fromArgv = '') { let parsedArgv = []; if (fromArgv !== '') { - parsedArgv = tokenizeArgs(fromArgv); + try { + parsedArgv = tokenizeArgs(fromArgv); + } catch { + throw new Error('Could not parse `--node-arguments` value. Make sure all strings are closed and backslashes are used correctly.'); + } } return [...process.execArgv, ...fromConf, ...parsedArgv]; diff --git a/package-lock.json b/package-lock.json index d430b0b9b..840ff800d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "acorn": "^8.13.0", "acorn-walk": "^8.3.4", "ansi-styles": "^6.2.1", - "args-tokenizer": "^0.2.1", + "args-tokenizer": "^0.3.0", "arrify": "^3.0.0", "callsites": "^4.2.0", "cbor": "^9.0.2", @@ -3020,9 +3020,9 @@ } }, "node_modules/args-tokenizer": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/args-tokenizer/-/args-tokenizer-0.2.1.tgz", - "integrity": "sha512-1hd00qLJxfSYLirIJherrIBbLkpYlLttu2lxQvVJWY+ohZgEZ2Sf9Rnsx5C1kQNo22eb9tV8/l8TWpjYKtwNIw==", + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/args-tokenizer/-/args-tokenizer-0.3.0.tgz", + "integrity": "sha512-xXAd7G2Mll5W8uo37GETpQ2VrE84M181Z7ugHFGQnJZ50M2mbOv0osSZ9VsSgPfJQ+LVG0prSi0th+ELMsno7Q==", "license": "MIT" }, "node_modules/array-buffer-byte-length": { diff --git a/package.json b/package.json index b72309651..32df09e6b 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "acorn": "^8.13.0", "acorn-walk": "^8.3.4", "ansi-styles": "^6.2.1", - "args-tokenizer": "^0.2.1", + "args-tokenizer": "^0.3.0", "arrify": "^3.0.0", "callsites": "^4.2.0", "cbor": "^9.0.2", @@ -151,6 +151,5 @@ }, "volta": { "node": "22.10.0" - }, - "packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c" + } } diff --git a/test/node-arguments/snapshots/test.js.md b/test/node-arguments/snapshots/test.js.md index 7c8cc54ea..9fdb63532 100644 --- a/test/node-arguments/snapshots/test.js.md +++ b/test/node-arguments/snapshots/test.js.md @@ -37,11 +37,11 @@ Generated by [AVA](https://avajs.dev). }, ] -## forgive incomplete --node-arguments +## detects incomplete --node-arguments -> tests pass +> fails with message - [] + 'Could not parse `--node-arguments` value. Make sure all strings are closed and backslashes are used correctly.' ## reads node arguments from config diff --git a/test/node-arguments/snapshots/test.js.snap b/test/node-arguments/snapshots/test.js.snap index c908e36a2..bbccccf41 100644 Binary files a/test/node-arguments/snapshots/test.js.snap and b/test/node-arguments/snapshots/test.js.snap differ diff --git a/test/node-arguments/test.js b/test/node-arguments/test.js index cdf6d8410..92134a0f7 100644 --- a/test/node-arguments/test.js +++ b/test/node-arguments/test.js @@ -1,6 +1,6 @@ import test from '@ava/test'; -import {cwd, fixture} from '../helpers/exec.js'; +import {cleanOutput, cwd, fixture} from '../helpers/exec.js'; test('passed node arguments to workers', async t => { const options = { @@ -33,14 +33,14 @@ test('`filterNodeArgumentsForWorkerThreads` configuration ignored for worker pro t.snapshot(result.stats.passed, 'tests pass'); }); -test('forgive incomplete --node-arguments', async t => { +test('detects incomplete --node-arguments', async t => { const options = { cwd: cwd('node-arguments'), }; const result = await t.throwsAsync(fixture(['--node-arguments="--foo=\'bar"', 'node-arguments.js'], options)); - t.snapshot(result.stats.passed, 'tests pass'); + t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); test('reads node arguments from config', async t => {