Runs a one-time pass of the specified modes of tests, returning a Promise indicating whether the test run succeeded or failed.
NOTE:
test()assumes your source files live within thesrc/folder of the current working directory where the script is being called.
Looking for CLI docs? View companion benmvp test documentation.
To run all modes on all files (default behavior):
import { test } from '@benmvp/cli'
test()To run just unit tests on all files:
import { test } from '@benmvp/cli'
test({
modes: ['spec'],
})To run linting & typing on all files:
import { test } from '@benmvp/cli'
test({
modes: ['lint', 'type'],
})To run all modes only on files within utils/ directories:
import { test } from '@benmvp/cli'
test({
pattern: 'utils/',
})To just run linting on files within api/ directories while continuously watching for changes:
import { test } from '@benmvp/cli'
test({
modes: ['lint'],
pattern: 'api/',
watch: true,
})test() has the following TypeScript signature:
type Mode = 'type' | 'lint' | 'spec'
namespace TestOptions {
modes: Mode[];
pattern: string;
watch: boolean;
}
(options?: TestOptions): Promise<Result>The optional TestOptions object supports the following properties:
An Array of the types or modes of tests to run. Available modes:
'type'- Runs Typescript type-checking (files ending in.tsor.tsx)'lint'- Runs ESLint (files ending in.tsor.tsx)'spec'- Runs Jest-based unit tests (files ending in.spec.ts)
Optional. Defaults to all modes when unspecified.
A regexp pattern string that is matched against all tests paths before executing the test.
Optional. Defaults to '' (signifying no filter)
A flag indicating whether or not to continuously run the tests whenever source files change.
Optional. Defaults to false.
NOTE: Jest Watch Plugins are added to make watch mode even more useful. Specifically the eslint
watch-fixplugin is added to enable auto-fixing of lint errors. However, for this to work,'lint'has to be the first mode when specified.
test() returns a Promise.
When test() finishes successfully, the resolved value will be an object with a code property set to 0.
If test() exits unsuccessfully, the resolved value will be an object with a non-zero code property, a user-friendly message property, and an error property pointing to the inner exception.
Looking for CLI docs? View companion benmvp test documentation.
Still unsure of how to use @benmvp/cli? Ask for help!