Skip to content

Command line ​

This page describes scan options, followed by file and version detection. For an unexpected result, use troubleshooting.

To compare saved scans, use test-inventory diff old.json new.json. It takes --format json (default) or --format markdown, --pretty for JSON, and --output (-o). See Compare inventories.

sh
test-inventory [glob...] [options]

The globs select the test files, relative to --root. Quote them so the shell passes them on unchanged. Without globs, the test files are those the Playwright, Vitest, Jest, Mocha, Jasmine, Cypress or WebdriverIO configs in the root and the folders below it run, or for node:test and Bun the files node --test and bun test run, each with the config it uses; see configs. node_modules and .git folders are always left out. As in the runners, globs match folders and files whose names start with a dot, as in .storybook/. On Windows a \ in a glob separates folders, so tests\**\*.spec.ts works; on Linux and macOS it escapes the next character, as in tests/\[legacy\]/*.spec.ts. A / separates folders on every system. This normalization also applies when a node:test pattern names a linked folder explicitly.

Without scan globs, package scripts can narrow discovery using jest --runTestsByPath tests/orders.spec.js, vitest run orders, or playwright test orders. Scripts using the same config contribute their combined file set. These commands follow literal shell directory changes within the scanned project. Playwright also applies simple file filters to its default files in a package without a config.

For Playwright and Vitest projects built at runtime, readable top-level file settings select candidates with projects: null. A config-value-unknown error marks the result as incomplete; explicit globs can select additional files. See the configuration limits of Playwright and Vitest.

OptionMeaning
--framework <name>playwright, vitest, jest, mocha, jasmine, cypress, webdriverio, node or bun. One run reads one framework. Default: the one the project uses; see framework.
--root <dir>The project root. Paths in the output are relative to it. Default: the current folder.
--ignore <glob>Leave out matching files. Can be given more than once.
--framework-version <x.y.z>Apply the rules of this version instead of the one read from the project.
--comments <mode>Which tests get the comment lines above them: all, non-active or none. Default: non-active.
--expand-casesOne record per case of a .each or .for table and per pass of a loop whose values the scan can work out, each with the title the runner gives it and its caseIndex. Without it, a table or loop is one record with caseCount.
--state <state>Keep tests in this state, such as skip or fixme. Can be given more than once.
--tag <tag>Keep tests with this tag, as the output writes it, such as @smoke. Can be given more than once.
--grep <regex>Keep tests whose fullName matches the regular expression, ignoring case.
--onlyKeep tests that use .only, or are inside a describe that does.
--without-reasonKeep non-active tests without a reason, including expected failures and conditional states, but excluding notLoaded.
--related <file>Keep tests a change to this file can affect; see Tests a change can affect. Can be given more than once; - reads files from standard input, one per line.
--fields <keys>Write only these keys of each test, separated by commas. id is always kept.
--format <format>json, jsonl for one record per line, or commands for the command lines that run the tests kept; see Commands that run the tests. Default: json.
-o, --output <file>Write the output to a file instead of standard output. The file is replaced only once it is complete.
--prettyIndent the JSON with two spaces. Without it the JSON is on one line.
-h, --helpShow the help.
-v, --versionShow the version.

Filters ​

The filters reduce the returned inventory to matching tests; the scan still reads the selected source files. See key concepts when interpreting states and counts. A test is kept when it passes every filter given; a filter given more than once keeps a test that has any of its values. To list the tests in the web app that are skipped or marked fixme, with their reasons:

sh
npx test-inventory "tests/**/*.spec.ts" --framework playwright --state skip --state fixme --fields fullName,reason

Each test then has only id and the keys asked for:

json
{
  "id": "da2f5749ba9ab068",
  "fullName": "orders > limit orders > rejects a limit price far from the last trade",
  "reason": "confirm dialog stays open on WebKit"
}

The rest of the output describes the tests that were kept: files has their files, suites the describes around them, diagnostics their problems and the ones that are not about a single test, and summary counts them. Files and diagnostics whose tests were all left out are dropped too, but a file without tests stays with its errors, since tests may be missing from the answer. summary.fileCount is still the number of files scanned, and each file's suiteCount and testCount still count the whole file.

Output written with --fields leaves keys out of the test records, so it no longer matches the JSON Schema, which requires every key. Without --fields, filtered output matches it.

To keep only some files, give a narrower glob instead: the files left out are not read at all.

Tests a change can affect ​

--related keeps the tests a change to a file can affect: those whose dependencies include it, which covers the tests themselves, the code, fixtures, test data, configs, setup files and snapshots they use, and the tests that reach code the scan can't follow, which a change may affect unseen. Matching Vite module patterns also select the test, including for newly added or deleted files. To list the web app's tests that use the orders blotter page object:

sh
npx test-inventory "tests/**/*.spec.ts" --framework playwright --related pages/orders-blotter.ts --fields fullName

--related - reads the files from standard input, one per line, so the files a pull request changes can be piped in from git. Paths are taken from the current folder, as git writes them when run from the root of the repository, also when --root is a folder in it:

sh
git diff --name-only origin/main... | npx test-inventory --framework playwright --related -

The scan reads the files as they are, so a deleted file is in no test's dependencies; the tests that imported it reach a file that can't be read, and are kept. Installed packages aren't followed: a lockfile change keeps no test.

