Skip to content

Commit 0aed6b3

Browse files
authored
support parsing glob strings for files target (#70)
1 parent b348999 commit 0aed6b3

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

fixtures/files-glob/lib/add.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function add (x, y) {
2+
return x + y
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from 'node:test'
2+
import { add } from '../lib/add.js'
3+
import { strictEqual } from 'node:assert'
4+
5+
test('add', () => {
6+
strictEqual(add(1, 2), 3)
7+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from 'node:test'
2+
import { add } from '../../lib/add.js'
3+
import { strictEqual } from 'node:assert'
4+
5+
test('add2', () => {
6+
strictEqual(add(3, 2), 5)
7+
})

lib/run.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ export default async function runWithTypeScript (config) {
196196
if (prefix) {
197197
files = files.map((file) => join(prefix, file.replace(/ts$/, 'js')))
198198
}
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
199209
} else if (config.pattern) {
200210
let pattern = config.pattern
201211
if (prefix) {

test/cli.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ test('gh reporter', async () => {
8989
strictEqual(stdout.indexOf('::notice') >= 0, true)
9090
})
9191

92+
test('interprets globs for files', async () => {
93+
const cwd = join(import.meta.url, '..', 'fixtures', 'files-glob')
94+
const { stdout } = await execa('node', [
95+
borp,
96+
'\'test1/*.test.js\'',
97+
'\'test2/**/*.test.js\''
98+
], {
99+
cwd
100+
})
101+
102+
strictEqual(stdout.indexOf('tests 2') >= 0, true)
103+
})
104+
92105
test('Post compile script should be executed when --post-compile is sent with esm', async () => {
93106
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm-post-compile')
94107
const { stdout } = await execa('node', [

0 commit comments

Comments
 (0)