|
1 | 1 | import { skip, spawnPromisified } from '../common/index.mjs';
|
2 | 2 | import * as fixtures from '../common/fixtures.mjs';
|
3 |
| -import { match, strictEqual } from 'node:assert'; |
| 3 | +import assert, { match, strictEqual } from 'node:assert'; |
4 | 4 | import { test } from 'node:test';
|
5 | 5 |
|
6 | 6 | if (!process.config.variables.node_use_amaro) skip('Requires Amaro');
|
@@ -59,13 +59,35 @@ test('require a .ts file with implicit extension fails', async () => {
|
59 | 59 | });
|
60 | 60 |
|
61 | 61 | test('expect failure of an .mts file with CommonJS syntax', async () => {
|
62 |
| - const result = await spawnPromisified(process.execPath, [ |
63 |
| - fixtures.path('typescript/cts/test-cts-but-module-syntax.cts'), |
64 |
| - ]); |
65 |
| - |
66 |
| - strictEqual(result.stdout, ''); |
67 |
| - match(result.stderr, /To load an ES module, set "type": "module" in the package\.json or use the \.mjs extension\./); |
68 |
| - strictEqual(result.code, 1); |
| 62 | + const testFilePath = fixtures.path( |
| 63 | + 'typescript/cts/test-cts-but-module-syntax.cts' |
| 64 | + ); |
| 65 | + const result = await spawnPromisified(process.execPath, [testFilePath]); |
| 66 | + |
| 67 | + assert.strictEqual(result.stdout, ''); |
| 68 | + |
| 69 | + const expectedWarning = `Failed to load the ES module: ${testFilePath}. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.`; |
| 70 | + |
| 71 | + try { |
| 72 | + assert.ok( |
| 73 | + result.stderr.includes(expectedWarning), |
| 74 | + `Expected stderr to include: ${expectedWarning}` |
| 75 | + ); |
| 76 | + } catch (e) { |
| 77 | + if (e?.code === 'ERR_ASSERTION') { |
| 78 | + assert.match( |
| 79 | + result.stderr, |
| 80 | + /Failed to load the ES module:.*test-cts-but-module-syntax\.cts/ |
| 81 | + ); |
| 82 | + e.expected = expectedWarning; |
| 83 | + e.actual = result.stderr; |
| 84 | + e.operator = 'includes'; |
| 85 | + } |
| 86 | + throw e; |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + assert.strictEqual(result.code, 1); |
69 | 91 | });
|
70 | 92 |
|
71 | 93 | test('execute a .cts file importing a .cts file', async () => {
|
|
0 commit comments