Skip to content

Commit 3352675

Browse files
committed
fix: windoooooows
1 parent 1b88bce commit 3352675

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"scripts": {
1010
"test": "npm run lint && npm run test:integration && npm run coverage",
1111
"test:nolint": "npm run test:integration && npm run coverage",
12-
"test:unit": "node test/run-with-env.js --test --test-reporter=spec 'test/unit/**/*-test.js'",
12+
"test:unit": "node test/run-with-env.js --test --test-reporter=spec \"test/unit/**/*-test.js\"",
1313
"test:slow": "node --test --test-reporter=spec 'test/slow/**/*-test.js'",
14-
"test:integration": "node test/integration/static/index-test.js && node test/integration/static/publish/index-test.js && node test/run-with-env.js --test --test-reporter=spec 'test/integration/macros-n-plugins-test.js'",
15-
"coverage": "mkdir -p coverage && node test/run-with-env.js --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info 'test/unit/**/*-test.js'",
14+
"test:integration": "node test/integration/static/index-test.js && node test/integration/static/publish/index-test.js && node test/run-with-env.js --test --test-reporter=spec test/integration/macros-n-plugins-test.js",
15+
"coverage": "mkdir -p coverage && node test/run-with-env.js --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info \"test/unit/**/*-test.js\"",
1616
"lint": "eslint . --fix",
1717
"rc": "npm version prerelease --preid RC"
1818
},

test/run-with-env.js

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,68 @@ process.env.AWS_ACCESS_KEY_ID = 'blah'
44
process.env.AWS_SECRET_ACCESS_KEY = 'blah'
55

66
const { spawn } = require('child_process')
7+
const { readdirSync, statSync } = require('fs')
8+
const { join } = require('path')
79
const args = process.argv.slice(2)
810

9-
// On Windows, we need to use shell to expand globs
10-
const isWindows = process.platform === 'win32'
11+
// Simple glob expansion for **/*-test.js pattern
12+
function expandGlob (pattern) {
13+
if (!pattern.includes('*')) {
14+
return [ pattern ]
15+
}
1116

12-
const child = spawn('node', args, {
17+
// Handle test/unit/**/*-test.js pattern
18+
const match = pattern.match(/^(.+?)\/\*\*\/\*(.+)$/)
19+
if (match) {
20+
const baseDir = match[1]
21+
const suffix = match[2]
22+
const files = []
23+
24+
function walk (dir) {
25+
try {
26+
const entries = readdirSync(dir)
27+
for (const entry of entries) {
28+
const fullPath = join(dir, entry)
29+
try {
30+
const stat = statSync(fullPath)
31+
if (stat.isDirectory()) {
32+
walk(fullPath)
33+
}
34+
else if (entry.endsWith(suffix)) {
35+
files.push(fullPath)
36+
}
37+
}
38+
catch {
39+
// Skip files we can't stat
40+
}
41+
}
42+
}
43+
catch {
44+
// Skip directories we can't read
45+
}
46+
}
47+
48+
walk(baseDir)
49+
return files
50+
}
51+
52+
return [ pattern ]
53+
}
54+
55+
// Expand any glob patterns in args
56+
const expandedArgs = []
57+
for (const arg of args) {
58+
if (arg.includes('*')) {
59+
expandedArgs.push(...expandGlob(arg))
60+
}
61+
else {
62+
expandedArgs.push(arg)
63+
}
64+
}
65+
66+
const child = spawn('node', expandedArgs, {
1367
stdio: 'inherit',
14-
shell: isWindows,
68+
shell: false,
1569
})
1670

1771
child.on('exit', (code) => {

0 commit comments

Comments
 (0)