codeceptjs 4.0.0-beta.10.esm-aria → 4.0.0-beta.11.esm-aria

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/container.js +15 -1
  2. package/package.json +1 -1
package/lib/container.js CHANGED
@@ -690,13 +690,27 @@ async function loadSupportObject(modulePath, supportObjectName) {
690
690
  const tsContent = fs.readFileSync(filePath, 'utf8')
691
691
 
692
692
  // Transpile TypeScript to JavaScript with ES module output
693
- const jsContent = transpile(tsContent, {
693
+ let jsContent = transpile(tsContent, {
694
694
  module: 99, // ModuleKind.ESNext
695
695
  target: 99, // ScriptTarget.ESNext
696
696
  esModuleInterop: true,
697
697
  allowSyntheticDefaultImports: true,
698
698
  })
699
699
 
700
+ // Check if the code uses __dirname or __filename (CommonJS globals)
701
+ const usesCommonJSGlobals = /__dirname|__filename/.test(jsContent)
702
+
703
+ if (usesCommonJSGlobals) {
704
+ // Inject ESM equivalents at the top of the file
705
+ const esmGlobals = `import { fileURLToPath as __fileURLToPath } from 'url';
706
+ import { dirname as __dirname_fn } from 'path';
707
+ const __filename = __fileURLToPath(import.meta.url);
708
+ const __dirname = __dirname_fn(__filename);
709
+
710
+ `
711
+ jsContent = esmGlobals + jsContent
712
+ }
713
+
700
714
  return jsContent
701
715
  }
702
716
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "4.0.0-beta.10.esm-aria",
3
+ "version": "4.0.0-beta.11.esm-aria",
4
4
  "type": "module",
5
5
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
6
6
  "keywords": [