Skip to content

Commit 3803af4

Browse files
fix(ci): test runs on windows runner (#308)
This commit fixes an somewhat odd problem with vitest on windows runners in that it cannot process properly `await import(...)` statements. The changes in this commit represent the minimal changes to make the tests run properly instead of hanging, though there are other improvements to CI forthcoming.
1 parent 2330f65 commit 3803af4

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

test/bindings.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ suite('Bindings', async () => {
2222
'utf8',
2323
);
2424

25-
const test = await import(`./cases/${name}/test.js`);
25+
// NOTE: import separated from await due to issues on windows (see note in util.js)
26+
const testcasePromise = import(`./cases/${name}/test.js`);
27+
const testcase = await testcasePromise;
2628

2729
// Determine the relevant WIT world to use
2830
let witWorld,
2931
witPath,
3032
worldName,
3133
isWasiTarget = false;
32-
if (test.worldName) {
34+
if (testcase.worldName) {
3335
witPath = fileURLToPath(new URL('./wit', import.meta.url));
34-
worldName = test.worldName;
36+
worldName = testcase.worldName;
3537
isWasiTarget = true;
3638
} else {
3739
try {
@@ -61,12 +63,13 @@ suite('Bindings', async () => {
6163
}
6264
}
6365

64-
const enableFeatures = test.enableFeatures || ['http'];
66+
const enableFeatures = testcase.enableFeatures || ['http'];
6567
const disableFeatures =
66-
test.disableFeatures ||
68+
testcase.disableFeatures ||
6769
(isWasiTarget ? [] : ['random', 'clocks', 'http', 'stdio']);
6870

6971
let testArg;
72+
let instance;
7073
try {
7174
const { component, imports } = await componentize(source, {
7275
sourceName: `${name}.js`,
@@ -77,6 +80,7 @@ suite('Bindings', async () => {
7780
disableFeatures: maybeLogging(disableFeatures),
7881
debugBuild: DEBUG_TEST_ENABLED,
7982
});
83+
8084
const map = {
8185
'wasi:cli-base/*': '@bytecodealliance/preview2-shim/cli-base#*',
8286
'wasi:clocks/*': '@bytecodealliance/preview2-shim/clocks#*',
@@ -88,6 +92,7 @@ suite('Bindings', async () => {
8892
'wasi:random/*': '@bytecodealliance/preview2-shim/random#*',
8993
'wasi:sockets/*': '@bytecodealliance/preview2-shim/sockets#*',
9094
};
95+
9196
for (let [impt] of imports) {
9297
if (impt.startsWith('wasi:')) continue;
9398
if (impt.startsWith('[')) impt = impt.slice(impt.indexOf(']') + 1);
@@ -130,15 +135,20 @@ suite('Bindings', async () => {
130135
const outputPath = fileURLToPath(
131136
new URL(`./output/${name}/${name}.js`, import.meta.url),
132137
);
133-
var instance = await import(outputPath);
138+
139+
// NOTE: import separated from await due to issues on windows (see note in util.js)
140+
const instancePromise = import(outputPath);
141+
instance = await instancePromise;
142+
134143
} catch (e) {
135-
if (test.err) {
136-
test.err(e);
144+
if (testcase.err) {
145+
testcase.err(e);
137146
return;
138147
}
139148
throw e;
140149
}
141-
await test.test(instance, testArg);
150+
151+
await testcase.test(instance, testArg);
142152
});
143153
}
144154
});

test/builtins.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ suite('Builtins', async () => {
1919
for (const filename of builtins) {
2020
const name = filename.slice(0, -3);
2121
test.concurrent(name, async () => {
22+
// NOTE: import separated from await due to issues on windows (see note in util.js)
23+
const builtinModulePromise = import(`./builtins/${name}.js`);
24+
2225
const {
2326
source,
2427
test: runTest,
2528
disableFeatures,
2629
enableFeatures,
27-
} = await import(`./builtins/${name}.js`);
30+
} = await builtinModulePromise;
2831

2932
const { component } = await componentize(
3033
source,

test/util.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@ export async function setupComponent(opts) {
5656
}
5757

5858
const componentJsPath = join(wasiDir, 'component.js');
59-
var instance = await import(componentJsPath);
6059

61-
return {
62-
instance,
63-
outputDir,
64-
};
60+
// NOTE: On Windows, vitest has stated suddenly hanging when processing code with an
61+
// `await import(...)` in it, when the `...` is a bare identifier.
62+
//
63+
// This can be worked around in many ways:
64+
// - doing a trivial tranformation on the identifier/argument
65+
// - returning a more traditional promise
66+
// - separating await and import() calls
67+
//
68+
// Here we choose to return the promise more traditionally
69+
return import(componentJsPath)
70+
.then(instance => {
71+
return {
72+
instance,
73+
outputDir,
74+
};
75+
});
6576
}

0 commit comments

Comments
 (0)