π only
The .only modifier enables selective execution of tests, allowing you to focus on specific describe, it, and/or test blocks by running only those marked with .only. See the usage to understand the different conditions and behaviors.
From 3.0.0-rc.1 onwards.
History
| Version | Changes |
|---|---|
| v3.0.0 | only modifier to describe, it and test methods. |
| v2.7.0 | only modifier to describe, it and test methods (experimental). |
Usageβ
To enable the .only modifier, you must to pass the --only flag.
You can pass the --only flag either using the test runner (Poku) or the runner you prefer, for example:
npx poku --only
npx tsx test/my-test.test.ts --only
npm test -- --only
node test/my-test.test.js --only
Common Examplesβ
import { describe, it, test } from 'poku';
describe.only(() => {
// β
Will be executed
it(() => {
// β
Will be executed
});
test(() => {
// β
Will be executed
});
});
describe(() => {
// βοΈ Will be skipped
it(() => {
// βοΈ Will be skipped
});
test(() => {
// βοΈ Will be skipped
});
});
describe(() => {
// β
Will be executed
it(() => {
// βοΈ Will be skipped
});
it.only(() => {
// β
Will be executed
});
test(() => {
// βοΈ Will be skipped
});
});
npx poku --only
Intentional Limitationsβ
The .only modifier must be written directly on it, test, or describe. Aliasing it to another name or accessing it indirectly won't work because Poku doesn't track tests internally, as other test runners do. For example:
import { test } from 'poku';
const run = test.only;
run('aliased', () => {
// β Won't be recognized
});
test.only('direct', () => {
// β
Will be recognized
});
- The
.onlymodifier works exactly as its respectivedescribe,itandtestmethods (e.g., by runningbeforeEachandafterEachfor thetest.onlyorit.only). - It's not possible to run
.onlymodifiers without--onlyflag.
It's important to recall that Poku respects conventional JavaScript syntax in tests and doesn't change the order of the executions.