|
1 | 1 | import{skip,spawnPromisified}from'../common/index.mjs'; |
2 | 2 | import*asfixturesfrom'../common/fixtures.mjs'; |
3 | | -import{match,strictEqual}from'node:assert'; |
| 3 | +importassert,{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 | | -constresult=awaitspawnPromisified(process.execPath,[ |
63 | | -fixtures.path('typescript/cts/test-cts-but-module-syntax.cts'), |
64 | | -]); |
65 | | - |
66 | | -strictEqual(result.stdout,''); |
67 | | -match(result.stderr,/ToloadanESmodule,set"type":"module"inthepackage\.jsonorusethe\.mjsextension\./); |
68 | | -strictEqual(result.code,1); |
| 62 | +consttestFilePath=fixtures.path( |
| 63 | +'typescript/cts/test-cts-but-module-syntax.cts' |
| 64 | +); |
| 65 | +constresult=awaitspawnPromisified(process.execPath,[testFilePath]); |
| 66 | + |
| 67 | +assert.strictEqual(result.stdout,''); |
| 68 | + |
| 69 | +constexpectedWarning=`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 | +/FailedtoloadtheESmodule:.*test-cts-but-module-syntax\.cts/ |
| 81 | +); |
| 82 | +e.expected=expectedWarning; |
| 83 | +e.actual=result.stderr; |
| 84 | +e.operator='includes'; |
| 85 | +} |
| 86 | +throwe; |
| 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