Currently, this flag's behaviour is very unexpected, often resulting in silent-failure footguns, and precludes command nesting, as demonstrated in a very simple and typical CI setup:
- name: tests with coverage
run: node --run test -- --test-reporter lcovThat results in
node --test --test-reporter lcovIn most cases, --test-reporter gets lost (the lcov reporter is not enabled); in a worse case, this unexpectedly causes tests within a directory named lcov to be run.
Currently (since always):
--test receives everything after it (space-delimited).
--test currently does 2 things:
- enables the test runner
- accepts paths for the runner to consume
This is similar to another existing feature with which we want to improve interop: watch mode.
--watch currently does 2 things:
- enables
watchmode - optionally accepts 1 value to override the entrypoint
node
--watch
--watch-path ./src/**/*.ts
--watch-path ./test/**/*.tsCurrently watch has 2 flags (which are redundant):
node --watchnode --watch ./src/not-pjson-main.jsnode
--watch ./src/not-pjson-main.js
--watch-path ./src/**/*.jsThis could be simplified into just 1 --watch flag (where the default value is a single-element array of the derived entrypoint).
node --watchnode --watch ./src/not-pjson-main.jsnode --watch ./src/**/*.jsnode
--watch ./assets/**
--watch ./src/**/*.js
./src/not-pjson-main.jsAn explicit entrypoint, like all node commands, must come last and must be a relative or absolute path (not a glob/pattern).
test would then work the same way:
node --testnode --test ./src/**/*.test.jsnode
--test ./src/foo/*.test.js
--test ./src/bar/*.test.js
./src/not-pjson-main.js--watch receives a clone of --test's resolved value(s) plus --watch's own values—with 1 exception: when both test and watch modes are enabled, --watch does not include a default entrypoint (it's irrelevant and it would likely result in perf waste at best, and unexpected behaviour at worst).
All examples are sequence-independent (all within the same heading behave the same).
node
--test ./src/foo/*.test.js
--test ./src/bar/*.test.js
--watch
./src/not-pjson-main.jsnode
--watch
--test ./src/foo/*.test.js
--test ./src/bar/*.test.js
./src/not-pjson-main.jsnode
--test ./src/foo/*.test.js
--test ./src/bar/*.test.js
--watchnode
--watch
--test ./src/foo/*.test.js
--test ./src/bar/*.test.jsnode
--test ./src/foo/*.test.js
--test ./src/bar/*.test.js
--watch ./src/**/*.jsnode
--watch ./src/**/*.js
--test ./src/foo/*.test.js
--test ./src/bar/*.test.js--test is optional and optionally accepts 1 value, whose value defaults to node's built-in glob defaults (./src/**/*.test.(c|m)?(j|t)s, etc). Additional paths are supplied via a new --test-path flag:
| Description | Code sample | Resulting --test value |
|---|---|---|
| Override default |
node --test ./src/foo/*.test.js |
|
| Override default & Set additional path |
node
--test ./src/foo/*.test.js
--test-path ./src/bar/*.test.js |
|
| Defaults + Additional paths |
node
--test
--test-path ./src/foo/*.test.js
--test-path ./src/bar/*.test.js |
which reduces to only the default: |
| No defaults & Additional paths |
node
--test-path ./src/foo/*.test.js
--test-path ./src/bar/*.test.js |
|