|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const{ spawnPromisified }=require('../common'); |
4 | | -consttmpdir=require('../common/tmpdir'); |
5 | | -constassert=require('assert'); |
6 | | -const{ writeFileSync, unlink }=require('fs'); |
7 | | -const{ describe, after, it }=require('node:test'); |
8 | | - |
9 | | -tmpdir.refresh(); |
| 4 | +constassert=require('node:assert'); |
| 5 | +const{ describe, it }=require('node:test'); |
10 | 6 |
|
11 | 7 | constfileImports={ |
12 | | -cjs: 'const assert = require("assert");', |
13 | | -mjs: 'import assert from "assert";', |
| 8 | +commonjs: 'const assert = require("assert");', |
| 9 | +module: 'import assert from "assert";', |
14 | 10 | }; |
15 | 11 |
|
16 | | -constfileNames=[]; |
17 | | - |
18 | | -for(const[ext,header]ofObject.entries(fileImports)){ |
19 | | -constfileName=`test-file.${ext}`; |
20 | | -// Store the generated filesnames in an array |
21 | | -fileNames.push(`${tmpdir.path}/${fileName}`); |
22 | | - |
23 | | -writeFileSync(tmpdir.resolve(fileName),`${header}\nassert.ok(0 === 2);`); |
24 | | -} |
25 | | - |
26 | 12 | describe('ensure the assert.ok throwing similar error messages for esm and cjs files',()=>{ |
27 | | -constnodejsPath=`${process.execPath}`; |
28 | | -consterrorsMessages=[]; |
29 | | - |
30 | 13 | it('should return code 1 for each command',async()=>{ |
31 | | -for(constfileNameoffileNames){ |
32 | | -const{ stderr, code }=awaitspawnPromisified(nodejsPath,[fileName]); |
| 14 | +consterrorsMessages=[]; |
| 15 | +for(const[inputType,header]ofObject.entries(fileImports)){ |
| 16 | +const{ stderr, code }=awaitspawnPromisified(process.execPath,[ |
| 17 | +'--input-type', |
| 18 | +inputType, |
| 19 | +'--eval', |
| 20 | +`${header}\nassert.ok(0 === 2);\n`, |
| 21 | +]); |
33 | 22 | assert.strictEqual(code,1); |
34 | 23 | // For each error message, filter the lines which will starts with AssertionError |
35 | 24 | errorsMessages.push( |
36 | 25 | stderr.split('\n').find((s)=>s.startsWith('AssertionError')) |
37 | 26 | ); |
38 | 27 | } |
39 | | -}); |
40 | | - |
41 | | -after(()=>{ |
42 | 28 | assert.strictEqual(errorsMessages.length,2); |
43 | 29 | assert.deepStrictEqual(errorsMessages[0],errorsMessages[1]); |
44 | | - |
45 | | -for(constfileNameoffileNames){ |
46 | | -unlink(fileName,()=>{}); |
47 | | -} |
48 | | - |
49 | | -tmpdir.refresh(); |
50 | 30 | }); |
51 | 31 | }); |
0 commit comments