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

add: option to run esm from runner and config file #8230

Merged
merged 4 commits into from
Jul 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/testcafe-with-v8-flag-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
const path = require('path');
const url = require('url');
const v8FlagsFilter = require('@devexpress/bin-v8-flags-filter');
const semver = require('semver');

const ESM_OPTION = '--esm';

const forcedArgs = [];

if (process.argv.slice(2).includes(ESM_OPTION)) {
forcedArgs.push('--no-warnings');
forcedArgs.push(`--experimental-loader=${url.pathToFileURL(path.join(__dirname, '../lib/compiler/esm-loader.js')).href}`);
if (!semver.satisfies(process.version, '18.19.0 - 18.x || >=20.8.0'))
forcedArgs.push(`--experimental-loader=${url.pathToFileURL(path.join(__dirname, '../lib/compiler/esm-loader.js')).href}`);
}

v8FlagsFilter(path.join(__dirname, '../lib/cli'), {
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/test-file/api-based.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import addExportAPI from './add-export-api';
import url from 'url';
import PREVENT_MODULE_CACHING_SUFFIX from '../prevent-module-caching-suffix';

const { register } = require('node:module');
const { pathToFileURL } = require('node:url');
const semver = require('semver');


const CWD = process.cwd();

Expand Down Expand Up @@ -66,6 +70,9 @@ export default class APIBasedTestFileCompilerBase extends TestFileCompilerBase {

async _execAsModule (code, filename) {
if (this.esm) {
if (semver.satisfies(process.version, '18.19.0 - 18.x || >=20.8.0'))
register('../esm-loader.js', pathToFileURL(__filename));

const fileUrl = url.pathToFileURL(filename);

//NOTE: It is necessary to prevent module caching during live mode.
Expand Down
4 changes: 4 additions & 0 deletions ts-defs-src/runner-api/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ interface RunOptions {
* Disables native automation of Chromium-based browsers. Use this option to speed up browser automation and increase test stability.
*/
disableNativeAutomation: boolean;
/**
* Allows you to import modules that do not support CommonJS.
*/
esm: boolean;
}

interface StartOptions {
Expand Down
Loading