Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Fix ESM file imports on Windows to use file-protocol URLs #1675

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/cli/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

const path = require( "path" );
const url = require( "url" );

const requireFromCWD = require( "./require-from-cwd" );
const requireQUnit = require( "./require-qunit" );
Expand Down Expand Up @@ -83,7 +84,11 @@ async function run( args, options ) {
( 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

// filePath is an absolute file path here (per path.resolve above).
// On Windows, Node.js enforces that absolute paths via ESM use valid URLs,
// e.g. file-protocol) https://github.com/qunitjs/qunit/issues/1667
await import( url.pathToFileURL( filePath ) ); // eslint-disable-line node/no-unsupported-features/es-syntax
} else {
throw e;
}
Expand Down
4 changes: 1 addition & 3 deletions test/cli/cli-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,7 @@ HOOK: BCD1 @ B after`;
} );

if ( semver.gte( process.versions.node, "12.0.0" ) ) {

// TODO: Import paths broken on Windows. https://github.com/qunitjs/qunit/issues/1667
QUnit[ skipOnWinTest ]( "run ESM test suite with import statement", async assert => {
QUnit.test( "run ESM test suite with import statement", async assert => {
const command = [ "qunit", "../../es2018/esm.mjs" ];
const execution = await execute( command );

Expand Down