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

Allow passing --include on the CLI? #4861

Closed
4 tasks done
JoshuaKGoldberg opened this issue Jan 3, 2024 · 4 comments
Closed
4 tasks done

Allow passing --include on the CLI? #4861

JoshuaKGoldberg opened this issue Jan 3, 2024 · 4 comments
Labels
p3-significant High priority enhancement (priority)

Comments

@JoshuaKGoldberg
Copy link
Contributor

Clear and concise description of the problem

Right now, there's no documented way I could find to specify the include config option with the CLI. Would the project be open to adding an --include CLI option?

Suggested solution

Being able to run vitest --include 'some/globs'.

--exclude support was added in #4148 -> #4279. I suppose this proposal is roughly the same idea.

Alternative

In the meantime, we can -t to specify on test names. But it'd be nice to go by file name.

Additional context

My use case is a project that has a few end-to-end tests defined with Vitest. Each of those tests runs a lot of commands and modifies the current directory. So being able to run e.g. pnpm run test:e2e:create that calls `vitest --include

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Jan 3, 2024

Can't you just pass it down as a filter? The terminal usually handles it before Vitest ever needs to.

vitest **/some-glob.ts

Alternatively you can just pass down any substring:

vitest tests-folder/e2e

@JoshuaKGoldberg
Copy link
Contributor Author

Ah, that makes sense. I don't know why I didn't think of that as an implicit --include. Thanks! 😄

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 18, 2024
@sheremet-va sheremet-va reopened this Mar 26, 2024
@sheremet-va sheremet-va added the p3-significant High priority enhancement (priority) label Mar 26, 2024
@sheremet-va
Copy link
Member

vitest **/some-glob.ts will limit the filter to files inside include and exclude patterns, so this is not a full replacement. See: #5348 (reply in thread)

@sheremet-va
Copy link
Member

We believe that it's better to use a workspace feature to organize your Vitest configuration:

import { defineWorkspace } from 'vitest/config'

export default defineWorkspace([
  {
    test: {
      include: ['tests/**/*.unit.test.ts'],
      name: 'unit',
      environment: 'happy-dom',
    }
  },
  {
    test: {
      include: ['tests/**/*.e2e.test.ts'],
      name: 'e2e',
      environment: 'node',
    }
  }
])

You can then run it as vitest --project=e2e.

For that reason, as a team, we decided that it's better to wait until there is more demand for this feature (CLI --include).

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-significant High priority enhancement (priority)
Projects
Archived in project
Development

No branches or pull requests

2 participants