| 535 | * @param {string} featureName - Name of the feature to scaffold tests for. |
| 536 | */ |
| 537 | export async function runnerCreateTests(featureName) { |
| 538 | const fsp = fs.promises |
| 539 | |
| 540 | const configDir = path.join('test/data/sandbox/configs', featureName) |
| 541 | await fsp.mkdir(configDir, { recursive: true }) |
| 542 | |
| 543 | const configContent = `exports.config = { |
| 544 | tests: './*_test.js', |
| 545 | output: './output', |
| 546 | helpers: { |
| 547 | FileSystem: {}, |
| 548 | }, |
| 549 | include: {}, |
| 550 | bootstrap: false, |
| 551 | mocha: {}, |
| 552 | name: '${featureName} tests' |
| 553 | } |
| 554 | ` |
| 555 | await fsp.writeFile(path.join(configDir, `codecept.conf.js`), configContent) |
| 556 | |
| 557 | const testContent = `Feature('${featureName}'); |
| 558 | |
| 559 | Scenario('test ${featureName}', ({ I }) => { |
| 560 | // Add test steps here |
| 561 | }); |
| 562 | ` |
| 563 | await fsp.writeFile(path.join(configDir, `${featureName}_test.js`), testContent) |
| 564 | |
| 565 | const runnerTestContent = `const { expect } = require('expect') |
| 566 | const exec = require('child_process').exec |
| 567 | const { codecept_dir, codecept_run } = require('./consts') |
| 568 | const debug = require('debug')('codeceptjs:tests') |
| 569 | |
| 570 | const config_run_config = (config, grep, verbose = false) => |
| 571 | \`\${codecept_run} \${verbose ? '--verbose' : ''} --config \${codecept_dir}/configs/${featureName}/\${config} \${grep ? \`--grep "\${grep}"\` : ''}\` |
| 572 | |
| 573 | describe('CodeceptJS ${featureName}', function () { |
| 574 | this.timeout(10000) |
| 575 | |
| 576 | it('should run ${featureName} test', done => { |
| 577 | exec(config_run_config('codecept.conf.js'), (err, stdout) => { |
| 578 | debug(stdout) |
| 579 | expect(stdout).toContain('OK') |
| 580 | expect(err).toBeFalsy() |
| 581 | done() |
| 582 | }) |
| 583 | }) |
| 584 | }) |
| 585 | ` |
| 586 | await fsp.writeFile(path.join('test/runner', `${featureName}_test.js`), runnerTestContent) |
| 587 | |
| 588 | say(`Created test files for feature: ${featureName}`) |
| 589 | say('Run codecept tests with:') |
| 590 | say(`./bin/codecept.js run --config ${configDir}/codecept.conf.js`) |
| 591 | say('') |
| 592 | say('Run tests with:') |
| 593 | say(`npx mocha test/runner --grep ${featureName}`) |
| 594 | } |