borp 0.16.0 → 0.17.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/README.md +10 -1
- package/borp.js +13 -1
- package/fixtures/files-glob/lib/add.js +3 -0
- package/fixtures/files-glob/test1/add.test.js +7 -0
- package/fixtures/files-glob/test2/nested/add2.test.js +7 -0
- package/fixtures/relative-reporter/lib/add.js +3 -0
- package/fixtures/relative-reporter/reporter.js +24 -0
- package/fixtures/relative-reporter/test/add.test.js +7 -0
- package/fixtures/relative-reporter/test/add2.test.js +7 -0
- package/lib/run.js +10 -0
- package/package.json +1 -1
- package/test/cli.test.js +26 -0
package/README.md
CHANGED
|
@@ -18,6 +18,15 @@ borp --coverage
|
|
|
18
18
|
|
|
19
19
|
# with check coverage active
|
|
20
20
|
borp --coverage --check-coverage --lines 95
|
|
21
|
+
|
|
22
|
+
# with a node_modules located reporter
|
|
23
|
+
borp --reporter foo
|
|
24
|
+
|
|
25
|
+
# with a node_modules located reporter writing to stderr
|
|
26
|
+
borp --reporter foo:stderr
|
|
27
|
+
|
|
28
|
+
# with a local custom reporter
|
|
29
|
+
borp --reporter ./lib/some-reporter.mjs
|
|
21
30
|
```
|
|
22
31
|
|
|
23
32
|
Borp will automatically run all tests files matching `*.test.{js|ts}`.
|
|
@@ -98,7 +107,7 @@ Note the use of `incremental: true`, which speed up compilation massively.
|
|
|
98
107
|
* `--ignore` or `-i`, ignore a glob pattern, and not look for tests there
|
|
99
108
|
* `--expose-gc`, exposes the gc() function to tests
|
|
100
109
|
* `--pattern` or `-p`, run tests matching the given glob pattern
|
|
101
|
-
* `--reporter` or `-r`, set up a reporter, use a colon to set a file destination. Default: `spec`.
|
|
110
|
+
* `--reporter` or `-r`, set up a reporter, use a colon to set a file destination. Reporter may either be a module name resolvable by standard `node_modules` resolution, or a path to a script relative to the process working directory (must be an ESM script). Default: `spec`.
|
|
102
111
|
* `--no-typescript` or `-T`, disable automatic TypeScript compilation if `tsconfig.json` is found.
|
|
103
112
|
* `--post-compile` or `-P`, the path to a file that will be executed after each typescript compilation.
|
|
104
113
|
* `--check-coverage`, enables c8 check coverage; default is false
|
package/borp.js
CHANGED
|
@@ -114,7 +114,19 @@ try {
|
|
|
114
114
|
|
|
115
115
|
for (const input of args.values.reporter) {
|
|
116
116
|
const [name, dest] = input.split(':')
|
|
117
|
-
|
|
117
|
+
let Ctor
|
|
118
|
+
if (Object.prototype.hasOwnProperty.call(reporters, name) === true) {
|
|
119
|
+
Ctor = reporters[name]
|
|
120
|
+
} else {
|
|
121
|
+
try {
|
|
122
|
+
// Try to load a custom reporter from a file relative to the process.
|
|
123
|
+
const modPath = join(process.cwd(), name.replace(/^['"]/, '').replace(/['"]$/, ''))
|
|
124
|
+
Ctor = await import(modPath).then((m) => m.default || m)
|
|
125
|
+
} catch {
|
|
126
|
+
// Fallback to trying to load the reporter from node_modules resolution.
|
|
127
|
+
Ctor = await import(name).then((m) => m.default || m)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
118
130
|
const reporter = Ctor.prototype && Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor
|
|
119
131
|
let output = process.stdout
|
|
120
132
|
if (dest) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { Transform } from 'node:stream'
|
|
4
|
+
|
|
5
|
+
const testReporter = new Transform({
|
|
6
|
+
writableObjectMode: true,
|
|
7
|
+
transform (event, encoding, callback) {
|
|
8
|
+
switch (event.type) {
|
|
9
|
+
case 'test:pass': {
|
|
10
|
+
return callback(null, `passed: ${event.data.file}\n`)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
case 'test:fail': {
|
|
14
|
+
return callback(null, `failed: ${event.data.file}\n`)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
default: {
|
|
18
|
+
callback(null, null)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export default testReporter
|
package/lib/run.js
CHANGED
|
@@ -196,6 +196,16 @@ export default async function runWithTypeScript (config) {
|
|
|
196
196
|
if (prefix) {
|
|
197
197
|
files = files.map((file) => join(prefix, file.replace(/ts$/, 'js')))
|
|
198
198
|
}
|
|
199
|
+
const expandedFiles = []
|
|
200
|
+
for (let i = 0; i < files.length; i += 1) {
|
|
201
|
+
if (files[i].includes('*') === false) {
|
|
202
|
+
expandedFiles.push(files[i])
|
|
203
|
+
continue
|
|
204
|
+
}
|
|
205
|
+
const parsed = await glob(files[i].replace(/^['"]/, '').replace(/['"]$/, ''), { ignore, cwd, windowsPathsNoEscape: true })
|
|
206
|
+
Array.prototype.push.apply(expandedFiles, parsed)
|
|
207
|
+
}
|
|
208
|
+
files = expandedFiles
|
|
199
209
|
} else if (config.pattern) {
|
|
200
210
|
let pattern = config.pattern
|
|
201
211
|
if (prefix) {
|
package/package.json
CHANGED
package/test/cli.test.js
CHANGED
|
@@ -74,6 +74,19 @@ test('reporter from node_modules', async () => {
|
|
|
74
74
|
strictEqual(stdout.indexOf('tests 2') >= 0, true)
|
|
75
75
|
})
|
|
76
76
|
|
|
77
|
+
test('reporter from relative path', async () => {
|
|
78
|
+
const cwd = join(import.meta.url, '..', 'fixtures', 'relative-reporter')
|
|
79
|
+
const { stdout } = await execa('node', [
|
|
80
|
+
borp,
|
|
81
|
+
'--reporter=./fixtures/relative-reporter/reporter.js'
|
|
82
|
+
], {
|
|
83
|
+
cwd
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
strictEqual(/passed:.+add\.test\.js/.test(stdout), true)
|
|
87
|
+
strictEqual(/passed:.+add2\.test\.js/.test(stdout), true)
|
|
88
|
+
})
|
|
89
|
+
|
|
77
90
|
test('gh reporter', async () => {
|
|
78
91
|
const cwd = join(import.meta.url, '..', 'fixtures', 'js-esm')
|
|
79
92
|
const { stdout } = await execa('node', [
|
|
@@ -89,6 +102,19 @@ test('gh reporter', async () => {
|
|
|
89
102
|
strictEqual(stdout.indexOf('::notice') >= 0, true)
|
|
90
103
|
})
|
|
91
104
|
|
|
105
|
+
test('interprets globs for files', async () => {
|
|
106
|
+
const cwd = join(import.meta.url, '..', 'fixtures', 'files-glob')
|
|
107
|
+
const { stdout } = await execa('node', [
|
|
108
|
+
borp,
|
|
109
|
+
'\'test1/*.test.js\'',
|
|
110
|
+
'\'test2/**/*.test.js\''
|
|
111
|
+
], {
|
|
112
|
+
cwd
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
strictEqual(stdout.indexOf('tests 2') >= 0, true)
|
|
116
|
+
})
|
|
117
|
+
|
|
92
118
|
test('Post compile script should be executed when --post-compile is sent with esm', async () => {
|
|
93
119
|
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm-post-compile')
|
|
94
120
|
const { stdout } = await execa('node', [
|