testNamePattern
Only run tests whose title matches the given pattern.
History
| Version | Changes |
|---|---|
| v4.2.0 | testNamePattern option. |
Unlike filter which matches file paths, testNamePattern matches individual test titles (it and test blocks).
CLIβ
# Run only tests containing "auth" in the title
npx poku --testNamePattern='auth' ./test
# Short flag
npx poku -t='auth' ./test
Config Fileβ
- json
- js
{
"$schema": "https://poku.io/schemas/configs.json",
"testNamePattern": "auth"
}
import { defineConfig } from 'poku';
export default defineConfig({
testNamePattern: /auth/,
});
APIβ
await poku('./test', {
testNamePattern: /auth/,
});
Exampleβ
Given a test file:
import { test, assert } from 'poku';
test('Auth: login with valid credentials', () => {
assert(true);
});
test('Auth: reject invalid token', () => {
assert(true);
});
test('Users: list all users', () => {
assert(true);
});
Running with --testNamePattern='Auth:' will only execute the two Auth tests, skipping Users: list all users:
npx poku -t='Auth:' ./test
tip
To skip specific tests by title instead, see testSkipPattern.
To filter by file path, see filter.
info
This option is inspired by Node.js' --test-name-pattern, Jest's --testNamePattern, and Vitest's --testNamePattern.