MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / getImportString

Function getImportString

lib/command/definitions.js:228–251  ·  view source on GitHub ↗

* * * @param {string} testsPath * @param {string} targetFolderPath * @param {Object } pathsToType * @param {Object } pathsToValue * * @returns {Array }

(testsPath, targetFolderPath, pathsToType, pathsToValue)

Source from the content-addressed store, hash-verified

226 * @returns {Array<string>}
227 */
228function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue) {
229 const importStrings = []
230
231 for (const name in pathsToType) {
232 const originalPath = pathsToType[name]
233 const relativePath = getPath(originalPath, targetFolderPath, testsPath)
234 // 4.x is ESM-first: step files and page objects use `export default`,
235 // so the type is reached via `.default` regardless of file extension
236 // (.js, .ts, or no extension, as set in `include`).
237 importStrings.push(`type ${name} = typeof import('${relativePath}').default;`)
238 }
239
240 for (const name in pathsToValue) {
241 const originalPath = pathsToValue[name]
242 const relativePath = getPath(originalPath, targetFolderPath, testsPath)
243 if (originalPath.endsWith('.js') || originalPath.endsWith('.ts')) {
244 importStrings.push(`type ${name} = InstanceType<typeof import('${relativePath}').default>;`)
245 } else {
246 importStrings.push(`type ${name} = import('${relativePath}');`)
247 }
248 }
249
250 return importStrings
251}
252
253/**
254 * @param {Map} map

Callers 1

definitions.jsFile · 0.85

Calls 2

getPathFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected