Skip to content

Commit

Permalink
fix: esm loader fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bayheck committed Feb 22, 2024
1 parent 15cfdca commit d22957d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compilers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ function createTestFileCompilers (compilerOptions = {}, { baseUrl, esm } = {}) {

let testFileCompilers = [];

export function getTestFileCompilers () {
export function getTestFileCompilers (esm) {
if (!testFileCompilers.length)
initTestFileCompilers();
initTestFileCompilers({}, { baseUrl: '', esm });

return testFileCompilers;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/esm-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function load (url: string, context: Context, defaultLoad: Function
if (isNodeModulesDep || isTestcafeLibDep || !filename)
return defaultLoad(url, context, defaultLoad);

const testFilesInfo = await Compiler.createTestFileInfo(filename);
const testFilesInfo = await Compiler.createTestFileInfo(filename, true);

if (testFilesInfo?.compiler) {
const [compiledCode] = await testFilesInfo.compiler.precompile([testFilesInfo]);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class Compiler {
return uniq(flattenDeep(getTestFileCompilers().map(compiler => compiler.getSupportedExtension())));
}

static async createTestFileInfo (filename) {
static async createTestFileInfo (filename, esm = false) {
let code = null;

try {
Expand All @@ -38,7 +38,7 @@ export default class Compiler {

code = stripBom(code).toString();

const compiler = find(getTestFileCompilers(), someCompiler => someCompiler.canCompile(code, filename));
const compiler = find(getTestFileCompilers(esm), someCompiler => someCompiler.canCompile(code, filename));

if (!compiler)
return null;
Expand Down

0 comments on commit d22957d

Please sign in to comment.