|
| 1 | +const assert = require("assert"); |
| 2 | +const path = require("path"); |
| 3 | +const fs = require("fs"); |
| 4 | +const exec = require("child_process").exec; |
| 5 | + |
| 6 | +const runner = path.join(__dirname, "/../../bin/codecept.js"); |
| 7 | +const codecept_dir = path.join(__dirname, "/../data/sandbox/configs/gherkin/"); |
| 8 | + |
| 9 | +describe("gherkin bdd commands", () => { |
| 10 | + describe("bdd:init", () => { |
| 11 | + let codecept_dir_js = path.join(codecept_dir, "config_js"); |
| 12 | + let codecept_dir_ts = path.join(codecept_dir, "config_ts"); |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + fs.copyFileSync( |
| 16 | + path.join(codecept_dir_js, "codecept.conf.init.js"), |
| 17 | + path.join(codecept_dir_js, "codecept.conf.js") |
| 18 | + ); |
| 19 | + fs.copyFileSync( |
| 20 | + path.join(codecept_dir_ts, "codecept.conf.init.ts"), |
| 21 | + path.join(codecept_dir_ts, "codecept.conf.ts") |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(() => { |
| 26 | + try { |
| 27 | + fs.rmSync(path.join(codecept_dir_js, "codecept.conf.js")); |
| 28 | + fs.rmSync(path.join(codecept_dir_js, "features"), { |
| 29 | + recursive: true, |
| 30 | + }); |
| 31 | + fs.rmSync(path.join(codecept_dir_js, "step_definitions"), { |
| 32 | + recursive: true, |
| 33 | + }); |
| 34 | + } catch (e) {} |
| 35 | + try { |
| 36 | + fs.rmSync(path.join(codecept_dir_ts, "codecept.conf.ts")); |
| 37 | + fs.rmSync(path.join(codecept_dir_ts, "features"), { |
| 38 | + recursive: true, |
| 39 | + }); |
| 40 | + fs.rmSync(path.join(codecept_dir_ts, "step_definitions"), { |
| 41 | + recursive: true, |
| 42 | + }); |
| 43 | + } catch (e) {} |
| 44 | + }); |
| 45 | + |
| 46 | + [ |
| 47 | + { |
| 48 | + codecept_dir_test: codecept_dir_js, |
| 49 | + extension: "js", |
| 50 | + }, |
| 51 | + { |
| 52 | + codecept_dir_test: codecept_dir_ts, |
| 53 | + extension: "ts", |
| 54 | + }, |
| 55 | + ].forEach(({ codecept_dir_test, extension }) => { |
| 56 | + it(`prepare CodeceptJS to run feature files (codecept.conf.${extension})`, (done) => { |
| 57 | + exec(`${runner} gherkin:init ${codecept_dir_test}`, (err, stdout) => { |
| 58 | + let dir = path.join(codecept_dir_test, "features"); |
| 59 | + |
| 60 | + stdout.should.include( |
| 61 | + "Initializing Gherkin (Cucumber BDD) for CodeceptJS" |
| 62 | + ); |
| 63 | + stdout.should.include( |
| 64 | + `Created ${dir}, place your *.feature files in it` |
| 65 | + ); |
| 66 | + stdout.should.include( |
| 67 | + "Created sample feature file: features/basic.feature" |
| 68 | + ); |
| 69 | + |
| 70 | + dir = path.join(codecept_dir_test, "step_definitions"); |
| 71 | + stdout.should.include( |
| 72 | + `Created ${dir}, place step definitions into it` |
| 73 | + ); |
| 74 | + stdout.should.include( |
| 75 | + `Created sample steps file: step_definitions/steps.${extension}` |
| 76 | + ); |
| 77 | + assert(!err); |
| 78 | + |
| 79 | + const configResult = fs |
| 80 | + .readFileSync( |
| 81 | + path.join(codecept_dir_test, `codecept.conf.${extension}`) |
| 82 | + ) |
| 83 | + .toString(); |
| 84 | + configResult.should.contain(`features: './features/*.feature'`); |
| 85 | + configResult.should.contain( |
| 86 | + `steps: ['./step_definitions/steps.${extension}']` |
| 87 | + ); |
| 88 | + done(); |
| 89 | + }); |
| 90 | + }); |
| 91 | + }); |
| 92 | + }); |
| 93 | +}); |
0 commit comments