|
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');
|
@@ -63,14 +63,35 @@ test('require a .ts file with implicit extension fails', async () => {
|
63 | 63 | });
|
64 | 64 |
|
65 | 65 | test('expect failure of an .mts file with CommonJS syntax', async () => {
|
66 |
| - const result = await spawnPromisified(process.execPath, [ |
67 |
| - '--experimental-strip-types', |
68 |
| - fixtures.path('typescript/cts/test-cts-but-module-syntax.cts'), |
69 |
| - ]); |
70 |
| - |
71 |
| - strictEqual(result.stdout, ''); |
72 |
| - match(result.stderr, /To load an ES module, set "type": "module" in the package\.json or use the \.mjs extension\./); |
73 |
| - strictEqual(result.code, 1); |
| 66 | + const testFilePath = fixtures.path( |
| 67 | + 'typescript/cts/test-cts-but-module-syntax.cts' |
| 68 | + ); |
| 69 | + const result = await spawnPromisified(process.execPath, ['--experimental-strip-types', testFilePath]); |
| 70 | + |
| 71 | + assert.strictEqual(result.stdout, ''); |
| 72 | + |
| 73 | + 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.`; |
| 74 | + |
| 75 | + try { |
| 76 | + assert.ok( |
| 77 | + result.stderr.includes(expectedWarning), |
| 78 | + `Expected stderr to include: ${expectedWarning}` |
| 79 | + ); |
| 80 | + } catch (e) { |
| 81 | + if (e?.code === 'ERR_ASSERTION') { |
| 82 | + assert.match( |
| 83 | + result.stderr, |
| 84 | + /Failed to load the ES module:.*test-cts-but-module-syntax\.cts/ |
| 85 | + ); |
| 86 | + e.expected = expectedWarning; |
| 87 | + e.actual = result.stderr; |
| 88 | + e.operator = 'includes'; |
| 89 | + } |
| 90 | + throw e; |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | + assert.strictEqual(result.code, 1); |
74 | 95 | });
|
75 | 96 |
|
76 | 97 | test('execute a .cts file importing a .cts file', async () => {
|
|
0 commit comments