codeceptjs 4.0.0-beta.14 → 4.0.0-beta.15

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.
@@ -37,8 +37,11 @@ export async function transpileTypeScript(mainFilePath, typescript) {
37
37
  let esmGlobals = ''
38
38
 
39
39
  if (usesRequire || usesModuleExports) {
40
+ // IMPORTANT: Use the original .ts file path as the base for require()
41
+ // This ensures dynamic require() calls work with relative paths from the original file location
42
+ const originalFileUrl = `file://${filePath.replace(/\\/g, '/')}`
40
43
  esmGlobals += `import { createRequire } from 'module';
41
- const require = createRequire(import.meta.url);
44
+ const require = createRequire('${originalFileUrl}');
42
45
  const module = { exports: {} };
43
46
  const exports = module.exports;
44
47
 
@@ -46,9 +49,11 @@ const exports = module.exports;
46
49
  }
47
50
 
48
51
  if (usesCommonJSGlobals) {
52
+ // For __dirname and __filename, also use the original file path
53
+ const originalFileUrl = `file://${filePath.replace(/\\/g, '/')}`
49
54
  esmGlobals += `import { fileURLToPath as __fileURLToPath } from 'url';
50
55
  import { dirname as __dirname_fn } from 'path';
51
- const __filename = __fileURLToPath(import.meta.url);
56
+ const __filename = '${filePath.replace(/\\/g, '/')}';
52
57
  const __dirname = __dirname_fn(__filename);
53
58
 
54
59
  `
@@ -96,8 +101,16 @@ const __dirname = __dirname_fn(__filename);
96
101
 
97
102
  // Try adding .ts extension if file doesn't exist and no extension provided
98
103
  if (!path.extname(importedPath)) {
99
- if (fs.existsSync(importedPath + '.ts')) {
100
- importedPath = importedPath + '.ts'
104
+ const tsPath = importedPath + '.ts'
105
+ if (fs.existsSync(tsPath)) {
106
+ importedPath = tsPath
107
+ } else {
108
+ // Try .js extension as well
109
+ const jsPath = importedPath + '.js'
110
+ if (fs.existsSync(jsPath)) {
111
+ // Skip .js files, they don't need transpilation
112
+ continue
113
+ }
101
114
  }
102
115
  }
103
116
 
@@ -134,7 +147,11 @@ const __dirname = __dirname_fn(__filename);
134
147
  const tempFile = transpiledFiles.get(tsPath)
135
148
  // Get relative path from main temp file to this temp file
136
149
  const relPath = path.relative(baseDir, tempFile).replace(/\\/g, '/')
137
- return `from './${relPath}'`
150
+ // Ensure the path starts with ./
151
+ if (!relPath.startsWith('.')) {
152
+ return `from './${relPath}'`
153
+ }
154
+ return `from '${relPath}'`
138
155
  }
139
156
 
140
157
  // Otherwise, keep the import as-is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeceptjs",
3
- "version": "4.0.0-beta.14",
3
+ "version": "4.0.0-beta.15",
4
4
  "type": "module",
5
5
  "description": "Supercharged End 2 End Testing Framework for NodeJS",
6
6
  "keywords": [
@@ -2742,6 +2742,7 @@ declare namespace CodeceptJS {
2742
2742
  * `grabStorageState({ indexedDB: true })`) IndexedDB data; treat as sensitive and do not commit.
2743
2743
  */
2744
2744
  // @ts-ignore
2745
+ // @ts-ignore
2745
2746
  type PlaywrightConfig = {
2746
2747
  url?: string;
2747
2748
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -6142,6 +6143,7 @@ declare namespace CodeceptJS {
6142
6143
  * @property [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
6143
6144
  */
6144
6145
  // @ts-ignore
6146
+ // @ts-ignore
6145
6147
  type PuppeteerConfig = {
6146
6148
  url: string;
6147
6149
  basicAuth?: any;
@@ -7987,6 +7989,7 @@ declare namespace CodeceptJS {
7987
7989
  * @property [maxUploadFileSize] - set the max content file size in MB when performing api calls.
7988
7990
  */
7989
7991
  // @ts-ignore
7992
+ // @ts-ignore
7990
7993
  type RESTConfig = {
7991
7994
  endpoint?: string;
7992
7995
  prettyPrintJson?: boolean;
@@ -9143,6 +9146,7 @@ declare namespace CodeceptJS {
9143
9146
  * @property [logLevel = silent] - level of logging verbosity. Default: silent. Options: trace | debug | info | warn | error | silent. More info: https://webdriver.io/docs/configuration/#loglevel
9144
9147
  */
9145
9148
  // @ts-ignore
9149
+ // @ts-ignore
9146
9150
  type WebDriverConfig = {
9147
9151
  url: string;
9148
9152
  browser: string;
@@ -2832,6 +2832,7 @@ declare namespace CodeceptJS {
2832
2832
  * `grabStorageState({ indexedDB: true })`) IndexedDB data; treat as sensitive and do not commit.
2833
2833
  */
2834
2834
  // @ts-ignore
2835
+ // @ts-ignore
2835
2836
  type PlaywrightConfig = {
2836
2837
  url?: string;
2837
2838
  browser?: 'chromium' | 'firefox' | 'webkit' | 'electron';
@@ -6383,6 +6384,7 @@ declare namespace CodeceptJS {
6383
6384
  * @property [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
6384
6385
  */
6385
6386
  // @ts-ignore
6387
+ // @ts-ignore
6386
6388
  type PuppeteerConfig = {
6387
6389
  url: string;
6388
6390
  basicAuth?: any;
@@ -8364,6 +8366,7 @@ declare namespace CodeceptJS {
8364
8366
  * @property [maxUploadFileSize] - set the max content file size in MB when performing api calls.
8365
8367
  */
8366
8368
  // @ts-ignore
8369
+ // @ts-ignore
8367
8370
  type RESTConfig = {
8368
8371
  endpoint?: string;
8369
8372
  prettyPrintJson?: boolean;
@@ -9580,6 +9583,7 @@ declare namespace CodeceptJS {
9580
9583
  * @property [logLevel = silent] - level of logging verbosity. Default: silent. Options: trace | debug | info | warn | error | silent. More info: https://webdriver.io/docs/configuration/#loglevel
9581
9584
  */
9582
9585
  // @ts-ignore
9586
+ // @ts-ignore
9583
9587
  type WebDriverConfig = {
9584
9588
  url: string;
9585
9589
  browser: string;