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

Support exclude globs, e.g. !some/**/deep_path/**/* #127

Merged
merged 1 commit into from
Nov 21, 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ borp --reporter foo:stderr

# with a local custom reporter
borp --reporter ./lib/some-reporter.mjs

# matching all test.js files except ones in nested node_modules directories
borp 'test/**/*.test.js' '!test/**/node_modules/**/*.test.js'
```

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

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

Expand Down
14 changes: 13 additions & 1 deletion lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,27 @@ export default async function runWithTypeScript (config) {
if (prefix) {
files = files.map((file) => join(prefix, file.replace(/ts$/, 'js')))
}

const expandedFiles = []
const globs = []
for (let i = 0; i < files.length; i += 1) {
if (files[i].includes('*') === false) {
expandedFiles.push(files[i])
continue
}
const parsed = await glob(files[i].replace(/^['"]/, '').replace(/['"]$/, ''), { ignore, cwd, windowsPathsNoEscape: true })
const pattern = files[i].replace(/^['"]/, '').replace(/['"]$/, '')
if (pattern[0] === '!') {
ignore.push(pattern.slice(1))
continue
}
globs.push(pattern)
}

if (globs.length > 0) {
const parsed = await glob(globs, { ignore, cwd, windowsPathsNoEscape: true })
Array.prototype.push.apply(expandedFiles, parsed)
}

files = expandedFiles
} else if (config.pattern) {
let pattern = config.pattern
Expand Down
19 changes: 18 additions & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,24 @@ test('interprets globs for files', async () => {
cwd
})

strictEqual(stdout.indexOf('tests 2') >= 0, true)
strictEqual(stdout.indexOf('✔ add') >= 0, true)
strictEqual(stdout.indexOf('✔ add2') >= 0, true)
strictEqual(stdout.indexOf('✔ a thing'), -1)
})

test('interprets globs for files with an ignore rule', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'files-glob')
const { stdout } = await execa('node', [
borp,
'\'**/*.test.js\'',
'\'!test1/**/node_modules/**/*\''
], {
cwd
})

strictEqual(stdout.indexOf('✔ add') >= 0, true)
strictEqual(stdout.indexOf('✔ add2') >= 0, true)
strictEqual(stdout.indexOf('✔ a thing'), -1)
})

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