Skip to content

Commit

Permalink
test: cover case with a longer stack
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Oct 31, 2024
1 parent a67f4e7 commit 00dfc8f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function main() {
func1(func2(func3()))
}

function func1() {
require('./app.js')
}
function func2() {}
function func3() {}

main()
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ test('correctly reports errors when an ESM module is required with --no-experime
assert(result.stderr.toString().match(matchRegex));
assert.strictEqual(result.stdout.toString(), '');
});

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

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

const result = spawnSync(process.execPath, args);

assert.strictEqual(result.status, 1);
assert(result.stderr.toString().match(matchRegex));
assert.strictEqual(result.stdout.toString(), '');
});

0 comments on commit 00dfc8f

Please sign in to comment.