-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Test runner matching every .ts and .js if glob is not provided #56546
Comments
It matches the files because they are under a |
As correctly pointed out by @targos, this behaviour is intended. IMHO, it is common to have test helpers/fixtures under the test directory. |
Mocha also checks for a |
I think executing only |
I agree that a huge breaking change. But I'm also convinced that |
Without changing the default behaviour, perhaps a flag Normally the positional args would be fine, but if using with "scripts": {
"test": "node --test 'dist/test/*.spec.js'"
} npm test -- --test-only 'dist/test/some-folder/*.spec.js' In this case, the Alternatively, allowing flags after positionals would also work, but the default pattern flag would be nice if you could additionally pass in a test name to run only that file instead of eg.
running Not sure how feasible that is, but something like that behaviour would be nice. Related: #51384 |
As supected unflagging experimental-strip-types in v22 is a breaking change because it will execute .ts if glob is not provided. Ideas? |
I don't think there is a scenario where you can execute any additional files and be able to guarantee it won't break anyone. IMO the benefit to unflagging in the same way as v23 is worth it. I think users will be far more annoyed by the lack of "easy" TypeScript support in the test runner for the rest of v22's lifetime than they will be over possibly having to rename fixtures one time. |
FWIW, we didn't backport globs in the test runner to v20 because there was a remote chance that the glob would match some existing pattern. In retrospect, I think that was a massive mistake (which we could technically still rectify), as it introduced hard to work around changes between v20 and v22. I don't think we should make the same mistake here. |
Possible options are:
|
There are other options too (ignore a |
I thin the main problem I heard users talkabout are:
Another issue is that there is no way to run the same command to exclude .ts files in v20 and v22 (Immagine a library supporting v20 and v22 running tests, v22 enables typescript and they have to disable it, they cannot use the same command for v22 and v20 because requires glob and they cant --no-experimental-strip-types) |
Or backport glob to v20 there is a special semver minor in v20 coming could be a good time 😃 |
+1000 to backporting globs to v20. |
It needs a volunteer to do the manual backport |
+1 to backborting globs to v20 I needed for my project. my package support v20 but isn't tested on it because we specify tests using glob |
#47653 is the change that needs to be backported. |
But its a semver major 🫨 I dont think its possible then |
Yea, that's what I was referring to in #56546 (comment). If we are aiming for 100% guaranteed non-breaking behavior then we can't backport that or process However, I don't believe that option is what is best for end users. If one person has a filename containing an asterisk, I don't think that's worth keeping globs out of v20 🤷 |
Pinging @nodejs/tsc as this is a tricky situation |
It's worth noting that |
The focus seems to be on test fixtures which happen to be TypeScript files. This is an edge case. I feel like this discussion is missing the most important context: The most basic TypeScript setup. An example of such a project is TypeScript has historically been and still is a compile-time language. You compile it to JavaScript, you then run the emitted JavaScript code. This is no different for tests.
In this project {
"scripts": {
"prepack": "tsc --build",
"pretest": "tsc --build",
"test": "node --test --enable-source-maps"
}
} With the new glob pattern, not only
With Node.js supporting TypeScript files, TypeScript is no longer just a compile-time language. You need a different TypeScript configuration. You need to compile source files, but not tests. I imagine a project layout like this:
The problem is, the first setup works with projects using Node.js versions up to 22. The second setup works with projects using Node.js 23 and greater. Libraries however, need to run tests against multiple Node.js versions. Many libraries are still even compatible with Node.js versions that are EOL. Breaking compatibility with a Node.js version, even if it’s EOL, would require a semver major release of the library. Some vague ideas I have:
|
Thanks for the input @remcohaszing!
I agree that this is important and that we should minimize differences in test discovery between versions.
I think the easiest way to accomplish this and address the previous point is to just backport glob support to v20. Unfortunately, since it's semver major, the TSC would need to bless that. |
I definitely agree backporting glob support to v20 would be a great idea. However, this still means you can’t test a library against versions 16, 18, 20, 22, and 23 with the same setup. I personally test against even majors only, so I really read version 23 as some future version. Although I guess it’s a somewhat acceptable middle ground to delay testing against Node.js 24 until I decide to drop support for Node.js 18. The odds of JavaScript-only packages breaking in newer Node.js versions are relatively small. |
16 is EOL and afaik does not have the test runner and 18 is EOL in 1 month. |
Node.js 16 does have the test runner. I’m aware it’s EOL, that’s my point. I absolutely push for people to use modern Node.js versions. But for a library removing support for an EOL Node.js version is still a breaking change. Node.js going EOL shouldn’t mean all npm packages have to make a semver major release. This can be decided on a per-package basis. Note that I’m not saying libraries should support every Node.js version indefinitely, but there’s a middle ground somewhere. |
v16 is experimental so it does really matter. I disagree we should care about EOL versions or libraries supporting EOL version. And honestly its a very niche issue. |
I would argue most packages support EOL Node.js versions during some points in their lifetime, often several versions. Of course you may draw your own conclusions from this, but I wouldn’t say this is a niche. |
Would allowing flags to come after positional glob / file patterns in the test runner resolve these issues? |
This is the reason why I created https://www.npmjs.com/package/borp among others: standardizing the test runner across multiple Node.js versions, ts supports and a few other bits. I'm happy to:
Or we could just use the npm |
I opened a PR to change the standard glob for .ts |
It would be great to put the
The problem is that globs don't exist at all in v20. It wouldn't be a different glob strategy. |
Just something that we didn't take a look is what other runtime does. |
Version
Test on v23.6.0 and v22.10.0
Platform
Subsystem
test_runner
What steps will reproduce the bug?
Consider this folder structure:
When running
node --test
the test runner will execute./test/fixtures/boom.js
.In v23 it will also execute
./test/fixtures/boom.ts
, since--experimental-strip-types
has been unflagged.Error: boom
at Object. (/Users/marcoippolito/Documents/projects/test/test/fixtures/boom.js:1:7)
at Module._compile (node:internal/modules/cjs/loader:1739:14)
at Object..js (node:internal/modules/cjs/loader:1904:10)
at Module.load (node:internal/modules/cjs/loader:1473:32)
at Function._load (node:internal/modules/cjs/loader:1285:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:151:5)
at node:internal/main/run_main_module:33:47
Node.js v23.6.0
✖ test/fixtures/boom.js (36.07275ms)
'test failed'
/Users/marcoippolito/Documents/projects/test/test/fixtures/boom.ts:1
throw new Error('boom TS');
^
Error: boom TS
at Object. (/Users/marcoippolito/Documents/projects/test/test/fixtures/boom.ts:1:7)
at Module._compile (node:internal/modules/cjs/loader:1739:14)
at Object.loadTS [as .ts] (node:internal/modules/cjs/loader:1831:10)
at Module.load (node:internal/modules/cjs/loader:1473:32)
at Function._load (node:internal/modules/cjs/loader:1285:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:151:5)
at node:internal/main/run_main_module:33:47
Node.js v23.6.0
✖ test/fixtures/boom.ts (62.136209ms)
'test failed'
✔ should return true (0.3725ms)
ℹ tests 3
ℹ suites 0
ℹ pass 1
ℹ fail 2
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 72.075583
✖ failing tests:
test at test/fixtures/boom.js:1:1
✖ test/fixtures/boom.js (36.07275ms)
'test failed'
test at test/fixtures/boom.ts:1:1
✖ test/fixtures/boom.ts (62.136209ms)
'test failed'
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
Maybe this is intended behavior but I'd would expect matching
.test.js
.I think it's an undesired side effect to execute everything.
I immagine breakages due to a lot of
.ts
fixtures being executed.What do you see instead?
Everything is executed.
Additional information
I know changing this would be a breaking change, but I dont think it's sane as it is.
The text was updated successfully, but these errors were encountered: