Skip to content

Commit

Permalink
add: option to run esm from runner and config file (#8230)
Browse files Browse the repository at this point in the history
<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->

## Purpose
_Describe the problem you want to address or the feature you want to
implement._

## Approach
_Describe how your changes address the issue or implement the desired
functionality in as much detail as possible._

## References
close #8213

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail

---------

Co-authored-by: Bayheck <adil.rakhaliyev@devexpress.com>
  • Loading branch information
Bayheck and Bayheck authored Jul 18, 2024
1 parent 89895be commit b35a5ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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

0 comments on commit b35a5ac

Please sign in to comment.