testNamePattern doesn't parse RegEx'es in the CLI, or documentation is unclear
fritz-trawa opened this issue · comments
Fritz Stelluto commented
Describe the bug
Hi, thanks for the great library. I cannot get the testNamePattern option to handle regular expressions on the CLI, even though according to the source code it should be parsed as a RegEx
Reproduction
// test-file.spec.ts
import { describe, expect, it } from 'vitest';
describe('container', () => {
// this should only run in the non-regex case...
describe('the data-quality', () => {
// ...and it should fail because of this
it('no pattern', async () => {
expect(true).toBe(false);
});
// this should run in the regex and non-regex case, and pass
it('data-quality: has pattern', async () => {
expect(true).toBe(true);
});
});
// none of this should run in either regex or non-regex
describe('do not mind me', () => {
it('just ignore me', async () => {
expect(true).toBe(false);
});
});
});
and then on the cli
# runs all tests, one of which fails, as expected
vitest --run '--testNamePattern=data-quality' test-file.spec.ts
# doesn't run any tests
vitest --run '--testNamePattern=^data-quality' test-file.spec.ts
# neither does this
vitest --run '--testNamePattern=/^data-quality/' test-file.spec.ts
# nope
vitest --run '--testNamePattern=/^(data-quality)/' test-file.spec.ts]([url]())
# what am I missing
vitest --run '--testNamePattern=\^data-quality' test-file.spec.ts
# if the above didn't run never mind this, which according to the source it should be parsed
vitest --run '--testNamePattern=^data-quality/i' test-file.spec.ts
#EDIT this also doesn't run
vitest --run '--testNamePattern=^data-quality.*$' test-file.spec.ts
# just confirming it has nothing to do with the quotation marks
vitest --run --testNamePattern="^data-quality.*$" test-file.spec.ts
System Info
vitest/1.6.0 darwin-arm64 node-v20.12.2
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Vladimir commented
It's passed into RegExp
as is. It is also applied to the whole name string, so in your case it's:
container the data-quality data-quality: has pattern
So having ^
at the start won't help.
Fritz Stelluto commented
Understood, thanks for the explanation