Skip to content

Commit 2adb229

Browse files
mertcanaltinaduh95
andauthored
Update test-typescript-commonjs.mjs
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4ee996b commit 2adb229

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

test/es-module/test-typescript-commonjs.mjs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,16 @@ test('expect failure of an .mts file with CommonJS syntax', async () => {
6969
const expectedWarning = `Failed to load the ES module: ${testFilePath}. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.`;
7070

7171
try {
72-
// First assertion: check that stderr contains a generic pattern for the ES module load failure.
73-
// This ensures that at a minimum the error message structure is as expected.
74-
assert.match(
75-
result.stderr,
76-
/Failed to load the ES module:.*test-cts-but-module-syntax\.cts/
77-
);
78-
79-
// Second assertion: verify that stderr includes the complete expected warning message.
80-
// We use a try/catch here to improve the error output, providing more context if the assertion fails.
81-
// Having two assertions ensures that:
82-
// 1. We first confirm the error message follows the expected general format.
83-
// 2. We then check that the specific warning (with file path and message details) is present.
8472
assert.ok(
8573
result.stderr.includes(expectedWarning),
8674
`Expected stderr to include: ${expectedWarning}`
8775
);
8876
} catch (e) {
8977
if (e?.code === 'ERR_ASSERTION') {
78+
assert.match(
79+
result.stderr,
80+
/Failed to load the ES module:.*test-cts-but-module-syntax\.cts/
81+
);
9082
e.expected = expectedWarning;
9183
e.actual = result.stderr;
9284
e.operator = 'includes';

0 commit comments

Comments
 (0)