-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add testNamePatterns param to run() #46522
Conversation
Review requested:
|
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.
Start looks fine, all the lint errors inside GH make this a bit hard to review but +1 on the initiative and working on the feature.
Note you missed passing stuff down (in line 240 when doing new Test
, see the test failures)
[support request] Fail test files:
Fail test message: In all these failing tests we have a test: I take a look into common.mustNotCall() and it returns a function that always ends with so.. if I understood correctly, I could say this test will never pass, am I correct? |
|
I know, my changes broke it of course, but sorry, maybe I'm not been clear, my question is more related to understanding why it can't be called to help me to debug it. I'm debugging to fix it, but understanding a little bit more about this test could help me to fix I faster, you know but i think i already found what's wrong... i will work on this soon |
At least one issue is likely this line: testNamePatterns.concat(testNamePatternsFromCLI);
|
update: I'm taking few days off for canival, i will finalize tihs pr this week |
56a71bc
to
69681f7
Compare
83fd79a
to
2287515
Compare
@benjamingr @cjihrig @recrack @ljharb |
A function argument that can't be accepted depending of some logic restriction. | ||
e.g. The function `run(...)` from module `node:test` can't accept `testNamePatterns` | ||
param from programatic function and from CLI at same time. <a id="ERR_ARG_NOT_ITERABLE"></a> |
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.
A function argument that can't be accepted depending of some logic restriction. | |
e.g. The function `run(...)` from module `node:test` can't accept `testNamePatterns` | |
param from programatic function and from CLI at same time. <a id="ERR_ARG_NOT_ITERABLE"></a> | |
A function argument that can't be accepted depending of some logic restriction. |
@@ -960,6 +960,7 @@ module.exports = { | |||
// Note: Node.js specific errors must begin with the prefix ERR_ | |||
|
|||
E('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError); | |||
E('ERR_ARG_NOT_ALLOWED', '%s is already being assigned', Error); |
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.
I can see people being confused by this error message (I was when first reading it, and I have the context of this PR).
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.
I'd use ERR_INVALID_ARG_TYPE
@@ -42,6 +43,7 @@ const { | |||
kEmptyObject, | |||
once: runOnce, | |||
} = require('internal/util'); | |||
const { ObjectHasOwn } = primordials; |
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.
Please add this where primordials
is already destructured above (and keep the list sorted)
@@ -163,9 +165,16 @@ class Test extends AsyncResource { | |||
constructor(options) { | |||
super('Test'); | |||
|
|||
let { fn, name, parent, skip } = options; | |||
let { fn, name, parent, skip, testNamePatterns: _testNamePatterns } = options; |
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.
let { fn, name, parent, skip, testNamePatterns: _testNamePatterns } = options; | |
let { fn, name, parent, skip, testNamePatterns: testNamePatternsArg } = options; |
const { concurrency, only, timeout, todo, signal } = options; | ||
|
||
if (ObjectHasOwn(options, '_testNamePatterns') && testNamePatterns) { | ||
throw new ERR_ARG_NOT_ALLOWED('testNamePatterns'); |
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.
I think we need a test added for the case where the user tries to specify both.
@@ -163,9 +165,16 @@ class Test extends AsyncResource { | |||
constructor(options) { | |||
super('Test'); | |||
|
|||
let { fn, name, parent, skip } = options; | |||
let { fn, name, parent, skip, testNamePatterns: _testNamePatterns } = options; |
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.
We need input validation on this new option, as well as tests for the validation.
{ | ||
// Return only test that maches with the filter | ||
const args = ['--test', '--test-name-pattern="too"', join(testFixtures, 'test/random.cjs')]; | ||
const child = spawnSync('./node', args); |
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.
const child = spawnSync('./node', args); | |
const child = spawnSync(process.execPath, args); |
|
||
{ | ||
// Return only test that maches with the filter | ||
const args = ['--test', '--test-name-pattern="too"', join(testFixtures, 'test/random.cjs')]; |
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.
We already have tests for the CLI flag. I'm not sure why this is being added.
@@ -8,6 +8,17 @@ const testFixtures = fixtures.path('test-runner'); | |||
|
|||
describe('require(\'node:test\').run', { concurrency: true }, () => { | |||
|
|||
it('should not throw error', async () => { |
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.
What is this test trying to accomplish? It seems like it could be dropped.
closing this PR, i don't want to work on this anymore |
@italojs thanks for the effort! |
fix: #46045
WIP: implementing unit tests
Comments about the implementation is welcome