Skip to content

test_runner: improve --test-name-pattern to allow matching single test#51577

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mdrobny:feat/test-runner-match-unique-name
Mar 1, 2024
Merged

test_runner: improve --test-name-pattern to allow matching single test#51577
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mdrobny:feat/test-runner-match-unique-name

Conversation

@mdrobny

@mdrobny mdrobny commented Jan 27, 2024

Copy link
Copy Markdown
Contributor

Try to match a test by name prefixed with all its ancestors to ensure uniqueness of the name

Fixes: #46728

It adds a feature that is present in all major test runners. It's well described in this comment

It allows developers to quickly run/debug a single test e.g. from their editor


I am a first time contributor 😉

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Jan 27, 2024
Comment thread lib/internal/test_runner/test.js
Comment thread test/fixtures/test-runner/output/name_pattern.snapshot Outdated
Comment thread lib/internal/test_runner/test.js Outdated
Comment thread lib/internal/test_runner/test.js Outdated
Comment thread lib/internal/test_runner/test.js Outdated
@mdrobny mdrobny force-pushed the feat/test-runner-match-unique-name branch 2 times, most recently from 9603fec to f47b2b0 Compare January 27, 2024 16:24
@mdrobny

mdrobny commented Jan 27, 2024

Copy link
Copy Markdown
Contributor Author

I fixed too long commit message, it should pass the lint now

@MoLow

MoLow commented Jan 27, 2024

Copy link
Copy Markdown
Member

do we have a benchmark test for --test-name-pattern? the changes looks ok but I wonder what are the performance implications

@mdrobny

mdrobny commented Jan 28, 2024

Copy link
Copy Markdown
Contributor Author

@MoLow you are right, there can be negative performance implications when using --test-name-pattern flag since we must do additional regexp matching for all not matching tests.

I can try to write some naive benchmark test. So far, for 1000 test suits, I didn't observe any meaningful difference

@mdrobny

mdrobny commented Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

I experimented with benchmarking test runner with mitata package. It repeats many times the operation and does the measurements

Here is the test suite repeated 1000 times

const {describe, it} = require('node:test');

for (let i = 0; i < 1000; i++) {
  describe('describeTest', () => {
    it('itTest1', () => {});
    it('itTest2', () => {});

    describe('describeTest', () => {
      it('itTest1', () => {});
      it('itTest2', () => {});
    });
  })
}

here is the benchmark code using my locally compiled version of Node with changes from this branch

import { run, bench, group, baseline } from 'mitata';
import { spawnSync } from 'node:child_process'

const pathToLocalNode = '../../node/node';

group('test runner', () => {
  baseline('no pattern', () => {
    spawnSync(pathToLocalNode, ['--test'], { stdio: 'ignore' })
  });

  bench('with name pattern not matching any test', () => {
    spawnSync(pathToLocalNode, ['--test-name-pattern', 'nothing', '--test'], {stdio: 'ignore'})
  })

  bench('with name pattern matching all tests', () => {
    spawnSync(pathToLocalNode, ['--test-name-pattern', 'describeTest', '--test'], {stdio: 'ignore'})
  })

  bench('with name pattern matching single test', () => {
    spawnSync(pathToLocalNode, ['--test-name-pattern', 'describeTest describeTest itTest2', '--test'], { stdio: 'ignore' })
  })
});

await run();

those are the results from running benchmark on my computer (Macbook with M1 Pro)

image

Looks like there is almost no difference when using --test-name-pattern flag which is.. surprising 🤔 I expected a bit more slowness. Am I missing something in this benchmark?

@mdrobny

mdrobny commented Feb 15, 2024

Copy link
Copy Markdown
Contributor Author

@MoLow what do you think about the benchmark results?

@MoLow MoLow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. the overhead is specific for the case when using --test-name-pattern

@MoLow MoLow added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 18, 2024
@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2024
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mdrobny

mdrobny commented Feb 26, 2024

Copy link
Copy Markdown
Contributor Author

@MoLow why do you consider it a major (breaking) change? 🤔
it rather won't affect current usages of --test-name-pattern but adds support for matching single test by prefixing with all parent names.
Do you have some example in mind where this will break some current usage?

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@MoLow

MoLow commented Feb 26, 2024

Copy link
Copy Markdown
Member

@MoLow why do you consider it a major (breaking) change? 🤔 it rather won't affect current usages of --test-name-pattern but adds support for matching single test by prefixing with all parent names. Do you have some example in mind where this will break some current usage?

using the example from the documentation, added in this PR:

describe('test 1', (t) => {
  it('some test');
});

describe('test 2', (t) => {
  it('some test');
});

Starting Node.js with --test-name-pattern="test 1 some test" would match
only some test in test 1.

prior to this change, using --test-name-pattern="test 1 some test" would run no tests, and now it will run 1 test - I consider that a breaking change

@MoLow

MoLow commented Feb 26, 2024

Copy link
Copy Markdown
Member

@mdrobny please rebase this PR

@mdrobny mdrobny force-pushed the feat/test-runner-match-unique-name branch from f47b2b0 to a66c5a9 Compare February 28, 2024 15:09
@MoLow MoLow added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 28, 2024
@MoLow MoLow added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. labels Feb 29, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 29, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/51577
✔  Done loading data for nodejs/node/pull/51577
----------------------------------- PR info ------------------------------------
Title      test_runner: improve `--test-name-pattern` to allow matching single test (#51577)
Author     Michał Drobniak  (@mdrobny, first-time contributor)
Branch     mdrobny:feat/test-runner-match-unique-name -> nodejs:main
Labels     semver-major, author ready, needs-ci, test_runner
Commits    1
 - test_runner: improve `--test-name-pattern` to allow matching single test
Committers 1
 - mdrobny 
PR-URL: https://github.com/nodejs/node/pull/51577
Fixes: https://github.com/nodejs/node/issues/46728
Reviewed-By: Moshe Atlow 
Reviewed-By: Chemi Atlow 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/51577
Fixes: https://github.com/nodejs/node/issues/46728
Reviewed-By: Moshe Atlow 
Reviewed-By: Chemi Atlow 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sat, 27 Jan 2024 09:22:46 GMT
   ✔  Approvals: 2
   ✔  - Moshe Atlow (@MoLow) (TSC): https://github.com/nodejs/node/pull/51577#pullrequestreview-1908557778
   ✔  - Chemi Atlow (@atlowChemi): https://github.com/nodejs/node/pull/51577#pullrequestreview-1887168630
   ✘  semver-major requires at least 2 TSC approvals
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-02-29T10:49:29Z: https://ci.nodejs.org/job/node-test-pull-request/57498/
- Querying data for job/node-test-pull-request/57498/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/8096266840

@nodejs-github-bot nodejs-github-bot added the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Feb 29, 2024
@MoLow MoLow requested review from aduh95 and benjamingr and removed request for benjamingr February 29, 2024 12:51
@MoLow MoLow added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Mar 1, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 1, 2024
@nodejs-github-bot nodejs-github-bot merged commit 00dc6d9 into nodejs:main Mar 1, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 00dc6d9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test runner should allow specific subtest filtering, via --test-name-pattern or otherwise

6 participants