2023-11-11 14:24:56 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { spawnPromisified } = require('../common');
|
2024-07-21 17:34:38 +00:00
|
|
|
const assert = require('node:assert');
|
|
|
|
const { describe, it } = require('node:test');
|
2023-11-11 14:24:56 +00:00
|
|
|
|
|
|
|
const fileImports = {
|
2024-07-21 17:34:38 +00:00
|
|
|
commonjs: 'const assert = require("assert");',
|
|
|
|
module: 'import assert from "assert";',
|
2023-11-11 14:24:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('ensure the assert.ok throwing similar error messages for esm and cjs files', () => {
|
|
|
|
it('should return code 1 for each command', async () => {
|
2024-07-21 17:34:38 +00:00
|
|
|
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`,
|
|
|
|
]);
|
2023-11-11 14:24:56 +00:00
|
|
|
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]);
|
|
|
|
});
|
|
|
|
});
|