Skip to content

Commit 7a97799

Browse files
committed
test: improve matching
1 parent 9cda6cf commit 7a97799

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

test/parallel/test-require-esm-with-no-experimental-require-module.mjs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,22 @@ import { test } from 'node:test';
33
import * as fixtures from '../common/fixtures.mjs';
44
import { spawnSync } from 'node:child_process';
55
import assert from 'node:assert';
6-
import { EOL } from 'node:os';
76

87
test('correctly reports error for a longer stack trace', () => {
98
// The following regex matches the error message that is expected to be thrown
109
//
11-
// package-type-module/require-esm-error-annotation/longer-stack.cjs:6
10+
// package-type-module/require-esm-error-annotation/index.cjs:6
1211
// require('./app.js')
1312
// ^
1413

1514
const fixture = fixtures.path('es-modules/package-type-module/require-esm-error-annotation/index.cjs');
1615
const args = ['--no-experimental-require-module', fixture];
17-
18-
const lineNumber = 6;
19-
const lineContent = "require('./app.js')";
20-
const fullMessage = `${fixture}:${lineNumber}${EOL} ${lineContent}${EOL} ^${EOL}`;
16+
const regex = /index\.cjs:6[\n\r]+\s{2}require\('\.\/app\.js'\)[\n\r]+\s{2}\^/;
2117

2218
const result = spawnSync(process.execPath, args);
23-
24-
console.log(`STDERR: ${result.stderr.toString()}`);
19+
const stderr = result.stderr.toString();
2520

2621
assert.strictEqual(result.status, 1);
2722
assert.strictEqual(result.stdout.toString(), '');
28-
assert(result.stderr.toString().indexOf(fullMessage) > -1);
23+
assert.match(stderr, regex);
2924
});

0 commit comments

Comments
 (0)