Skip to content

Commit e065731

Browse files
committed
refactor: rewrite using node:test to ensure failure is caught in case promises don't settle
1 parent 0bf97dd commit e065731

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed
Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { spawnPromisified } from '../common/index.mjs';
22
import * as fixtures from '../common/fixtures.js';
33
import assert from 'node:assert/strict';
4+
import { describe, it } from 'node:test';
45

56
const importMetaMainScript = `
67
import assert from 'node:assert/strict';
@@ -31,45 +32,43 @@ function wrapScriptInUrlWorker(script) {
3132
`;
3233
}
3334

34-
async function test_evaluated_script() {
35-
const result = await spawnPromisified(
36-
process.execPath,
37-
['--input-type=module', '--eval', importMetaMainScript],
38-
);
39-
assert.deepStrictEqual(result, {
40-
stderr: '',
41-
stdout: '',
42-
code: 0,
43-
signal: null,
44-
});
45-
}
46-
47-
async function test_evaluated_script_in_eval_worker() {
48-
const result = await spawnPromisified(
49-
process.execPath,
50-
['--input-type=module', '--eval', wrapScriptInEvalWorker(importMetaMainScript)],
51-
);
52-
assert.deepStrictEqual(result, {
53-
stderr: '',
54-
stdout: '',
55-
code: 0,
56-
signal: null,
57-
});
58-
}
35+
describe("import.meta.main in evaluated scripts", () => {
36+
it("should evaluate true in evaluated script", async () => {
37+
const result = await spawnPromisified(
38+
process.execPath,
39+
['--input-type=module', '--eval', importMetaMainScript],
40+
);
41+
assert.deepStrictEqual(result, {
42+
stderr: '',
43+
stdout: '',
44+
code: 0,
45+
signal: null,
46+
});
47+
})
5948

60-
async function test_evaluated_script_in_url_worker() {
61-
const result = await spawnPromisified(
62-
process.execPath,
63-
['--input-type=module', '--eval', wrapScriptInUrlWorker(importMetaMainScript)],
64-
);
65-
assert.deepStrictEqual(result, {
66-
stderr: '',
67-
stdout: '',
68-
code: 0,
69-
signal: null,
70-
});
71-
}
49+
it("should evaluate true in worker instantiated with module source by evaluated script", async () => {
50+
const result = await spawnPromisified(
51+
process.execPath,
52+
['--input-type=module', '--eval', wrapScriptInEvalWorker(importMetaMainScript)],
53+
);
54+
assert.deepStrictEqual(result, {
55+
stderr: '',
56+
stdout: '',
57+
code: 0,
58+
signal: null,
59+
});
60+
})
7261

73-
await test_evaluated_script();
74-
await test_evaluated_script_in_eval_worker();
75-
await test_evaluated_script_in_url_worker();
62+
it("should evaluate true in worker instantiated with `data:` URL by evaluated script", async () => {
63+
const result = await spawnPromisified(
64+
process.execPath,
65+
['--input-type=module', '--eval', wrapScriptInUrlWorker(importMetaMainScript)],
66+
);
67+
assert.deepStrictEqual(result, {
68+
stderr: '',
69+
stdout: '',
70+
code: 0,
71+
signal: null,
72+
});
73+
})
74+
})

0 commit comments

Comments
 (0)