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

feat(cli): Support location filters for suites #7048

Conversation

mzhubail
Copy link
Contributor

@mzhubail mzhubail commented Dec 8, 2024

Description

Closes #5445.

This is a continuation on my previous PR #6411, with support for matching location of suite.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

- The jest of it is that we have a stricter matching mode, when a test
  location is passed:

  ```ts
  if (testLocations !== undefined && testLocations.length !== 0) {
  ```

  We have three cases to deal with:

  1. Parent did match via location filter, and as such this test is
      marked to run. No Questions asked.

  2. This test / suite does match via location filter, and as such mark
      it to run, and do the same for its children.

  3. No match. In this case I'd mark as skipped only it is a test. (if
      it's a suite, I still want to go through its children)
Copy link

netlify bot commented Dec 8, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a1b7384
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67553d307ed0470008246de5
😎 Deploy Preview https://deploy-preview-7048--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mzhubail
Copy link
Contributor Author

mzhubail commented Dec 8, 2024

  • The jest of it is that we have a stricter matching mode, when a test location is passed:

    if (testLocations !== undefined && testLocations.length !== 0) {

    We have three cases to deal with:

    1. Parent did match via location filter, and as such this test is marked to run. No Questions asked.

    2. This test / suite does match via location filter, and as such mark it to run, and do the same for its children.

    3. No match. In this case I'd mark as skipped only it is a test. (if it's a suite, I still want to go through its children)

  • if (t.location && testLocations?.includes(t.location.line)) {
    t.mode = 'run'
    matchedLocations.push(t.location.line)
    hasLocationMatch = true
    }
    else if (parentMatchedWithLocation) {

    Note that I set the case of test matching before parentMatchedWithLocation to avoid printing wrong output on an edge case. See

    test('handles matching test inside a suite', async () => {
    If we had the condition parentMatchedWithLocation before, this test cases would report test not found.

@sheremet-va sheremet-va merged commit 751e2dc into vitest-dev:main Dec 9, 2024
17 checks passed
@sheremet-va
Copy link
Member

Thanks!

@mzhubail mzhubail deleted the feature/cli-support-location-filters-for-suites branch December 9, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support specifying a line number when filtering tests
2 participants