Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-typescript flag #11

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)
})