# test Runs a project's suites on Node's built-in test runner through [`@hyperfrontend/testing`](https://www.hyperfrontend.dev/docs/libraries/testing.md): it starts a Node process with the runtime's preload, loads the project's test configuration, prints the coverage table and the reasons a run failed. ```json { "test": { "executor": "@hyperfrontend/workspace:test" } } ``` | Option | What it does | | --------------------- | ------------------------------------------------------------------------------- | | `--testConfig` | The test configuration; defaults to `test.config.ts` in the project | | `--coverageDirectory` | Where coverage is written; defaults to `coverage/` under the root | The runtime is resolved from the workspace that runs the task. ## API Reference ### Functions #### runTestsCli ```typescript function runTestsCli(argv: unknown): Promise ``` Loads a project's test configuration and runs its suites. **Parameters** | Name | Type | Description | | --- | --- | --- | | `argv` | `unknown` | The workspace root, the project root, the coverage directory and the configuration module | **Returns** `Promise`: The exit code: 0 when every suite passed and the coverage thresholds held, 1 otherwise #### testExecutor ```typescript function testExecutor(options: TestExecutorOptions, context: ExecutorContext): Promise ``` Test executor for workspace projects. Runs the project's suites on Node's built-in test runner. The runner is started as its own process so the project's `test.config.ts` is evaluated by the same runtime that executes the tests, rather than by whatever TypeScript loader the calling process has installed. **Parameters** | Name | Type | Description | | --- | --- | --- | | `options` | `TestExecutorOptions` | Executor options naming the test configuration and coverage directory | | `context` | `ExecutorContext` | The workspace, the project and the target the task runs on | **Returns** `Promise`: An object indicating success or failure of the test run **Example: A `test` target reading the project's `test.config.ts`** ```json { "targets": { "test": { "executor": "@hyperfrontend/workspace:test", "options": { "coverageDirectory": "coverage/libs/core" } } } } ``` `npx hf run lib-core:test` starts a Node.js process with `@hyperfrontend/testing/hooks` preloaded; coverage lands in `coverage/libs/core`, the default for a project at `libs/core`. ### Interfaces #### TestExecutorOptions Schema types for the test executor. **Properties** | Name | Type | Description | | --- | --- | --- | | `testConfig?` | `string` | Path to the project's test configuration. Defaults to {projectRoot}/test.config.ts. | | `coverageDirectory?` | `string` | Where coverage reports are written. Defaults to {workspaceRoot}/coverage/{projectRoot}. | ### Variables #### RUNNER_ENTRY The entry of this package that holds the runner the executor starts in a process of its own. ```typescript const RUNNER_ENTRY: "@hyperfrontend/workspace/executors/test" ``` **Value** `'@hyperfrontend/workspace/executors/test'` #### TESTING_PACKAGE The package every project's suites run on. ```typescript const TESTING_PACKAGE: "@hyperfrontend/testing" ``` **Value** `'@hyperfrontend/testing'` --- Canonical page: https://www.hyperfrontend.dev/docs/libraries/workspace/executors/test/ This file: https://www.hyperfrontend.dev/docs/libraries/workspace/executors/test.md Documentation index: https://www.hyperfrontend.dev/llms.txt