-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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: In-source testing #45771
Comments
const {inlineTest, describe, it} = require('node:test');
if (inlineTest) {
describe("Array", () => {
describe("#indexOf()", () => {
it("should return -1 when the value is not present", () => {
assert.strictEqual([1, 2, 3].indexOf(4), -1)
})
})
})
} |
This would import the whole module, though. I was trying to avoid that, and it's the reason Vitest has a similar API (though it's ESM only). Perhaps we could use properties on |
So if I understand correctly if we ran |
I am closing as wont do, feel free to reopen if you intend to work on this |
So you'd consider merging a prototype? I can give it a try if we can reach consensus on an import syntax, though it's be easier to discuss this if you could reopen the issue. |
@nickmccurdy do you have any update on this? If not, I propose closing the issue. That wouldn't stop you from working on it if you really want to see this happen. |
No follow up for two weeks. Closing. |
What is the problem this feature will solve?
In-source tests let you write some tests in the same files as their implementation.
Vitest's explanation:
Building this into Node would also have the advantage of letting tutorials and examples for Node users show tests in the same files.
What is the feature you are proposing to solve the problem?
A
--test-source
flag that will run any Node files and expose thetest
function viaimport.meta.test
(as importing it could cause it to be accidentally bundled).The rest of the
node:test
module could also be exposed as properties of theimport.meta.test
function.What alternatives have you considered?
The text was updated successfully, but these errors were encountered: