codeceptjs 4.0.0-beta.14 → 4.0.0-beta.16
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.
- package/lib/utils/typescript.js +102 -68
- package/package.json +1 -1
- package/typings/promiseBasedTypes.d.ts +4 -0
- package/typings/types.d.ts +4 -0
package/lib/utils/typescript.js
CHANGED
|
@@ -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(
|
|
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 =
|
|
56
|
+
const __filename = '${filePath.replace(/\\/g, '/')}';
|
|
52
57
|
const __dirname = __dirname_fn(__filename);
|
|
53
58
|
|
|
54
59
|
`
|
|
@@ -69,85 +74,114 @@ const __dirname = __dirname_fn(__filename);
|
|
|
69
74
|
const transpiledFiles = new Map()
|
|
70
75
|
const baseDir = path.dirname(mainFilePath)
|
|
71
76
|
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const importRegex = /from\s+['"](\..+?)(?:\.ts)?['"]/g
|
|
78
|
-
let match
|
|
79
|
-
const imports = []
|
|
80
|
-
|
|
81
|
-
while ((match = importRegex.exec(jsContent)) !== null) {
|
|
82
|
-
imports.push(match[1])
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Transpile each imported TypeScript file
|
|
86
|
-
for (const relativeImport of imports) {
|
|
87
|
-
let importedPath = path.resolve(baseDir, relativeImport)
|
|
88
|
-
|
|
89
|
-
// Handle .js extensions that might actually be .ts files
|
|
90
|
-
if (importedPath.endsWith('.js')) {
|
|
91
|
-
const tsVersion = importedPath.replace(/\.js$/, '.ts')
|
|
92
|
-
if (fs.existsSync(tsVersion)) {
|
|
93
|
-
importedPath = tsVersion
|
|
94
|
-
}
|
|
77
|
+
// Recursive function to transpile a file and all its TypeScript dependencies
|
|
78
|
+
const transpileFileAndDeps = (filePath) => {
|
|
79
|
+
// Already transpiled, skip
|
|
80
|
+
if (transpiledFiles.has(filePath)) {
|
|
81
|
+
return
|
|
95
82
|
}
|
|
96
83
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
84
|
+
// Transpile this file
|
|
85
|
+
let jsContent = transpileTS(filePath)
|
|
86
|
+
|
|
87
|
+
// Find all relative TypeScript imports in this file
|
|
88
|
+
const importRegex = /from\s+['"](\..+?)(?:\.ts)?['"]/g
|
|
89
|
+
let match
|
|
90
|
+
const imports = []
|
|
103
91
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const transpiledImportContent = transpileTS(importedPath)
|
|
107
|
-
const tempImportFile = importedPath.replace(/\.ts$/, '.temp.mjs')
|
|
108
|
-
fs.writeFileSync(tempImportFile, transpiledImportContent)
|
|
109
|
-
transpiledFiles.set(importedPath, tempImportFile)
|
|
92
|
+
while ((match = importRegex.exec(jsContent)) !== null) {
|
|
93
|
+
imports.push(match[1])
|
|
110
94
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(
|
|
117
|
-
let
|
|
95
|
+
|
|
96
|
+
// Get the base directory for this file
|
|
97
|
+
const fileBaseDir = path.dirname(filePath)
|
|
98
|
+
|
|
99
|
+
// Recursively transpile each imported TypeScript file
|
|
100
|
+
for (const relativeImport of imports) {
|
|
101
|
+
let importedPath = path.resolve(fileBaseDir, relativeImport)
|
|
118
102
|
|
|
119
|
-
// Handle .js
|
|
120
|
-
if (
|
|
121
|
-
const tsVersion =
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
const relPath = path.relative(baseDir, tempFile).replace(/\\/g, '/')
|
|
125
|
-
return `from './${relPath}'`
|
|
103
|
+
// Handle .js extensions that might actually be .ts files
|
|
104
|
+
if (importedPath.endsWith('.js')) {
|
|
105
|
+
const tsVersion = importedPath.replace(/\.js$/, '.ts')
|
|
106
|
+
if (fs.existsSync(tsVersion)) {
|
|
107
|
+
importedPath = tsVersion
|
|
126
108
|
}
|
|
127
109
|
}
|
|
128
110
|
|
|
129
|
-
// Try
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
111
|
+
// Try adding .ts extension if file doesn't exist and no extension provided
|
|
112
|
+
if (!path.extname(importedPath)) {
|
|
113
|
+
const tsPath = importedPath + '.ts'
|
|
114
|
+
if (fs.existsSync(tsPath)) {
|
|
115
|
+
importedPath = tsPath
|
|
116
|
+
} else {
|
|
117
|
+
// Try .js extension as well
|
|
118
|
+
const jsPath = importedPath + '.js'
|
|
119
|
+
if (fs.existsSync(jsPath)) {
|
|
120
|
+
// Skip .js files, they don't need transpilation
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
123
|
+
}
|
|
138
124
|
}
|
|
139
125
|
|
|
140
|
-
//
|
|
141
|
-
|
|
126
|
+
// If it's a TypeScript file, recursively transpile it and its dependencies
|
|
127
|
+
if (importedPath.endsWith('.ts') && fs.existsSync(importedPath)) {
|
|
128
|
+
transpileFileAndDeps(importedPath)
|
|
129
|
+
}
|
|
142
130
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
131
|
+
|
|
132
|
+
// After all dependencies are transpiled, rewrite imports in this file
|
|
133
|
+
jsContent = jsContent.replace(
|
|
134
|
+
/from\s+['"](\..+?)(?:\.ts)?['"]/g,
|
|
135
|
+
(match, importPath) => {
|
|
136
|
+
let resolvedPath = path.resolve(fileBaseDir, importPath)
|
|
137
|
+
|
|
138
|
+
// Handle .js extension that might be .ts
|
|
139
|
+
if (resolvedPath.endsWith('.js')) {
|
|
140
|
+
const tsVersion = resolvedPath.replace(/\.js$/, '.ts')
|
|
141
|
+
if (transpiledFiles.has(tsVersion)) {
|
|
142
|
+
const tempFile = transpiledFiles.get(tsVersion)
|
|
143
|
+
const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
|
|
144
|
+
// Ensure the path starts with ./
|
|
145
|
+
if (!relPath.startsWith('.')) {
|
|
146
|
+
return `from './${relPath}'`
|
|
147
|
+
}
|
|
148
|
+
return `from '${relPath}'`
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Try with .ts extension
|
|
153
|
+
const tsPath = resolvedPath.endsWith('.ts') ? resolvedPath : resolvedPath + '.ts'
|
|
154
|
+
|
|
155
|
+
// If we transpiled this file, use the temp file
|
|
156
|
+
if (transpiledFiles.has(tsPath)) {
|
|
157
|
+
const tempFile = transpiledFiles.get(tsPath)
|
|
158
|
+
const relPath = path.relative(fileBaseDir, tempFile).replace(/\\/g, '/')
|
|
159
|
+
// Ensure the path starts with ./
|
|
160
|
+
if (!relPath.startsWith('.')) {
|
|
161
|
+
return `from './${relPath}'`
|
|
162
|
+
}
|
|
163
|
+
return `from '${relPath}'`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Otherwise, keep the import as-is
|
|
167
|
+
return match
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
// Write the transpiled file with updated imports
|
|
172
|
+
const tempFile = filePath.replace(/\.ts$/, '.temp.mjs')
|
|
173
|
+
fs.writeFileSync(tempFile, jsContent)
|
|
174
|
+
transpiledFiles.set(filePath, tempFile)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Start recursive transpilation from the main file
|
|
178
|
+
transpileFileAndDeps(mainFilePath)
|
|
179
|
+
|
|
180
|
+
// Get the main transpiled file
|
|
181
|
+
const tempJsFile = transpiledFiles.get(mainFilePath)
|
|
148
182
|
|
|
149
183
|
// Store all temp files for cleanup
|
|
150
|
-
const allTempFiles =
|
|
184
|
+
const allTempFiles = Array.from(transpiledFiles.values())
|
|
151
185
|
|
|
152
186
|
return { tempFile: tempJsFile, allTempFiles }
|
|
153
187
|
}
|
package/package.json
CHANGED
|
@@ -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;
|
package/typings/types.d.ts
CHANGED
|
@@ -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;
|