Open ficu88 opened 3 weeks ago
Same here, specifying file path patterns through shell or using explicit filename works ok.
Reverting to .js files for tests for now
Same here, specifying file path patterns through shell or using explicit filename works ok.
Reverting to .js files for tests for now
how did you manage to solve with file path pattern?
i tried both tsx --test **/*.test.?[cm][jt]s
and tsx --test '**/*.test.?[cm][jt]s'
without success.
Thank you
Issues is a place for discussing solutions that can land in tsx.
As per the Contribution guide, please avoid discussing work arounds here.
If you can investigate a solution, please open a PR
@ficu88 are you on a version of Node before v21? I'm on v20 and get the same behavior. From the description in the PR that adds test runner support, the feature only works on Node v21 and above.
If that's correct, perhaps the "fix" is to amend the docs to mention the Node version requirements for the test runner integration.
Side note for the maintainer: Respectfully the two comments marked as off-topic were helpful for me. For those who can't upgrade to Node v21+ any workaround is useful!
are you on a version of Node before v21?
See the reproduction Node version:
❯ node -v
v18.20.3
If that's correct, perhaps the "fix" is to amend the docs to mention the Node version requirements for the test runner integration.
Happy to accept a PR, would you be open to working on one?
Respectfully the two comments marked as off-topic were helpful for me. For those who can't upgrade to Node v21+ any workaround is useful!
As a maintainer, my priority is to serve sponsors first, then contributors, and finally users.
For sponsors needing a workaround, I'm happy to offer support directly via the sponsors-only repo.
The Issues tab is a place for contributors to collaborate and fix bugs to benefit all tsx users, and it's distracting/unproductive when the thread is polluted with workaround noise by non-contributors.
I opened #665 but I couldn't find any instructions for how to contribute to docs specifically. So I don't know how to validate my changes.
I maintain a completely free open source library on my own time so it's not realistic for me to sponsor. I'm sure there are many others in similar situations who are really happy with tsx, but can't upgrade their node version for whatever reason.
So for those people here's what I used until I can upgrade Node.js and make use of the built-in support in tsx. And who knows, it might be useful as inspiration for a similar feature in this repo.
// test/index.ts
import { glob } from 'glob'
import { run } from 'node:test';
import { spec } from 'node:test/reporters';
import { fileURLToPath } from 'url';
// Replacement for tsx's "test runner" feature until we can upgrade the project's minimum Node.js version to v21+.
// https://github.com/privatenumber/tsx/issues/663
const parentDir = fileURLToPath(new URL('./', import.meta.url));
const files = await glob(`${parentDir}/**/*.test.ts`)
run({files})
.on('test:fail', () => {
process.exitCode = 1;
})
.compose(new spec())
.pipe(process.stdout);
Then tsx works splendidly with npx tsx test/index.ts
@berniegp Thanks for your contribution, but I want to address a couple of concerns.
First, I'm genuinely confused by your decision to disregard the guidelines I clearly outlined regarding workarounds in Issues. I took the time to explain the reasoning behind these rules, and it feels disrespectful that you chose to ignore them. Please understand that these rules are in place to keep discussions focused and productive towards landing a fix that benefits everyone.
Additionally, your PR #665 appears incomplete as you didn't test it yourself, which creates unnecessary work on my end. Moving forward, please ensure that any contributions you make are fully tested and ready for review.
I'm happy to collaborate on landing a fix, but please keep responses relevant to that goal. Consider this a warning before further action is taken. Please respect the project guidelines. Thanks for understanding.
As I wrote above, I added my workaround info above for 2 reasons:
I'm sorry you feel I disregarded the guidelines.
Regarding my PR, I didn't test it my PR because I couldn't find how from reading https://github.com/privatenumber/tsx/blob/master/CONTRIBUTING.md. There's no mention of contributing to the docs there.
You asked for a PR and I provided one, in my free time, to the best of my abilities. And I transparently let you know I couldn't find out how to test it so I think your comment above is uncalled for.
Thanks for the tool and best of luck in future.
Node LTS v.20 here
I run tests. For the following file tree:
src/
commands.test.js
this works:
$ node --test src # is successfully executing the `src/commands.test.js` tests
However for a similar TS location:
src/
commands.test.ts
tsx doesn't find test files:
$ npx tsx --test src # is finding 0 tests
Yet if I pass the path it works:
$ npx tsx --test src/commands.test.ts # is successfully executing the `src/commands.test.ts` tests
$ npx tsx --test src/*.test.ts # is successfully executing the `src/commands.test.ts` tests
There is no such issue for Node v.21, but we're on the LTS Node v.20.
So it seems to be a test files discovery issue. Maybe it's worth adding the appropriate info to the docs here?
Yeah, feel free to open a PR to update the docs.
Explanation is in the PR: https://github.com/privatenumber/tsx/pull/410#issue-2007959217
Acknowledgements
Minimal reproduction URL
https://stackblitz.com/edit/node-hzy2ii?file=package.json,bar.test.ts
Problem & expected behavior (under 200 words)
When you run
tsx --test
, the filebar.test.ts
is not executed.https://tsx.is/node-enhancement#test-runner
Bugs are expected to be fixed by those affected by it
Compensating engineering work will speed up resolution and support the project