Skip to content

Commit ce81fff

Browse files
committed
test: handle windows backslashes
1 parent 6f463de commit ce81fff

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ 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';
67

78
test('correctly reports errors when an ESM module is required with --no-experimental-require-module', () => {
89
// The following regex matches the error message that is expected to be thrown
@@ -11,14 +12,17 @@ test('correctly reports errors when an ESM module is required with --no-experime
1112
// const app = require('./app');
1213
// ^
1314

14-
const matchRegex = /package-type-module[\\/]+require-esm-error-annotation[\\/]+index\.cjs:1[\r?\n]const app = require\('\.\/app'\);[\r?\n]\s{12}\^/;
1515
const fixture = fixtures.path('es-modules/package-type-module/require-esm-error-annotation/index.cjs');
1616
const args = ['--no-experimental-require-module', fixture];
1717

18+
const lineNumber = 1;
19+
const lineContent = `const app = require('./app');`;
20+
const fullMessage = `${fixture}:${lineNumber}${EOL}${lineContent}${EOL} ^${EOL}`;
21+
1822
const result = spawnSync(process.execPath, args);
1923

2024
assert.strictEqual(result.status, 1);
21-
assert(result.stderr.toString().match(matchRegex));
25+
assert(result.stderr.toString().indexOf(fullMessage) > -1);
2226
assert.strictEqual(result.stdout.toString(), '');
2327
});
2428

@@ -29,13 +33,16 @@ test('correctly reports error for a longer stack trace', () => {
2933
// require('./app.js')
3034
// ^
3135

32-
const matchRegex = /package-type-module[\\/]+require-esm-error-annotation[\\/]+longer-stack\.cjs:6[\r?\n]\s{2}require\('\.\/app\.js'\)[\r?\n]\s{2}\^/;
3336
const fixture = fixtures.path('es-modules/package-type-module/require-esm-error-annotation/longer-stack.cjs');
3437
const args = ['--no-experimental-require-module', fixture];
3538

39+
const lineNumber = 6;
40+
const lineContent = "require('./app.js')";
41+
const fullMessage = `${fixture}:${lineNumber}${EOL} ${lineContent}${EOL} ^${EOL}`;
42+
3643
const result = spawnSync(process.execPath, args);
3744

3845
assert.strictEqual(result.status, 1);
39-
assert(result.stderr.toString().match(matchRegex));
4046
assert.strictEqual(result.stdout.toString(), '');
47+
assert(result.stderr.toString().indexOf(fullMessage) > -1);
4148
});

0 commit comments

Comments
 (0)