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

Function helper

lib/command/generate.js:231–269  ·  view source on GitHub ↗
(genPath)

Source from the content-addressed store, hash-verified

229`
230
231export async function helper(genPath) {
232 const testsPath = getTestRoot(genPath)
233
234 output.print('Creating a new helper')
235 output.print('--------------------------')
236
237 return inquirer
238 .prompt([
239 {
240 type: 'input',
241 name: 'name',
242 message: 'Name of a Helper',
243 validate: val => !!val,
244 },
245 {
246 type: 'input',
247 name: 'filename',
248 message: 'Where should it be stored',
249 default: answers => `./${answers.name.toLowerCase()}_helper.${extension}`,
250 },
251 ])
252 .then(result => {
253 const name = ucfirst(result.name)
254 const helperFile = path.join(testsPath, result.filename)
255 const dir = path.dirname(helperFile)
256 if (!fileExists(dir)) fs.mkdirSync(dir)
257
258 if (!safeFileWrite(helperFile, helperTemplate.replace(/{{name}}/g, name))) return
259 output.success(`Helper for ${name} was created in ${helperFile}`)
260 output.print(`Update your config file (add to ${colors.cyan('helpers')} section):
261
262helpers: {
263 ${name}: {
264 require: '${result.filename}',
265 },
266},
267 `)
268 })
269}
270
271import { fileURLToPath } from 'url'
272const __dirname = path.dirname(fileURLToPath(import.meta.url))

Callers

nothing calls this directly

Calls 4

getTestRootFunction · 0.90
ucfirstFunction · 0.90
fileExistsFunction · 0.90
safeFileWriteFunction · 0.90

Tested by

no test coverage detected