-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: reduce flakiness of
test-assert-esm-cjs-message-verify
PR-URL: #53967 Fixes: #53962 Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
- Loading branch information
1 parent
edb75ae
commit 6d0b8de
Showing
1 changed file
with
12 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,31 @@ | ||
'use strict'; | ||
|
||
const { spawnPromisified } = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const assert = require('assert'); | ||
const { writeFileSync, unlink } = require('fs'); | ||
const { describe, after, it } = require('node:test'); | ||
|
||
tmpdir.refresh(); | ||
const assert = require('node:assert'); | ||
const { describe, it } = require('node:test'); | ||
|
||
const fileImports = { | ||
cjs: 'const assert = require("assert");', | ||
mjs: 'import assert from "assert";', | ||
commonjs: 'const assert = require("assert");', | ||
module: 'import assert from "assert";', | ||
}; | ||
|
||
const fileNames = []; | ||
|
||
for (const [ext, header] of Object.entries(fileImports)) { | ||
const fileName = `test-file.${ext}`; | ||
// Store the generated filesnames in an array | ||
fileNames.push(`${tmpdir.path}/${fileName}`); | ||
|
||
writeFileSync(tmpdir.resolve(fileName), `${header}\nassert.ok(0 === 2);`); | ||
} | ||
|
||
describe('ensure the assert.ok throwing similar error messages for esm and cjs files', () => { | ||
const nodejsPath = `${process.execPath}`; | ||
const errorsMessages = []; | ||
|
||
it('should return code 1 for each command', async () => { | ||
for (const fileName of fileNames) { | ||
const { stderr, code } = await spawnPromisified(nodejsPath, [fileName]); | ||
const errorsMessages = []; | ||
for (const [inputType, header] of Object.entries(fileImports)) { | ||
const { stderr, code } = await spawnPromisified(process.execPath, [ | ||
'--input-type', | ||
inputType, | ||
'--eval', | ||
`${header}\nassert.ok(0 === 2);\n`, | ||
]); | ||
assert.strictEqual(code, 1); | ||
// For each error message, filter the lines which will starts with AssertionError | ||
errorsMessages.push( | ||
stderr.split('\n').find((s) => s.startsWith('AssertionError')) | ||
); | ||
} | ||
}); | ||
|
||
after(() => { | ||
assert.strictEqual(errorsMessages.length, 2); | ||
assert.deepStrictEqual(errorsMessages[0], errorsMessages[1]); | ||
|
||
for (const fileName of fileNames) { | ||
unlink(fileName, () => {}); | ||
} | ||
|
||
tmpdir.refresh(); | ||
}); | ||
}); |