diff --git a/README.md b/README.md index 5990b01..df24869 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # borp -Borp is a typescript-aware runner for tests written using `node:test`. +Borp is a typescript-aware test runner for `node:test`. It also support code coverage via [c8](http://npm.im/c8). Borp is self-hosted, i.e. Borp runs its own tests. @@ -94,6 +94,7 @@ Note the use of `incremental: true`, which speed up compilation massively. * `--expose-gc`, exposes the gc() function to tests * `--pattern` or `-p`, run tests matching the given glob pattern * `--reporter` or `-r`, set up a reporter, use a colon to set a file destination. Default: `spec`. +* `--no-typescript` or `-T`, disable automatic TypeScript compilation if `tsconfig.json` is found. ## Reporters diff --git a/borp.js b/borp.js index 65cd868..e525ab6 100755 --- a/borp.js +++ b/borp.js @@ -32,6 +32,7 @@ const args = parseArgs({ ignore: { type: 'string', short: 'i', multiple: true }, 'expose-gc': { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, + 'no-typescript': { type: 'boolean', short: 'T' }, reporter: { type: 'string', short: 'r', @@ -78,6 +79,7 @@ if (args.values.coverage) { const config = { ...args.values, + typescript: !args.values['no-typescript'], files: args.positionals, pattern: args.values.pattern, cwd: process.cwd() diff --git a/fixtures/ts-esm2/src/add.ts b/fixtures/ts-esm2/src/add.ts new file mode 100644 index 0000000..95c44a7 --- /dev/null +++ b/fixtures/ts-esm2/src/add.ts @@ -0,0 +1,4 @@ + +export function add (x: number, y: number): number { + return x + y +} diff --git a/fixtures/ts-esm2/test/add.test.ts b/fixtures/ts-esm2/test/add.test.ts new file mode 100644 index 0000000..2453771 --- /dev/null +++ b/fixtures/ts-esm2/test/add.test.ts @@ -0,0 +1,7 @@ +import { test } from 'node:test' +import { add } from '../src/add.js' +import { strictEqual } from 'node:assert' + +test('add', () => { + strictEqual(add(1, 2), 3) +}) diff --git a/fixtures/ts-esm2/test/add2.test.ts b/fixtures/ts-esm2/test/add2.test.ts new file mode 100644 index 0000000..f0f049c --- /dev/null +++ b/fixtures/ts-esm2/test/add2.test.ts @@ -0,0 +1,7 @@ +import { test } from 'node:test' +import { add } from '../src/add.js' +import { strictEqual } from 'node:assert' + +test('add2', () => { + strictEqual(add(3, 2), 5) +}) diff --git a/fixtures/ts-esm2/tsconfig.json b/fixtures/ts-esm2/tsconfig.json new file mode 100644 index 0000000..52f28e3 --- /dev/null +++ b/fixtures/ts-esm2/tsconfig.json @@ -0,0 +1,24 @@ +{ + "$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 + } +} diff --git a/lib/run.js b/lib/run.js index 2c0720a..e7a9841 100644 --- a/lib/run.js +++ b/lib/run.js @@ -28,7 +28,7 @@ export default async function runWithTypeScript (config) { let prefix = '' let tscPath - if (tsconfigPath) { + if (tsconfigPath && config.typescript !== false) { const _require = createRequire(tsconfigPath) const typescriptPathCWD = _require.resolve('typescript') tscPath = join(typescriptPathCWD, '..', '..', 'bin', 'tsc') @@ -56,6 +56,11 @@ export default async function runWithTypeScript (config) { prefix = join(dirname(tsconfigPath), outDir) } } + + // TODO remove those and create a new object + delete config.typescript + delete config['no-typescript'] + config.prefix = prefix config.setup = (test) => { /* c8 ignore next 12 */ diff --git a/test/basic.test.js b/test/basic.test.js index 4f32c32..3972300 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -46,7 +46,7 @@ test('ts-cjs', async (t) => { await completed }) -test('ts-esm with named failes', async (t) => { +test('ts-esm with named files', async (t) => { const { strictEqual, completed, match } = tspl(t, { plan: 3 }) const config = { files: ['test/add.test.ts'], diff --git a/test/cli.test.js b/test/cli.test.js index 6df5b07..1c5c4a6 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -1,7 +1,9 @@ import { test } from 'node:test' import { execa } from 'execa' import { join } from 'desm' -import { rejects } from 'node:assert' +import { rejects, strictEqual } from 'node:assert' +import { rm } from 'node:fs/promises' +import path from 'node:path' const borp = join(import.meta.url, '..', 'borp.js') @@ -44,3 +46,17 @@ test('failing test with --expose-gc flag sets correct status code', async () => cwd: join(import.meta.url, '..', 'fixtures', 'fails') })) }) + +test('disable ts and run no tests', async () => { + const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm2') + await rm(path.join(cwd, 'dist'), { recursive: true, force: true }) + const { stdout } = await execa('node', [ + borp, + '--reporter=spec', + '--no-typescript' + ], { + cwd + }) + + strictEqual(stdout.indexOf('tests 0') >= 0, true) +})