Skip to content

Commit

Permalink
CLI: Improve ESM detection
Browse files Browse the repository at this point in the history
Also skip the sourcemap test under coverage mode.

Fixes #1593.
Closes #1594.
  • Loading branch information
smcclure15 authored Apr 15, 2021
1 parent 7129fe5 commit 241b565
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/cli/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ async function run( args, options ) {
try {
require( filePath );
} catch ( e ) {
if ( e.code === "ERR_REQUIRE_ESM" && ( !nodeVint || nodeVint >= 72 ) ) {
if ( ( e.code === "ERR_REQUIRE_ESM" ||
( e instanceof SyntaxError &&
e.message === "Cannot use import statement outside a module" ) ) &&
( !nodeVint || nodeVint >= 72 ) ) {
await import( filePath ); // eslint-disable-line node/no-unsupported-features/es-syntax
} else {
throw e;
Expand Down
22 changes: 12 additions & 10 deletions test/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,18 @@ QUnit.module( "CLI Main", () => {
}
} );

QUnit.test( "mapped trace with native source map", async assert => {
const command = "NODE_OPTIONS='--enable-source-maps' qunit sourcemap/source.min.js";
try {
await execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );
assert.equal( e.stdout, expectedOutput[ command ] );
}
} );
// skip if running in code coverage mode - that leads to conflicting maps-on-maps that invalidate this test
QUnit[ process.env.NYC_PROCESS_ID ? "skip" : "test" ](
"mapped trace with native source map", async function( assert ) {
const command = "NODE_OPTIONS='--enable-source-maps' qunit sourcemap/source.min.js";
try {
await execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );
assert.equal( e.stdout, expectedOutput[ command ] );
}
} );
}

QUnit.test( "timeouts correctly recover", async assert => {
Expand Down

0 comments on commit 241b565

Please sign in to comment.