Getting started
test-inventory reads JavaScript and TypeScript test files and lists the tests in them as JSON. It parses the code and never runs it, so it needs no browsers, no build and no configuration of the test runner.
0.1 supports Playwright 1.42 and newer and Vitest 3.0 and newer. It needs Node.js 22.12 or newer, and runs on Linux, macOS and Windows, on x64 and Arm.
Install
npm install --save-dev test-inventoryOr try it without adding it to the project. npx downloads the package for one run, after asking:
npx test-inventory "tests/**/*.spec.ts" --framework playwright --output inventory.jsonScan a Playwright suite
Take a spec from the UI tests of a trading app, tests/orders/limit-orders.spec.ts:
import { test, expect } from '../../fixtures/index';
import { TAGS } from '../../test-data/tags';
test.describe('orders', { tag: '@orders' }, () => {
test.describe('limit orders', () => {
// ...
// FIXME: TRD-412 the confirm dialog stays open on WebKit
test(
'rejects a limit price far from the last trade',
{ annotation: { type: 'issue', description: 'TRD-412' } },
async ({ browserName, orderTicket }) => {
test.fixme(browserName === 'webkit', 'confirm dialog stays open on WebKit');
await orderTicket.buy({ quantity: 1, limitPrice: 1 });
await expect(orderTicket.error).toHaveText('Limit price is more than 50% away from the last trade.');
},
);
});
});Run the scan from the project root:
npx test-inventory "tests/**/*.spec.ts" --framework playwright --pretty --output inventory.jsonThe test's record in inventory.json, shortened:
{
"id": "da2f5749ba9ab068",
"relativeFilePath": "tests/orders/limit-orders.spec.ts",
"lineStart": 24,
"lineEnd": 32,
"fullName": "orders > limit orders > rejects a limit price far from the last trade",
"state": "fixme",
"isFixme": true,
"isConditional": true,
"condition": "browserName === 'webkit'",
"reason": "confirm dialog stays open on WebKit",
"stateSource": "test",
"stateLine": 28,
"tags": ["@orders"],
"annotations": [{ "type": "issue", "description": "TRD-412", "lineStart": 26 }],
"comments": ["FIXME: TRD-412 the confirm dialog stays open on WebKit"]
}The test imports test from a local fixtures file. The scan follows that one import to check that it exports a Playwright test object created with test.extend().
Scan a Vitest suite
npx test-inventory "tests/**/*.{test,test-d}.ts" "src/**/*.ts" --framework vitest --output inventory.jsonInclude the source files when they contain in-source tests, and the *.test-d.ts files for type tests.
Next
- Examples for end-to-end tests, a Node service, React, Vue, browser mode and a monorepo.
- The command line options.
- Query recipes and CI recipes.
- Every key in the output.
- The diagnostics: what the scan could not read, and why.
If test-inventory turns out to be useful to you, sponsoring its development pays for the time that keeps it current with new Playwright and Vitest versions.