borp 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/borp.js +4 -1
- package/fixtures/ts-esm-source-map/src/add.ts +4 -0
- package/fixtures/ts-esm-source-map/test/add.test.ts +7 -0
- package/fixtures/ts-esm-source-map/tsconfig.json +24 -0
- package/lib/run.js +11 -0
- package/package.json +1 -1
- package/test/sourceMap.test.js +87 -0
- package/test/watch.test.js +4 -4
- package/test-utils/clock.js +3 -2
package/borp.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { parseArgs } from 'node:util'
|
|
4
4
|
import Reporters from 'node:test/reporters'
|
|
5
|
+
import { findUp } from 'find-up'
|
|
5
6
|
import { mkdtemp, rm, readFile } from 'node:fs/promises'
|
|
6
7
|
import { createWriteStream } from 'node:fs'
|
|
7
8
|
import { finished } from 'node:stream/promises'
|
|
@@ -141,10 +142,12 @@ try {
|
|
|
141
142
|
const localPrefix = relative(process.cwd(), config.prefix)
|
|
142
143
|
exclude = exclude.map((file) => posix.join(localPrefix, file))
|
|
143
144
|
}
|
|
145
|
+
const nycrc = await findUp(['.c8rc', '.c8rc.json', '.nycrc', '.nycrc.json'], { cwd: config.cwd })
|
|
144
146
|
const report = Report({
|
|
145
147
|
reporter: ['text'],
|
|
146
148
|
tempDirectory: covDir,
|
|
147
|
-
exclude
|
|
149
|
+
exclude,
|
|
150
|
+
...nycrc && JSON.parse(await readFile(nycrc, 'utf8'))
|
|
148
151
|
})
|
|
149
152
|
|
|
150
153
|
if (args.values['check-coverage']) {
|
|
@@ -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
|
+
}
|
package/lib/run.js
CHANGED
|
@@ -16,6 +16,13 @@ function deferred () {
|
|
|
16
16
|
return { resolve, reject, promise }
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function enableSourceMapSupport (tsconfig) {
|
|
20
|
+
if (!tsconfig?.compilerOptions?.sourceMap) {
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS || '') + ' --enable-source-maps'
|
|
25
|
+
}
|
|
19
26
|
export default async function runWithTypeScript (config) {
|
|
20
27
|
// This is a hack to override
|
|
21
28
|
// https://github.com/nodejs/node/commit/d5c9adf3df
|
|
@@ -58,6 +65,8 @@ export default async function runWithTypeScript (config) {
|
|
|
58
65
|
prefix = join(dirname(tsconfigPath), outDir)
|
|
59
66
|
}
|
|
60
67
|
|
|
68
|
+
enableSourceMapSupport(tsconfig)
|
|
69
|
+
|
|
61
70
|
if (tscPath) {
|
|
62
71
|
// This will throw if we cannot find the `tsc` binary
|
|
63
72
|
await access(tscPath)
|
|
@@ -116,6 +125,8 @@ export default async function runWithTypeScript (config) {
|
|
|
116
125
|
if (config['post-compile'] && tsconfigPath) {
|
|
117
126
|
const tsconfig = JSON.parse(await readFile(tsconfigPath))
|
|
118
127
|
outDir = tsconfig.compilerOptions.outDir
|
|
128
|
+
|
|
129
|
+
enableSourceMapSupport(tsconfig)
|
|
119
130
|
}
|
|
120
131
|
let start = Date.now()
|
|
121
132
|
tscChild = execa('node', [tscPath, ...typescriptCliArgs], { cwd })
|
package/package.json
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { test } from 'node:test'
|
|
4
|
+
import { execa } from 'execa'
|
|
5
|
+
import { existsSync } from 'node:fs'
|
|
6
|
+
import { AssertionError, equal, fail, match, strictEqual } from 'node:assert'
|
|
7
|
+
import { tspl } from '@matteo.collina/tspl'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import { cp, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
|
10
|
+
import runWithTypeScript from '../lib/run.js'
|
|
11
|
+
import { join } from 'desm'
|
|
12
|
+
|
|
13
|
+
test('borp should return ts file path in error message when sourceMap is active in tsconfig', async (t) => {
|
|
14
|
+
const borp = join(import.meta.url, '..', 'borp.js')
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
await execa('node', [
|
|
18
|
+
borp
|
|
19
|
+
], {
|
|
20
|
+
cwd: join(import.meta.url, '..', 'fixtures', 'ts-esm-source-map')
|
|
21
|
+
})
|
|
22
|
+
fail('Should not complete borp without error')
|
|
23
|
+
} catch (e) {
|
|
24
|
+
if (e instanceof AssertionError) {
|
|
25
|
+
throw e
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
equal(e.exitCode, 1)
|
|
29
|
+
match(e.message, /at TestContext\..*add\.test\.ts/, 'Error message should contain ts file path')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const fileMapPath = join(import.meta.url, '..', 'fixtures', 'ts-esm-source-map', 'dist', 'src', 'add.js.map')
|
|
33
|
+
strictEqual(existsSync(fileMapPath), true, 'Map file should be generated')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('source map should be generated when watch is active', async (t) => {
|
|
37
|
+
const { strictEqual, completed } = tspl(t, { plan: 1 })
|
|
38
|
+
|
|
39
|
+
const dir = path.resolve(await mkdtemp('.test-watch'))
|
|
40
|
+
await cp(join(import.meta.url, '..', 'fixtures', 'ts-esm-source-map'), dir, {
|
|
41
|
+
recursive: true
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const passTest = `
|
|
45
|
+
import { test } from 'node:test'
|
|
46
|
+
import { add } from '../src/add.js'
|
|
47
|
+
import { strictEqual } from 'node:assert'
|
|
48
|
+
|
|
49
|
+
test('addSuccess', () => {
|
|
50
|
+
strictEqual(add(1,2), 3)
|
|
51
|
+
})
|
|
52
|
+
`
|
|
53
|
+
await writeFile(path.join(dir, 'test', 'add.test.ts'), passTest)
|
|
54
|
+
|
|
55
|
+
const controller = new AbortController()
|
|
56
|
+
t.after(async () => {
|
|
57
|
+
controller.abort()
|
|
58
|
+
try {
|
|
59
|
+
await rm(dir, { recursive: true, retryDelay: 100, maxRetries: 10 })
|
|
60
|
+
} catch {}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const config = {
|
|
64
|
+
files: [],
|
|
65
|
+
cwd: dir,
|
|
66
|
+
signal: controller.signal,
|
|
67
|
+
watch: true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
await runWithTypeScript(config)
|
|
71
|
+
|
|
72
|
+
const failureTestToWrite = `
|
|
73
|
+
import { test } from 'node:test'
|
|
74
|
+
import { add } from '../src/add.js'
|
|
75
|
+
import { strictEqual } from 'node:assert'
|
|
76
|
+
|
|
77
|
+
test('addFailure', () => {
|
|
78
|
+
strictEqual(add(1,2), 4)
|
|
79
|
+
})
|
|
80
|
+
`
|
|
81
|
+
await writeFile(path.join(dir, 'test', 'add.test.ts'), failureTestToWrite)
|
|
82
|
+
|
|
83
|
+
const expectedMapFilePath = path.join(dir, 'dist', 'src', 'add.js.map')
|
|
84
|
+
strictEqual(existsSync(expectedMapFilePath), true, 'Map file should be generated')
|
|
85
|
+
|
|
86
|
+
await completed
|
|
87
|
+
})
|
package/test/watch.test.js
CHANGED
|
@@ -33,7 +33,7 @@ test('watch', async (t) => {
|
|
|
33
33
|
|
|
34
34
|
const fn = (test) => {
|
|
35
35
|
if (test.type === 'test:fail') {
|
|
36
|
-
|
|
36
|
+
match(test.data.name, /add/)
|
|
37
37
|
stream.removeListener('data', fn)
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -85,7 +85,7 @@ test('watch file syntax error', async (t) => {
|
|
|
85
85
|
|
|
86
86
|
const fn = (test) => {
|
|
87
87
|
if (test.type === 'test:fail') {
|
|
88
|
-
match(test.data.name, /add
|
|
88
|
+
match(test.data.name, /add/)
|
|
89
89
|
stream.removeListener('data', fn)
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -111,7 +111,7 @@ test('add', () => {
|
|
|
111
111
|
})
|
|
112
112
|
|
|
113
113
|
test('watch with post compile hook should call the hook the right number of times', async (t) => {
|
|
114
|
-
const {
|
|
114
|
+
const { completed, ok, match } = tspl(t, { plan: 2 })
|
|
115
115
|
|
|
116
116
|
const dir = path.resolve(await mkdtemp('.test-watch-with-post-compile-hook'))
|
|
117
117
|
await cp(join(import.meta.url, '..', 'fixtures', 'ts-esm-post-compile'), dir, {
|
|
@@ -138,7 +138,7 @@ test('watch with post compile hook should call the hook the right number of time
|
|
|
138
138
|
|
|
139
139
|
const fn = (test) => {
|
|
140
140
|
if (test.type === 'test:fail') {
|
|
141
|
-
|
|
141
|
+
match(test.data.name, /add/)
|
|
142
142
|
stream.removeListener('data', fn)
|
|
143
143
|
}
|
|
144
144
|
}
|
package/test-utils/clock.js
CHANGED
|
@@ -4,9 +4,10 @@ let clock
|
|
|
4
4
|
|
|
5
5
|
if (process.argv[1].endsWith('borp.js')) {
|
|
6
6
|
clock = FakeTimers.install({
|
|
7
|
-
|
|
7
|
+
now: Date.now(),
|
|
8
8
|
shouldAdvanceTime: true,
|
|
9
|
-
advanceTimeDelta: 100
|
|
9
|
+
advanceTimeDelta: 100,
|
|
10
|
+
toFake: ['Date', 'setTimeout', 'clearTimeout']
|
|
10
11
|
})
|
|
11
12
|
process.on('message', listener)
|
|
12
13
|
}
|