(genPath, opts)
| 109 | ` |
| 110 | |
| 111 | export async function pageObject(genPath, opts) { |
| 112 | const testsPath = getTestRoot(genPath) |
| 113 | const config = await getConfig(testsPath) |
| 114 | const kind = opts.T || 'page' |
| 115 | if (!config) return |
| 116 | |
| 117 | let configFile = path.join(testsPath, `codecept.conf.${extension}`) |
| 118 | |
| 119 | if (!fileExists(configFile)) { |
| 120 | extension = 'ts' |
| 121 | configFile = path.join(testsPath, `codecept.conf.${extension}`) |
| 122 | } |
| 123 | output.print(`Creating a new ${kind} object`) |
| 124 | output.print('--------------------------') |
| 125 | |
| 126 | return inquirer |
| 127 | .prompt([ |
| 128 | { |
| 129 | type: 'input', |
| 130 | name: 'name', |
| 131 | message: `Name of a ${kind} object`, |
| 132 | validate: val => !!val, |
| 133 | }, |
| 134 | { |
| 135 | type: 'input', |
| 136 | name: 'filename', |
| 137 | message: 'Where should it be stored', |
| 138 | default: answers => `./${kind}s/${answers.name}.${extension}`, |
| 139 | }, |
| 140 | { |
| 141 | type: 'list', |
| 142 | name: 'objectType', |
| 143 | message: 'What is your preferred object type', |
| 144 | choices: ['module', 'class'], |
| 145 | default: 'module', |
| 146 | }, |
| 147 | ]) |
| 148 | .then(result => { |
| 149 | const pageObjectFile = path.join(testsPath, result.filename) |
| 150 | const dir = path.dirname(pageObjectFile) |
| 151 | if (!fileExists(dir)) fs.mkdirSync(dir) |
| 152 | |
| 153 | let actor = 'actor' |
| 154 | |
| 155 | if (config.include.I) { |
| 156 | let actorPath = config.include.I |
| 157 | if (actorPath.charAt(0) === '.') { |
| 158 | // relative path |
| 159 | actorPath = path.relative(dir, path.dirname(path.join(testsPath, actorPath))) + actorPath.substring(1) // get an upper level |
| 160 | } |
| 161 | actor = `import('${actorPath}')` |
| 162 | } |
| 163 | |
| 164 | const name = lcfirst(result.name) + ucfirst(kind) |
| 165 | if (result.objectType === 'module' && extension === 'ts') { |
| 166 | if (!safeFileWrite(pageObjectFile, poModuleTemplateTS.replace('{{actor}}', actor))) return |
| 167 | } else if (result.objectType === 'module' && extension === 'js') { |
| 168 | if (!safeFileWrite(pageObjectFile, pageObjectTemplate.replace('{{actor}}', actor))) return |
nothing calls this directly
no test coverage detected