0.17.6 • Published 1 year ago
@dancastillo/testing-borp-with-fastify v0.17.6
borp
Borp is a typescript-aware test runner for node:test.
It also support code coverage via c8.
Borp is self-hosted, i.e. Borp runs its own tests.
Install
npm i borp --save-devUsage
borp --coverage
# with check coverage active
borp --coverage --check-coverage --lines 95
# with a node_modules located reporter
borp --reporter foo
# with a node_modules located reporter writing to stderr
borp --reporter foo:stderr
# with a local custom reporter
borp --reporter ./lib/some-reporter.mjsBorp will automatically run all tests files matching *.test.{js|ts}.
Example project setup
.
├── src
│ ├── lib
│ │ └── math.ts
│ └── test
│ └── math.test.ts
└── tsconfig.jsonAs an example, consider having a src/lib/math.ts file
export function math (x: number, y: number): number {
return x + y
}and a src/test/math.test.ts file:
import { test } from 'node:test'
import { math } from '../lib/math.js'
import { strictEqual } from 'node:assert'
test('math', () => {
strictEqual(math(1, 2), 3)
})and the following tsconfig.json:
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"resolveJsonModule": true,
"removeComments": true,
"newLine": "lf",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"lib": [
"ESNext"
],
"incremental": true
}
}Note the use of incremental: true, which speed up compilation massively.
Options
--concurrencyor-c, to set the number of concurrent tests. Defaults to the number of available CPUs minus one.--coverageor-C, enables code coverage--onlyor-o, only runnode:testwith theonlyoption set--watchor-w, re-run tests on changes--timeoutor-t, timeouts the tests after a given time; default is 30000 ms--no-timeout, disables the timeout--coverage-excludeor-X, a list of comma-separated patterns to exclude from the coverage report. All tests files are ignored by default.--ignoreor-i, ignore a glob pattern, and not look for tests there--expose-gc, exposes the gc() function to tests--patternor-p, run tests matching the given glob pattern--reporteror-r, set up a reporter, use a colon to set a file destination. Reporter may either be a module name resolvable by standardnode_modulesresolution, or a path to a script relative to the process working directory (must be an ESM script). Default:spec.--no-typescriptor-T, disable automatic TypeScript compilation iftsconfig.jsonis found.--post-compileor-P, the path to a file that will be executed after each typescript compilation.--check-coverage, enables c8 check coverage; default is false
Check coverage options
--lines, set the lines threshold when check coverage is active; default is 100--functions, set the functions threshold when check coverage is active; default is 100--statements, set the statements threshold when check coverage is active; default is 100--branches, set the branches threshold when check coverage is active; default is 100
Reporters
Here are the available reporters:
gh: emits::errorworkflow commands for GitHub Actions to show inlined errors. Enabled by default when running on GHA.tap: outputs the test results in the TAP format.spec: outputs the test results in a human-readable format.dot: outputs the test results in a compact format, where each passing test is represented by a ., and each failing test is represented by a X.junit: outputs test results in a jUnit XML format
License
MIT