(modulePath, supportObjectName)
| 843 | } |
| 844 | |
| 845 | async function loadSupportObject(modulePath, supportObjectName) { |
| 846 | if (!modulePath) { |
| 847 | throw new Error(`Support object "${supportObjectName}" is not defined`) |
| 848 | } |
| 849 | // If function/class provided directly |
| 850 | if (typeof modulePath === 'function') { |
| 851 | try { |
| 852 | // class constructor |
| 853 | if (modulePath.prototype && modulePath.prototype.constructor === modulePath) { |
| 854 | return new modulePath() |
| 855 | } |
| 856 | // plain function factory |
| 857 | return modulePath() |
| 858 | } catch (err) { |
| 859 | throw new Error(`Could not include object ${supportObjectName} from function: ${err.message}`) |
| 860 | } |
| 861 | } |
| 862 | if (typeof modulePath === 'string' && modulePath.charAt(0) === '.') { |
| 863 | modulePath = path.join(store.codeceptDir, modulePath) |
| 864 | } |
| 865 | try { |
| 866 | // Use dynamic import for both ESM and CJS modules |
| 867 | let importPath = modulePath |
| 868 | let tempJsFile = null |
| 869 | let fileMapping = null |
| 870 | |
| 871 | if (typeof importPath === 'string') { |
| 872 | const ext = path.extname(importPath) |
| 873 | |
| 874 | // Handle TypeScript files |
| 875 | if (ext === '.ts') { |
| 876 | try { |
| 877 | // Use the TypeScript transpilation utility |
| 878 | const typescript = ((await import('typescript')).default || (await import('typescript'))) |
| 879 | const { tempFile, allTempFiles, fileMapping: mapping } = await transpileTypeScript(importPath, typescript) |
| 880 | |
| 881 | debug(`Transpiled TypeScript file: ${importPath} -> ${tempFile}`) |
| 882 | |
| 883 | // Attach cleanup handler |
| 884 | importPath = tempFile |
| 885 | // Store temp files list in a way that cleanup can access them |
| 886 | tempJsFile = allTempFiles |
| 887 | fileMapping = mapping |
| 888 | // Store file mapping in container for runtime error fixing (merge with existing) |
| 889 | if (!container.tsFileMapping) { |
| 890 | container.tsFileMapping = new Map() |
| 891 | } |
| 892 | for (const [key, value] of mapping.entries()) { |
| 893 | container.tsFileMapping.set(key, value) |
| 894 | } |
| 895 | } catch (tsError) { |
| 896 | throw new Error(`Failed to load TypeScript file ${importPath}: ${tsError.message}. Make sure 'typescript' package is installed.`) |
| 897 | } |
| 898 | } else if (!ext) { |
| 899 | // Append .js if no extension provided (ESM resolution requires it) |
| 900 | importPath = `${importPath}.js` |
| 901 | } |
| 902 | } |
no test coverage detected