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

fix: add possibility to filter test files by fileName #1915

Merged
merged 3 commits into from Sep 1, 2022

Conversation

bartoszgolebiowski
Copy link
Contributor

Hello,

fix #1797

I have created PR with a new option for "node-vite".
I added to vitest config new property "fileNamePattern", it is similar to "testNamePattern"
It is responsible for skipping test files when the pattern does not match.
I added documentation for "fileNamePattern" next to "testNamePattern" property.
I added additional information for the CLI help option about the new property.
I added a test case to check if the new functionality works as expected.

To test it you can:

  1. test/core/vitest.config.ts -> remove "fileNamePattern" property. -> it will fail because I added failing file-name-pattern.test.ts
  2. pnpm run test -p .test -> it will fail because I added failing file-name-pattern.test.ts

@bartoszgolebiowski
Copy link
Contributor Author

bartoszgolebiowski commented Aug 24, 2022

failing on check: CI / test (windows-latest, 16), examples/playwright
I think this is not related to my changes.

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

I don't like basing solution on testNamePattern. We can already define a pattern for tests with include.

If you just want to add -p option to CLI, you can call this.rerunFiles with a new set of files, filtered by the new pattern.

@bartoszgolebiowski
Copy link
Contributor Author

Hello,

I added a new folder test-skip, which is used to create the test scenario to check if filtering works correctly.
I set fileNamePattern: '/core/test/',
Due to that it will match all tests inside the test folder, and will not match tests inside the test-skip folder.
I could not find any other method to create a test for this scenario, but I am open to discuss.

According to your review, I have updated the changeFilenamePattern method to filter files array and pass results to this.rerunFiles

@sheremet-va
Copy link
Member

According to your review, I have updated the changeFilenamePattern method to filter files array and pass results to this.rerunFiles

No, what I meant is that we don't need this property at all, because we already have include and exclude. When pressing p, we should just pass down correct files to rerunFiles.

I don't mind using regex for this.

@sheremet-va
Copy link
Member

@bartoszgolebiowski I pushed some changes to your PR. We don't have tests for stdin right now, unfortunately tho, and creating infrastructure for it is out of scope of this PR, I think. But would be great to have this stuff tested.

I also noticed that after rerunning it doesn't update test count, can you look into that?

@bartoszgolebiowski
Copy link
Contributor Author

Hello @sheremet-va

I added one failing test in the "skip-test" directory and new property "fileNamePattern"
in vitest.config.ts which was responsible for setting an initial value for filter 93056db#diff-644652b4f2da0d83159d02c25d7368a9480fe293826cc3314d4f25cd26672ea6L82

This filter runs all tests inside "test" directory and does not run test inside "skip-test" directory.
I can see that the new test file and logic for injecting value are gone.

To resolve it, we can still use 0fcdd52#diff-ff14f3092ee007d54e9c9f53fa4044149899b44fa12979cc92f1d182d1a2b057R45 and assigning this value to
93056db#diff-644652b4f2da0d83159d02c25d7368a9480fe293826cc3314d4f25cd26672ea6R26 and add failing test in the "skip-test" folder again.

let latestFilename = String(ctx.config.fileNamePattern || '')

BR
Bartosz Golebiowski

@sheremet-va
Copy link
Member

To resolve it, we can still use 0fcdd52#diff-ff14f3092ee007d54e9c9f53fa4044149899b44fa12979cc92f1d182d1a2b057R45 and assigning this value to
93056db#diff-644652b4f2da0d83159d02c25d7368a9480fe293826cc3314d4f25cd26672ea6R26 and add failing test in the "skip-test" folder again.

Yes, but this doesn't actually test the interaction that user has - pressing "p" and inserting filter.

@bartoszgolebiowski
Copy link
Contributor Author

@sheremet-va
It is true, in that case, I do not how to test this functionality.

BR

@sheremet-va sheremet-va merged commit 9add274 into vitest-dev:main Sep 1, 2022
antfu pushed a commit to poyoho/vitest that referenced this pull request Sep 4, 2022
* feat(vite-node): add possibility to filter test files by fileName

* feat(vite-node): change filtering mechanism to use 'includes' method

* refactor: use globTestFiles to filter by filename

Co-authored-by: golebiowskib <bartosz.golebiowski@@ttpsc.pl>
Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>
@unional
Copy link

unional commented Dec 7, 2022

The file name filter doesn't work at all. Using vitest 0.25.5. (during watch mode).

All tests files are still being executed.

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.

Filter tests by filename in watch mode
3 participants