Skip to content

Commit dc12f2a

Browse files
committed
test: test error annotation when requiring an es module
1 parent 07e16a1 commit dc12f2a

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import nothing from 'somewhere';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const app = require('./app');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import '../common/index.mjs';
2+
import { test } from 'node:test';
3+
import * as fixtures from '../common/fixtures.mjs';
4+
import { spawnSync } from 'node:child_process';
5+
import assert from 'node:assert';
6+
7+
test('correctly reports errors when trying to import an ESM module', () => {
8+
// The following regex matches the error message that is expected to be thrown
9+
//
10+
// package-type-module/require-esm-error-annotation/index.cjs:1
11+
// const app = require('./app');
12+
13+
const matchRegex = /package-type-module\/require-esm-error-annotation\/index.cjs:1[\r?\n]const app = require\(\'\.\/app\'\)/;
14+
const fixture = fixtures.path('es-modules/package-type-module/require-esm-error-annotation/index.cjs');
15+
const args = ['--no-experimental-require-module', fixture];
16+
17+
const result = spawnSync(process.execPath, args);
18+
19+
assert.strictEqual(result.status, 1);
20+
assert(result.stderr.toString().match(matchRegex));
21+
});

0 commit comments

Comments
 (0)