(genPath)
| 20 | |
| 21 | // generates empty test |
| 22 | export async function test(genPath) { |
| 23 | const testsPath = getTestRoot(genPath) |
| 24 | store.codeceptDir = testsPath |
| 25 | global.codecept_dir = testsPath |
| 26 | const config = await getConfig(testsPath) |
| 27 | if (!config) return |
| 28 | |
| 29 | output.print('Creating a new test...') |
| 30 | output.print('----------------------') |
| 31 | |
| 32 | const defaultExt = config.tests.match(/([^\*/]*?)$/)[1] || `_test.${extension}` |
| 33 | |
| 34 | return inquirer |
| 35 | .prompt([ |
| 36 | { |
| 37 | type: 'input', |
| 38 | name: 'feature', |
| 39 | message: 'Feature which is being tested (ex: account, login, etc)', |
| 40 | validate: val => !!val, |
| 41 | }, |
| 42 | { |
| 43 | type: 'input', |
| 44 | message: 'Filename of a test', |
| 45 | name: 'filename', |
| 46 | default(answers) { |
| 47 | return answers.feature.replace(' ', '_') + defaultExt |
| 48 | }, |
| 49 | }, |
| 50 | ]) |
| 51 | .then(async result => { |
| 52 | const testFilePath = path.dirname(path.join(testsPath, config.tests)).replace(/\*\*$/, '') |
| 53 | let testFile = path.join(testFilePath, result.filename) |
| 54 | const ext = path.extname(testFile) |
| 55 | if (!ext) testFile += defaultExt |
| 56 | const dir = path.dirname(testFile) |
| 57 | if (!fileExists(dir)) mkdirp.sync(dir) |
| 58 | let testContent = testTemplate.replace('{{feature}}', result.feature) |
| 59 | |
| 60 | const containerModule = await import('../container.js') |
| 61 | const container = containerModule.default || containerModule |
| 62 | await container.create(config, {}) |
| 63 | // translate scenario test |
| 64 | if (container.translation().loaded) { |
| 65 | const vocabulary = container.translation().vocabulary |
| 66 | testContent = testContent.replace('{{actor}}', container.translation().I) |
| 67 | if (vocabulary.contexts.Feature) testContent = testContent.replace('Feature', vocabulary.contexts.Feature) |
| 68 | if (vocabulary.contexts.Scenario) testContent = testContent.replace('Scenario', vocabulary.contexts.Scenario) |
| 69 | output.print(`Test was created in ${colors.bold(config.translation)} localization. See: https://codecept.io/translation/`) |
| 70 | } else { |
| 71 | testContent = testContent.replace('{{actor}}', 'I') |
| 72 | } |
| 73 | if (!config.fullPromiseBased) testContent = testContent.replace('async', '') |
| 74 | |
| 75 | if (!safeFileWrite(testFile, testContent)) return |
| 76 | output.success(`\nTest for ${result.filename} was created in ${testFile}`) |
| 77 | }) |
| 78 | } |
| 79 |
nothing calls this directly
no test coverage detected