Skip to content

Commit b5d0888

Browse files
authored
Add --no-typescript flag (#11)
Signed-off-by: Matteo Collina <[email protected]>
1 parent d05507c commit b5d0888

File tree

9 files changed

+70
-4
lines changed

9 files changed

+70
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# borp
22

3-
Borp is a typescript-aware runner for tests written using `node:test`.
3+
Borp is a typescript-aware test runner for `node:test`.
44
It also support code coverage via [c8](http://npm.im/c8).
55

66
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.
9494
* `--expose-gc`, exposes the gc() function to tests
9595
* `--pattern` or `-p`, run tests matching the given glob pattern
9696
* `--reporter` or `-r`, set up a reporter, use a colon to set a file destination. Default: `spec`.
97+
* `--no-typescript` or `-T`, disable automatic TypeScript compilation if `tsconfig.json` is found.
9798

9899
## Reporters
99100

borp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const args = parseArgs({
3232
ignore: { type: 'string', short: 'i', multiple: true },
3333
'expose-gc': { type: 'boolean' },
3434
help: { type: 'boolean', short: 'h' },
35+
'no-typescript': { type: 'boolean', short: 'T' },
3536
reporter: {
3637
type: 'string',
3738
short: 'r',
@@ -78,6 +79,7 @@ if (args.values.coverage) {
7879

7980
const config = {
8081
...args.values,
82+
typescript: !args.values['no-typescript'],
8183
files: args.positionals,
8284
pattern: args.values.pattern,
8385
cwd: process.cwd()

fixtures/ts-esm2/src/add.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
export function add (x: number, y: number): number {
3+
return x + y
4+
}

fixtures/ts-esm2/test/add.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from 'node:test'
2+
import { add } from '../src/add.js'
3+
import { strictEqual } from 'node:assert'
4+
5+
test('add', () => {
6+
strictEqual(add(1, 2), 3)
7+
})

fixtures/ts-esm2/test/add2.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from 'node:test'
2+
import { add } from '../src/add.js'
3+
import { strictEqual } from 'node:assert'
4+
5+
test('add2', () => {
6+
strictEqual(add(3, 2), 5)
7+
})

fixtures/ts-esm2/tsconfig.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"sourceMap": true,
6+
"target": "ES2022",
7+
"module": "NodeNext",
8+
"moduleResolution": "NodeNext",
9+
"esModuleInterop": true,
10+
"strict": true,
11+
"resolveJsonModule": true,
12+
"removeComments": true,
13+
"newLine": "lf",
14+
"noUnusedLocals": true,
15+
"noFallthroughCasesInSwitch": true,
16+
"isolatedModules": true,
17+
"forceConsistentCasingInFileNames": true,
18+
"skipLibCheck": true,
19+
"lib": [
20+
"ESNext"
21+
],
22+
"incremental": true
23+
}
24+
}

lib/run.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async function runWithTypeScript (config) {
2828
let prefix = ''
2929
let tscPath
3030

31-
if (tsconfigPath) {
31+
if (tsconfigPath && config.typescript !== false) {
3232
const _require = createRequire(tsconfigPath)
3333
const typescriptPathCWD = _require.resolve('typescript')
3434
tscPath = join(typescriptPathCWD, '..', '..', 'bin', 'tsc')
@@ -56,6 +56,11 @@ export default async function runWithTypeScript (config) {
5656
prefix = join(dirname(tsconfigPath), outDir)
5757
}
5858
}
59+
60+
// TODO remove those and create a new object
61+
delete config.typescript
62+
delete config['no-typescript']
63+
5964
config.prefix = prefix
6065
config.setup = (test) => {
6166
/* c8 ignore next 12 */

test/basic.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test('ts-cjs', async (t) => {
4646
await completed
4747
})
4848

49-
test('ts-esm with named failes', async (t) => {
49+
test('ts-esm with named files', async (t) => {
5050
const { strictEqual, completed, match } = tspl(t, { plan: 3 })
5151
const config = {
5252
files: ['test/add.test.ts'],

test/cli.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { test } from 'node:test'
22
import { execa } from 'execa'
33
import { join } from 'desm'
4-
import { rejects } from 'node:assert'
4+
import { rejects, strictEqual } from 'node:assert'
5+
import { rm } from 'node:fs/promises'
6+
import path from 'node:path'
57

68
const borp = join(import.meta.url, '..', 'borp.js')
79

@@ -44,3 +46,17 @@ test('failing test with --expose-gc flag sets correct status code', async () =>
4446
cwd: join(import.meta.url, '..', 'fixtures', 'fails')
4547
}))
4648
})
49+
50+
test('disable ts and run no tests', async () => {
51+
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm2')
52+
await rm(path.join(cwd, 'dist'), { recursive: true, force: true })
53+
const { stdout } = await execa('node', [
54+
borp,
55+
'--reporter=spec',
56+
'--no-typescript'
57+
], {
58+
cwd
59+
})
60+
61+
strictEqual(stdout.indexOf('tests 0') >= 0, true)
62+
})

0 commit comments

Comments
 (0)