Commands that run the tests ​

--format commands prints, in place of the inventory, a command line for each config that runs the tests kept, with the projects that run them, to run from the project root. With --related, these are the tests a change can affect:

sh
npx test-inventory "tests/**/*.spec.ts" --framework playwright --related pages/orders-blotter.ts --format commands
text
npx playwright test tests/orders/limit-orders.spec.ts tests/orders/market-orders.spec.ts tests/orders/order-lifecycle.spec.ts tests/portfolio.spec.ts --config playwright.config.ts --project chromium webkit

Each runner gets the files the way it takes them: Jest exact paths, with --runTestsByPath and --selectProjects; Vitest a --project for each project; Playwright the files before --project; Cypress one command for each testing type, with --component for component tests; WebdriverIO a --spec for each file; node:test, which reads its arguments as globs, paths with [, ], *, ?, { and } in brackets, as test/routes/[[]venue[]]/quotes.test.js; Bun paths that start with ./. Vitest takes each file as part of a path and Playwright as a regular expression, so a file whose path contains another file's path runs too. Mocha adds the files named on its command line to the config's spec, so its command runs every spec the config lists; a # line above a command says so. A test whose projects the scan couldn't work out runs in every project of its config. Paths that a shell would split are quoted for a POSIX shell. runCommands() gives the same commands from the library.

JSON Lines ​

--format jsonl writes the same inventory with one record on each line, which grep, jq -c and tools that read newline-delimited JSON, such as DuckDB, take one line at a time. Each line has a type key; the output reference lists the line types.

Exit codes ​

CodeWhen
0The scan finished. Diagnostics are part of the output, not failures.
1Reserved for a future release.
2The arguments were invalid, the output could not be written, or the scan crashed.

These are the exit codes ESLint uses. A reader that stops early, as | head does, is not an error: the output ends there and the code is 0. Globs that match no files are not an error either: the output is an empty inventory with a no-files-matched warning, and one line on standard error says so.

There are no options to fail a build on skipped tests or on diagnostics. The output is data; a check that needs a rule can read it, for example with Node.js:

sh
npx test-inventory "tests/**/*.spec.ts" --framework playwright --output inventory.json
node -e "if (require('./inventory.json').summary.onlyCount > 0) process.exit(1)"

Framework ​

Without --framework, the scan takes the runner the project uses: the one whose package, @playwright/test, vitest, jest, mocha, cypress, @wdio/cli, or for Jasmine jasmine or karma-jasmine, a package.json in the root or a folder below it lists, or whose config file is there: playwright.config.*, vitest.config.*, jest.config.*, .mocharc.*, spec/support/jasmine.*, cypress.config.*, wdio.conf.*, or a jest or mocha key in package.json; for node:test, a package.json script that runs node --test, or a node.config.json; for Bun, a script that runs bun test, or a bunfig.toml with a [test] table. A vite.config.* alone doesn't count, as Vite apps without Vitest have one, and node_modules is left out. Only when nothing is found there are the package.json files above the root read, as a monorepo may list its runner once at the top.

When the project uses several runners, such as Playwright for end-to-end tests and Vitest for unit tests, or none of them, the command stops with exit code 2 and names what it found. Scan once per runner, each with its --framework.

Framework version ​

Some syntax depends on the framework version: test.fail.only needs Playwright 1.49, the lock option 1.63, and Vitest 5 removed describe.sequential, and Jest 30 added %$ to .each titles. The version is read from the project, in this order:

  1. node_modules/@playwright/test/package.json, node_modules/vitest/package.json, node_modules/jest/package.json, node_modules/mocha/package.json, node_modules/cypress/package.json, node_modules/@wdio/cli/package.json, or for Jasmine node_modules/jasmine-core/package.json, else jasmine's.
  2. package-lock.json, pnpm-lock.yaml, yarn.lock or bun.lock.
  3. The version in package.json.

Each is looked for in the root, then in each folder above it, as a package in a monorepo may be installed or locked at the top. When none of them has the framework, as in a monorepo whose root leaves it to a package such as code/, the shallowest package.json below the root that declares it and holds scanned files is used instead, outside node_modules, and its folder is read in the same order. For node:test, the version is the Node.js version the project pins: the first of .node-version, .nvmrc, Volta's node in package.json and engines.node, in the root, then in each folder above it; a pin without a minor, such as 24, is a range, and so is engines.node, of which the newest version it names counts, and never one older than 22.0. For Bun, it is the first of .bun-version, packageManager and engines.bun in package.json, in the root, then in each folder above it, else the version of @types/bun or bun-types, read as above. --framework-version overrides all of them. The version ends up in frameworkVersion in the output.

When package.json gives only a range, such as ^4.0.0, frameworkVersion is the lowest version in it, the rules of the newest release in that major apply, and an approximate-framework-version warning names the range and the file. When nothing is found, frameworkVersion is null, the rules of the newest supported version apply, and an unknown-framework-version warning says so.

Large suites ​

Files are read one at a time and their syntax trees are dropped before the next file, and the JSON is written one record at a time. Memory grows with the number of records, not with the size of the files.

Documentation for test-inventory 0.12.2. Released under the MIT License.