Skip to content

Commit b19dc2a

Browse files
committed
fix: use CLI args instead of inline env vars for snap-test-global on Windows
Windows cmd.exe doesn't support `VAR=val command` syntax, causing snap-test-global to fail with 'SNAP_TEST_DIR is not recognized'. Replace with --dir and --bin-dir CLI args with ~ expansion via os.homedir().
1 parent f0abce5 commit b19dc2a

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
"build-native": "oxnode -C dev ./build.ts --skip-ts",
292292
"snap-test": "pnpm snap-test-local && pnpm snap-test-global",
293293
"snap-test-local": "tool snap-test",
294-
"snap-test-global": "SNAP_TEST_DIR=snap-tests-global SNAP_TEST_BIN_DIR=$HOME/.vite-plus/current/bin tool snap-test",
294+
"snap-test-global": "tool snap-test --dir snap-tests-global --bin-dir ~/.vite-plus/current/bin",
295295
"publish-native": "node ./publish-native-addons.ts",
296296
"test": "vitest run"
297297
},

packages/tools/src/snap-test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ async function runWithConcurrencyLimit(
6262
}
6363
}
6464

65+
function expandHome(p: string): string {
66+
return p.startsWith('~') ? path.join(homedir(), p.slice(1)) : p;
67+
}
68+
6569
export async function snapTest() {
66-
const { positionals } = parseArgs({
70+
const { positionals, values } = parseArgs({
6771
allowPositionals: true,
6872
args: process.argv.slice(3),
73+
options: {
74+
dir: { type: 'string' },
75+
'bin-dir': { type: 'string' },
76+
},
6977
});
7078

7179
const filter = positionals[0] ?? ''; // Optional filter to run specific test cases
@@ -115,15 +123,15 @@ export async function snapTest() {
115123
// Clean up the temporary directory on exit
116124
process.on('exit', () => fs.rmSync(tempTmpDir, { recursive: true, force: true }));
117125

118-
const casesDir = path.resolve(process.env.SNAP_TEST_DIR || 'snap-tests');
126+
const casesDir = path.resolve(values.dir || 'snap-tests');
119127

120128
const taskFunctions: (() => Promise<void>)[] = [];
121129
for (const caseName of fs.readdirSync(casesDir)) {
122130
if (caseName.startsWith('.')) {
123131
continue;
124132
} // Skip hidden files like .DS_Store
125133
if (caseName.includes(filter)) {
126-
taskFunctions.push(() => runTestCase(caseName, tempTmpDir, casesDir));
134+
taskFunctions.push(() => runTestCase(caseName, tempTmpDir, casesDir, values['bin-dir']));
127135
}
128136
}
129137

@@ -165,7 +173,7 @@ interface Steps {
165173
after?: string[];
166174
}
167175

168-
async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {
176+
async function runTestCase(name: string, tempTmpDir: string, casesDir: string, binDir?: string) {
169177
const steps: Steps = JSON.parse(
170178
await fsPromises.readFile(`${casesDir}/${name}/steps.json`, 'utf-8'),
171179
);
@@ -210,9 +218,9 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {
210218
}
211219
env['PATH'] = [
212220
// Extend PATH to include the package's bin directory
213-
// SNAP_TEST_BIN_DIR overrides the default for cases like global CLI tests
221+
// --bin-dir overrides the default for cases like global CLI tests
214222
// where vp should resolve to the Rust binary instead of the Node.js script
215-
path.resolve(process.env.SNAP_TEST_BIN_DIR || 'bin'),
223+
path.resolve(expandHome(binDir || 'bin')),
216224
...env['PATH'].split(path.delimiter),
217225
].join(path.delimiter);
218226

0 commit comments

Comments
 (0)