Skip to content

Commit

Permalink
support parsing glob strings for files target (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Jul 25, 2024
1 parent b348999 commit 0aed6b3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fixtures/files-glob/lib/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function add (x, y) {
return x + y
}
7 changes: 7 additions & 0 deletions fixtures/files-glob/test1/add.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../lib/add.js'
import { strictEqual } from 'node:assert'

test('add', () => {
strictEqual(add(1, 2), 3)
})
7 changes: 7 additions & 0 deletions fixtures/files-glob/test2/nested/add2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../../lib/add.js'
import { strictEqual } from 'node:assert'

test('add2', () => {
strictEqual(add(3, 2), 5)
})
10 changes: 10 additions & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ export default async function runWithTypeScript (config) {
if (prefix) {
files = files.map((file) => join(prefix, file.replace(/ts$/, 'js')))
}
const expandedFiles = []
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 })
Array.prototype.push.apply(expandedFiles, parsed)
}
files = expandedFiles
} else if (config.pattern) {
let pattern = config.pattern
if (prefix) {
Expand Down
13 changes: 13 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ test('gh reporter', async () => {
strictEqual(stdout.indexOf('::notice') >= 0, true)
})

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

strictEqual(stdout.indexOf('tests 2') >= 0, true)
})

test('Post compile script should be executed when --post-compile is sent with esm', async () => {
const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm-post-compile')
const { stdout } = await execa('node', [
Expand Down

0 comments on commit 0aed6b3

Please sign in to comment.