0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-assert-esm-cjs-message-verify.js
Antoine du Hamel 036ff03691
test: reduce flakiness of test-assert-esm-cjs-message-verify
PR-URL: https://github.com/nodejs/node/pull/53967
Fixes: https://github.com/nodejs/node/issues/53962
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-07-21 17:34:38 +00:00

32 lines
1.1 KiB
JavaScript

'use strict';
const { spawnPromisified } = require('../common');
const assert = require('node:assert');
const { describe, it } = require('node:test');
const fileImports = {
commonjs: 'const assert = require("assert");',
module: 'import assert from "assert";',
};
describe('ensure the assert.ok throwing similar error messages for esm and cjs files', () => {
it('should return code 1 for each command', async () => {
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'))
);
}
assert.strictEqual(errorsMessages.length, 2);
assert.deepStrictEqual(errorsMessages[0], errorsMessages[1]);
});
});