-
-
Notifications
You must be signed in to change notification settings - Fork 5
doc(proposal): un/break --test
#13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JakobJingleheimer
wants to merge
3
commits into
main
Choose a base branch
from
proposals/unbreak-test-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,332 @@ | ||
| # Proposal: un/break `--test` | ||
|
|
||
| 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: | ||
|
|
||
| ```yaml title="unit & e2e tests" | ||
| - name: tests with coverage | ||
| run: node --run test -- --test-reporter lcov | ||
| ``` | ||
|
|
||
| That results in | ||
|
|
||
| ```sh | ||
| node --test --test-reporter lcov | ||
| ``` | ||
|
|
||
| In 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. | ||
|
|
||
| ## More info | ||
|
|
||
| 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 `watch` mode | ||
| * optionally accepts 1 value to override the entrypoint | ||
|
|
||
| `--watch-path` sets additional paths to include as well as the entrypoint. | ||
|
|
||
| ```sh | ||
| node | ||
| --watch | ||
| --watch-path ./src/**/*.ts | ||
| --watch-path ./test/**/*.ts | ||
| ``` | ||
|
|
||
| ## Proposed options | ||
|
|
||
| ### Option: n-number of `--test`s + `--watch-path` | ||
|
|
||
| `--test` is no-longer positional, accepting 1 value per occurrance of the flag. Supplying any value will override the default glob path. | ||
|
|
||
| When combined with test mode, `--watch`'s value is ignored (treated as an "on" flag) | ||
|
|
||
| `--watch-path` supplies additional paths to trigger the test-runner to re-run. | ||
|
|
||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>Description</th> | ||
| <th>Code sample</th> | ||
| <th>Resulting <code>--test</code> value</th> | ||
| </tr> | ||
| </thead> | ||
|
|
||
| <tbody> | ||
|
|
||
| <tr> | ||
| <td> | ||
| Test & watch modes enabled with defaults | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node | ||
| --test | ||
| --watch | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `**/*.test.{cjs,cts,mjs,mts,js,ts}`, [etc](https://nodejs.org/api/test.html#running-tests-from-the-command-line) | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td> | ||
| Test & watch modes enabled, overriding default | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node | ||
| --test ./src/foo/*.test.js | ||
| --watch | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `./src/foo/*.test.js` | ||
|
|
||
| </td> | ||
| </tr> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td> | ||
| Test & watch modes enabled, using default & an additional path | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node | ||
| --test | ||
| --test ./src/foo/*.test.js | ||
| --watch | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `./src/foo/*.test.js` | ||
| `**/*.test.{cjs,cts,mjs,mts,js,ts}`, [etc](https://nodejs.org/api/test.html#running-tests-from-the-command-line) | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td> | ||
| Test & watch modes enabled, multiple test paths & additional watch paths | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node | ||
| --test ./src/foo/*.test.js | ||
| --test ./src/bar/*.test.js | ||
| --watch | ||
| --watch-path ./src/quz/fixt.json | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `./src/foo/*.test.js` | ||
| `./src/bar/*.test.js` | ||
|
|
||
| In addition to changes within the graph of those test, tests will also re-run if `./src/quz/fixt.json` changes. | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| </tbody> | ||
| </table> | ||
|
|
||
| ### Option: Break all the things | ||
|
|
||
| Currently `watch` has 2 flags (which are redundant): | ||
|
|
||
| ```sh title='reads "main" etc from package.json' | ||
| node --watch | ||
| ``` | ||
| ```sh | ||
| node --watch ./src/not-pjson-main.js | ||
| ``` | ||
| ```sh | ||
| node | ||
| --watch ./src/not-pjson-main.js | ||
| --watch-path ./src/**/*.js | ||
| ``` | ||
|
|
||
| This could be simplified into just 1 `--watch` flag (where the default value is a single-element array of the derived entrypoint). | ||
|
|
||
| ```sh title='reads "main" etc from package.json' | ||
| node --watch | ||
| ``` | ||
| ```sh title='override derived entrypoint' | ||
| node --watch ./src/not-pjson-main.js | ||
| ``` | ||
| ```sh title='package.json "main" + additional paths' | ||
| node | ||
| --watch | ||
| --watch ./src/**/*.js | ||
| --watch ./src/not-pjson-main.js | ||
| ``` | ||
|
|
||
| ```sh title='use default' | ||
| node --test | ||
| ``` | ||
| ```sh title='override default with one or more paths' | ||
| node --test ./src/bar/*.test.js | ||
| ``` | ||
| ```sh title='use default with one or more additional paths' | ||
| node | ||
| --test | ||
| --test ./src/foo/*.test.js | ||
| --test ./src/bar/*.test.js | ||
| ``` | ||
|
|
||
| #### All together | ||
|
|
||
| `--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). | ||
|
|
||
| ##### Test & watch mode enabled: | ||
|
|
||
| ```sh | ||
| node | ||
| --test ./src/foo/*.test.js | ||
| --test ./src/bar/*.test.js | ||
| --watch | ||
| ``` | ||
| ```sh | ||
| node | ||
| --watch | ||
| --test ./src/foo/*.test.js | ||
| --test ./src/bar/*.test.js | ||
| ``` | ||
|
|
||
| ##### Test & watch mode enabled with _additional_ watch path: | ||
|
|
||
| ```sh | ||
| node | ||
| --test ./src/foo/*.test.js | ||
| --test ./src/bar/*.test.js | ||
| --watch ./src/something-else.js | ||
| ``` | ||
|
|
||
| ### Option: Apply `--watch`'s current design to `--test` | ||
|
|
||
| `--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: | ||
|
|
||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <th>Description</th> | ||
| <th>Code sample</th> | ||
| <th>Resulting <code>--test</code> value</th> | ||
| </tr> | ||
| </thead> | ||
|
|
||
| <tbody> | ||
|
|
||
| <tr> | ||
| <td> | ||
| Override default | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node --test ./src/foo/*.test.js | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `./src/foo/*.test.js` | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td> | ||
| Override default & Set additional path | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node | ||
| --test ./src/foo/*.test.js | ||
| --test-path ./src/bar/*.test.js | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `./src/foo/*.test.js` | ||
| `./src/bar/*.test.js` | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td> | ||
| Defaults + Additional paths | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node | ||
| --test | ||
| --test-path ./src/foo/*.test.js | ||
| --test-path ./src/bar/*.test.js | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `**/*.test.{cjs,cts,mjs,mts,js,ts}`, [etc](https://nodejs.org/api/test.html#running-tests-from-the-command-line) | ||
| ~`./src/foo/*.test.js`~ | ||
| ~`./src/bar/*.test.js`~ | ||
|
|
||
| which reduces to only the default | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td> | ||
| No defaults & Additional paths | ||
| </td> | ||
| <td> | ||
|
|
||
| ```sh | ||
| node | ||
| --test-path ./src/foo/*.test.js | ||
| --test-path ./src/bar/*.test.js | ||
| ``` | ||
|
|
||
| </td> | ||
| <td> | ||
|
|
||
| `./src/foo/*.test.js` | ||
| `./src/bar/*.test.js` | ||
|
|
||
| </td> | ||
| </tr> | ||
|
|
||
| </tbody> | ||
| </table> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: those bullet-points are about
--watch, so i think--watch-pathshould be separate