Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/concepts/support-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The Node.js test runner is built into Node.js, so `init` never chooses it just f

With Jest, what `jest.mock` does depends on how the tests run. Babel and ts-jest compile them to CommonJS and hoist `jest.mock` above the imports, so it replaces the module and Veritas records a mock. In native ES modules (`"type": "module"` with no Babel config, no compiling transformer, and a Jest config whose `transform` is absent or empty and that has no `preset`; when in doubt, Veritas keeps counting `jest.mock` as a mock) the static imports are bound before `jest.mock` runs and the tests reach the real code, so Veritas does not count it as a mock of them; `jest.unstable_mockModule` followed by a dynamic `import()` is the ESM way, and what such an import loads is reported as unknown.

With the Node.js test runner, Veritas reads `test`/`it` and `describe`/`suite` from `node:test` (named, aliased, or the default import `import test from 'node:test'`, also through its members such as `test.describe` and `test.it`), `.skip`/`.todo`/`.only` and the same as an options object (`{ skip: true }`, `{ skip: 'reason' }`, `{ todo: 'later' }`, `{ only: true }`), the hooks `before`/`after`/`beforeEach`/`afterEach`, and the `mock` API (`mock.fn`, `mock.method`, `mock.getter`/`mock.setter`, `mock.module`). Every value export of `node:assert`, `node:assert/strict` and `assert` counts as an assertion (`assert(x)`, `assert.equal`, named imports such as `strictEqual`, `assert.strict.*`, `require`); a call counts only when its name resolves to that import, so a local function of the same name does not. So does `t.assert.*` on the test context and on the contexts of its subtests. CommonJS test files that bind them with a top-level `const { test } = require('node:test')` or `const assert = require('node:assert')` are read the same way, including modifiers read on a required member (`require('node:test')['describe']['skip']`, `test['skip'](...)`), and `node:assert` required inside a test; `require` counts only when the file does not declare its own. CommonJS has no default export, so `require('node:test').default` and `const { default: test } = require('node:test')` register nothing, while `import { default as test } from 'node:test'` does. Subtests (`t.test`) are analysed as part of the test that registers them, not listed on their own. With any runner, a test file matching `analysis.testInclude` from which no test registration can be read (its tests are registered by code static analysis does not follow) is named in the messages of the `map` stage, which is then `partial`, so the run cannot report `pass`. A file is left out only when it is shown to register nothing: every statement of it and of each local module it loads is known to run no code when it loads, and no module it imports registers tests. Known to run none are imports and exports of modules that pass the package rule, declarations of functions, types, interfaces, const or literal enums and classes without decorators, static blocks or static initialisers that run code, variables and `export default` of inert values (literals, templates without substitutions, functions, object and array literals of such values without spread, local names), CommonJS exports of inert values, a few inert builtins (`Symbol()`, `Object.freeze()`, path and URL helpers) and the runner's hooks and mock configuration (`beforeAll`, `vi.mock`, `jest.setTimeout`). Anything else counts: other calls, `new`, `await`, loops, spread, assignments, member reads that may run a getter, decorators. A package loaded for its side effects (`import 'pkg'`), re-exported whole (`export * from 'pkg'`) or imported dynamically always counts, and in a file of the runner's own pattern (`*.test.*`, `*.spec.*`) so does a package imported by name anywhere in its local imports; in a helper matched only by a directory glob, a package imported by name and used only inside functions does not. This has a known limitation with the Node.js test runner: `node --test` runs every file under a `test` directory as a test file, but a file matched only by such a directory glob (`**/test/**`) still uses the looser rule, so a file there that only binds a package import is not named, even if that package registers tests when it is imported. A local module that does not resolve counts too. A file that the rest of static analysis already finds open (code at load time it cannot read, or code it does not follow, such as a dynamic import of a computed name or a computed member of the runner; re-exports of the runner's API, local JSON loaded by `require` or `import()`, CommonJS exports of inert values and, in a helper matched only by a directory glob, a top-level `require` of a package used only inside functions are not such code) is never left out, whatever this rule says. So a barrel such as `export { test } from 'node:test'` or a helper that only defines functions is not named, while one that runs `const app = createApp()` when it loads is. When the code it runs calls into a package (`import { suite } from 'some-lib'; suite()`), possibly in a local module it loads, the message names the package and that module. A file that uses another runner's API (`bun:test`, `Deno.test`) is named with that reason. The message names the first 10 files and counts the rest.
With the Node.js test runner, Veritas reads `test`/`it` and `describe`/`suite` from `node:test` (named, aliased, or the default import `import test from 'node:test'`, also through its members such as `test.describe` and `test.it`), `.skip`/`.todo`/`.only` and the same as an options object (`{ skip: true }`, `{ skip: 'reason' }`, `{ todo: 'later' }`, `{ only: true }`), the hooks `before`/`after`/`beforeEach`/`afterEach`, and the `mock` API (`mock.fn`, `mock.method`, `mock.getter`/`mock.setter`, `mock.module`). Every value export of `node:assert`, `node:assert/strict` and `assert` counts as an assertion (`assert(x)`, `assert.equal`, named imports such as `strictEqual`, `assert.strict.*`, `require`); a call counts only when its name resolves to that import, so a local function of the same name does not. So does `t.assert.*` on the test context and on the contexts of its subtests. Members destructured from the context (`({ assert, mock }) => …`) are read the same way. When a test hands its context to a function that uses it in ways the analysis does not follow (passes it to another call, stores it, reads `arguments` or a rest parameter), including a function passed by name as the test itself, or to one that is also called with something else, the test is inconclusive (`opaque_call`) rather than judged to assert nothing. With node:test and Vitest, whose callbacks receive a test context (the second parameter with Vitest's `test.for`), any use of the context, a member destructured from it or an alias of them other than a direct member call such as `t.assert.equal(…)` or `ctx.expect(…)` keeps the test from being judged to assert nothing or to assert only constants. Jest's `done` is not a context. An ordinary helper that never receives a context (`function check(x) { expect(x).toBe(2) }`) is judged as any other call. With any runner, a test is also inconclusive when it asserts on a variable written by a closure it hands to project code (`compose([middleware])(ctx)` with the middleware setting `called`, or a handler registered on a project object in a `describe`), or when it hands a project object to a local helper that calls it through its parameter; the link to the project call is possible but not shown. CommonJS test files that bind them with a top-level `const { test } = require('node:test')` or `const assert = require('node:assert')` are read the same way, including modifiers read on a required member (`require('node:test')['describe']['skip']`, `test['skip'](...)`), and `node:assert` required inside a test; `require` counts only when the file does not declare its own. CommonJS has no default export, so `require('node:test').default` and `const { default: test } = require('node:test')` register nothing, while `import { default as test } from 'node:test'` does. Subtests (`t.test`) are analysed as part of the test that registers them, not listed on their own. With any runner, a test file matching `analysis.testInclude` from which no test registration can be read (its tests are registered by code static analysis does not follow) is named in the messages of the `map` stage, which is then `partial`, so the run cannot report `pass`. A file is left out only when it is shown to register nothing: every statement of it and of each local module it loads is known to run no code when it loads, and no module it imports registers tests. Known to run none are imports and exports of modules that pass the package rule, declarations of functions, types, interfaces, const or literal enums and classes without decorators, static blocks or static initialisers that run code, variables and `export default` of inert values (literals, templates without substitutions, functions, object and array literals of such values without spread, local names), CommonJS exports of inert values, a few inert builtins (`Symbol()`, `Object.freeze()`, path and URL helpers) and the runner's hooks and mock configuration (`beforeAll`, `vi.mock`, `jest.setTimeout`). Anything else counts: other calls, `new`, `await`, loops, spread, assignments, member reads that may run a getter, decorators. A package loaded for its side effects (`import 'pkg'`), re-exported whole (`export * from 'pkg'`) or imported dynamically always counts, and in a file of the runner's own pattern (`*.test.*`, `*.spec.*`) so does a package imported by name anywhere in its local imports; in a helper matched only by a directory glob, a package imported by name and used only inside functions does not. This has a known limitation with the Node.js test runner: `node --test` runs every file under a `test` directory as a test file, but a file matched only by such a directory glob (`**/test/**`) still uses the looser rule, so a file there that only binds a package import is not named, even if that package registers tests when it is imported. A local module that does not resolve counts too. A file that the rest of static analysis already finds open (code at load time it cannot read, or code it does not follow, such as a dynamic import of a computed name or a computed member of the runner; re-exports of the runner's API, local JSON loaded by `require` or `import()`, CommonJS exports of inert values and, in a helper matched only by a directory glob, a top-level `require` of a package used only inside functions are not such code) is never left out, whatever this rule says. So a barrel such as `export { test } from 'node:test'` or a helper that only defines functions is not named, while one that runs `const app = createApp()` when it loads is. When the code it runs calls into a package (`import { suite } from 'some-lib'; suite()`), possibly in a local module it loads, the message names the package and that module. A file that uses another runner's API (`bun:test`, `Deno.test`) is named with that reason. The message names the first 10 files and counts the rest.

When Veritas runs these tests, it runs `node --test` from the project root with Node's default file patterns, not the project's test script, so extra flags such as `--import tsx` or custom globs in that script are not applied. The bundled reporter writes its JSON report inside `.veritas/improve/`. Tests are keyed `<file>::<suite > test > subtest>`, and skipped and todo tests count as skipped. TypeScript tests run through Node's type stripping, so they must use erasable syntax and import `.ts` file names.

Expand Down
Loading
Loading