Skip to content

Commit 367fede

Browse files
authored
support exclude globs (#127)
1 parent 33e2623 commit 367fede

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ borp --reporter foo:stderr
2727

2828
# with a local custom reporter
2929
borp --reporter ./lib/some-reporter.mjs
30+
31+
# matching all test.js files except ones in nested node_modules directories
32+
borp 'test/**/*.test.js' '!test/**/node_modules/**/*.test.js'
3033
```
3134

3235
Borp will automatically run all tests files matching `*.test.{js|ts}`.
@@ -137,6 +140,9 @@ full path to some yaml file.
137140
The current supported options are:
138141

139142
+ `files` (string[]): An array of test files to include. Globs are supported.
143+
Note: any glob that starts with a `!` (bang character) will be treated as
144+
an ignore glob, e.g. `'!test/**/node_modules/**/*'` will ignore all files
145+
in nested `node_modules` directories that would otherwise be matched.
140146
+ `reporters` (string[]): An array of reporters to use. May be relative path
141147
strings, or module name strings.
142148

lib/run.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,27 @@ export default async function runWithTypeScript (config) {
196196
if (prefix) {
197197
files = files.map((file) => join(prefix, file.replace(/ts$/, 'js')))
198198
}
199+
199200
const expandedFiles = []
201+
const globs = []
200202
for (let i = 0; i < files.length; i += 1) {
201203
if (files[i].includes('*') === false) {
202204
expandedFiles.push(files[i])
203205
continue
204206
}
205-
const parsed = await glob(files[i].replace(/^['"]/, '').replace(/['"]$/, ''), { ignore, cwd, windowsPathsNoEscape: true })
207+
const pattern = files[i].replace(/^['"]/, '').replace(/['"]$/, '')
208+
if (pattern[0] === '!') {
209+
ignore.push(pattern.slice(1))
210+
continue
211+
}
212+
globs.push(pattern)
213+
}
214+
215+
if (globs.length > 0) {
216+
const parsed = await glob(globs, { ignore, cwd, windowsPathsNoEscape: true })
206217
Array.prototype.push.apply(expandedFiles, parsed)
207218
}
219+
208220
files = expandedFiles
209221
} else if (config.pattern) {
210222
let pattern = config.pattern

test/cli.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,24 @@ test('interprets globs for files', async () => {
112112
cwd
113113
})
114114

115-
strictEqual(stdout.indexOf('tests 2') >= 0, true)
115+
strictEqual(stdout.indexOf('✔ add') >= 0, true)
116+
strictEqual(stdout.indexOf('✔ add2') >= 0, true)
117+
strictEqual(stdout.indexOf('✔ a thing'), -1)
118+
})
119+
120+
test('interprets globs for files with an ignore rule', async () => {
121+
const cwd = join(import.meta.url, '..', 'fixtures', 'files-glob')
122+
const { stdout } = await execa('node', [
123+
borp,
124+
'\'**/*.test.js\'',
125+
'\'!test1/**/node_modules/**/*\''
126+
], {
127+
cwd
128+
})
129+
130+
strictEqual(stdout.indexOf('✔ add') >= 0, true)
131+
strictEqual(stdout.indexOf('✔ add2') >= 0, true)
132+
strictEqual(stdout.indexOf('✔ a thing'), -1)
116133
})
117134

118135
test('Post compile script should be executed when --post-compile is sent with esm', async () => {

0 commit comments

Comments
 (0)