@hyperfrontend/workspace/executors/test

test

Runs a project's suites on Node's built-in test runner through @hyperfrontend/testing: 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.

{
  "test": {
    "executor": "@hyperfrontend/workspace:test"
  }
}
OptionWhat it does
--testConfigThe test configuration; defaults to test.config.ts in the project
--coverageDirectoryWhere coverage is written; defaults to coverage/<project root> under the root

The runtime is resolved from the workspace that runs the task.

API Reference§

ƒ Functions

§function

runTestsCli(argv: unknown): Promise<number>

Loads a project's test configuration and runs its suites.
Parameters
NameTypeDescription
§argv
unknownThe workspace root, the project root, the coverage directory and the configuration module
Returns
Promise<number>
The exit code: 0 when every suite passed and the coverage thresholds held, 1 otherwise
§function

testExecutor(options: TestExecutorOptions, context: ExecutorContext): Promise<ExecutorResult>

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
NameTypeDescription
§options
TestExecutorOptionsExecutor options naming the test configuration and coverage directory
§context
ExecutorContextThe workspace, the project and the target the task runs on
Returns
Promise<ExecutorResult>
An object indicating success or failure of the test run
Example

A `test` target reading the project's `test.config.ts`

{
  "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

§interface

TestExecutorOptions

Schema types for the test executor.
Properties
§testConfig?:stringPath to the project's test configuration. Defaults to {projectRoot}/test.config.ts.
§coverageDirectory?:stringWhere coverage reports are written. Defaults to {workspaceRoot}/coverage/{projectRoot}.

● Variables

§type

RUNNER_ENTRY

The entry of this package that holds the runner the executor starts in a process of its own.
§type

TESTING_PACKAGE

The package every project's suites run on.