Skip to content

Commit

Permalink
Add --no-typescript flag (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Jan 31, 2024
1 parent d05507c commit b5d0888
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 4 deletions.
3 changes: 2 additions & 1 deletion 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.
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions borp.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions fixtures/ts-esm2/src/add.ts
@@ -0,0 +1,4 @@

export function add (x: number, y: number): number {
return x + y
}
7 changes: 7 additions & 0 deletions 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)
})
7 changes: 7 additions & 0 deletions 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)
})
24 changes: 24 additions & 0 deletions 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
}
}
7 changes: 6 additions & 1 deletion lib/run.js
Expand Up @@ -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')
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion test/basic.test.js
Expand Up @@ -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'],
Expand Down
18 changes: 17 additions & 1 deletion 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')

Expand Down Expand Up @@ -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)
})

0 comments on commit b5d0888

Please sign in to comment.