|
1 | 1 | import { spawnPromisified } from '../common/index.mjs'; |
2 | 2 | import * as fixtures from '../common/fixtures.js'; |
3 | 3 | import assert from 'node:assert/strict'; |
| 4 | +import { describe, it } from 'node:test'; |
4 | 5 |
|
5 | 6 | const importMetaMainScript = ` |
6 | 7 | import assert from 'node:assert/strict'; |
@@ -31,45 +32,43 @@ function wrapScriptInUrlWorker(script) { |
31 | 32 | `; |
32 | 33 | } |
33 | 34 |
|
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 | + }) |
59 | 48 |
|
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 | + }) |
72 | 61 |
|
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