Skip to content
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

Closed

Conversation

italojs
Copy link
Contributor

@italojs italojs commented Feb 6, 2023

fix: #46045
WIP: implementing unit tests
Comments about the implementation is welcome

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added dont-land-on-v14.x needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Feb 6, 2023
@italojs italojs marked this pull request as ready for review February 9, 2023 02:39
Copy link
Member

@benjamingr benjamingr left a 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)

lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
lib/internal/test_runner/test.js Outdated Show resolved Hide resolved
lib/internal/test_runner/test.js Outdated Show resolved Hide resolved
lib/internal/test_runner/test.js Outdated Show resolved Hide resolved
lib/internal/test_runner/test.js Outdated Show resolved Hide resolved
lib/internal/test_runner/test.js Outdated Show resolved Hide resolved
lib/internal/test_runner/runner.js Show resolved Hide resolved
lib/internal/test_runner/test.js Outdated Show resolved Hide resolved
test/fixtures/test-runner/test/random.cjs Show resolved Hide resolved
@italojs
Copy link
Contributor Author

italojs commented Feb 13, 2023

[support request]
I was working on failing units tests but I got a little bit confused with why it's failing

Fail test files:

  • node/test/message/test_runner_test_name_pattern.js
  • node/test/message/test_runner_test_name_pattern_with_only.js

Fail test message:
function should not have been called at [...]test_runner_test_name_pattern.js:<lineNumber>

In all these failing tests we have a test:
test('some test name', common.mustNotCall());

I take a look into common.mustNotCall() and it returns a function that always ends with assert.fail(<msg>)

so.. if I understood correctly, I could say this test will never pass, am I correct?

@cjihrig
Copy link
Contributor

cjihrig commented Feb 13, 2023

I could say this test will never pass, am I correct?

common.mustNotCall() is used in the Node test suite to assert that a function is not called. If you're getting failures due to common.mustNotCall(), it means that the changes in this PR have broken those assertions and it would need to be fixed before we can consider merging this PR.

@italojs
Copy link
Contributor Author

italojs commented Feb 13, 2023

I could say this test will never pass, am I correct?

common.mustNotCall() is used in the Node test suite to assert that a function is not called. If you're getting failures due to common.mustNotCall(), it means that the changes in this PR have broken those assertions and it would need to be fixed before we can consider merging this PR.

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 google about it but I just found some PRs and issues that don't explain why this function cant be called when others must be called (e.g. test('some msg', common.mustCall());

I'm debugging to fix it, but understanding a little bit more about this test could help me to fix I faster, you know
a explanation, a reference of someone that understood about it, some article, anything is welcome

but i think i already found what's wrong... i will work on this soon

@cjihrig
Copy link
Contributor

cjihrig commented Feb 13, 2023

At least one issue is likely this line:

testNamePatterns.concat(testNamePatternsFromCLI);

concat() does not change the existing array, so you're creating a new array and throwing it away.

@italojs
Copy link
Contributor Author

italojs commented Feb 20, 2023

update: I'm taking few days off for canival, i will finalize tihs pr this week

@italojs italojs force-pushed the italo/run-testNamePatterns-option branch 2 times, most recently from 56a71bc to 69681f7 Compare February 24, 2023 23:17
@italojs italojs force-pushed the italo/run-testNamePatterns-option branch from 83fd79a to 2287515 Compare February 25, 2023 14:32
doc/api/errors.md Outdated Show resolved Hide resolved
@italojs
Copy link
Contributor Author

italojs commented Mar 11, 2023

@benjamingr @cjihrig @recrack @ljharb
I think it's done, all checks is passing, it was an interesting "good first issue" I learned a lot about nodejs structure and coverage, and I saw some new contributions opportunity while I was doing it and learned more about nodejs
Thanks for your patience with who was reviewing it :)

Comment on lines +704 to +706
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Contributor

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).

Copy link
Member

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

lib/internal/test_runner/runner.js Show resolved Hide resolved
@@ -42,6 +43,7 @@ const {
kEmptyObject,
once: runOnce,
} = require('internal/util');
const { ObjectHasOwn } = primordials;
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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');
Copy link
Contributor

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;
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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')];
Copy link
Contributor

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 () => {
Copy link
Contributor

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.

@italojs
Copy link
Contributor Author

italojs commented Apr 9, 2023

closing this PR, i don't want to work on this anymore

@italojs italojs closed this Apr 9, 2023
@MoLow
Copy link
Member

MoLow commented Apr 9, 2023

@italojs thanks for the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support --test-name-pattern in run()
8 participants