Skip to content

Commit 6f5f03b

Browse files
committed
fix: gherkin_test and scenario stale test
1 parent 8e2fc37 commit 6f5f03b

File tree

3 files changed

+56
-52
lines changed

3 files changed

+56
-52
lines changed

lib/codecept.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default class Codecept {
204204
}
205205

206206
return new Promise((resolve, reject) => {
207-
try {x
207+
try {
208208
event.emit(event.all.before, this);
209209
mocha.run(() => {
210210
event.emit(event.all.result, this);

test/runner/gherkin_test.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
const assert = require('assert')
2-
const path = require('path')
3-
const fs = require('fs')
4-
const exec = require('child_process').exec
1+
import assert from 'assert';
2+
import path from 'path';
3+
import fs from 'fs';
4+
import { exec } from 'child_process';
55

6-
const runner = path.join(__dirname, '/../../bin/codecept.js')
7-
const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/gherkin/')
6+
const runner = path.join(path.dirname(import.meta.url), '/../../bin/codecept.js');
7+
const codecept_dir = path.join(path.dirname(import.meta.url), '/../data/sandbox/configs/gherkin/');
88

99
describe('gherkin bdd commands', () => {
1010
describe('bdd:init', () => {
11-
const codecept_dir_js = path.join(codecept_dir, 'config_js')
12-
const codecept_dir_ts = path.join(codecept_dir, 'config_ts')
11+
const codecept_dir_js = path.join(codecept_dir, 'config_js');
12+
const codecept_dir_ts = path.join(codecept_dir, 'config_ts');
1313

1414
beforeEach(() => {
1515
fs.copyFileSync(
1616
path.join(codecept_dir_js, 'codecept.conf.init.js'),
1717
path.join(codecept_dir_js, 'codecept.conf.js'),
18-
)
18+
);
1919
fs.copyFileSync(
2020
path.join(codecept_dir_ts, 'codecept.conf.init.ts'),
2121
path.join(codecept_dir_ts, 'codecept.conf.ts'),
22-
)
23-
})
22+
);
23+
});
2424

2525
afterEach(() => {
2626
try {
27-
fs.rmSync(path.join(codecept_dir_js, 'codecept.conf.js'))
27+
fs.rmSync(path.join(codecept_dir_js, 'codecept.conf.js'));
2828
fs.rmSync(path.join(codecept_dir_js, 'features'), {
2929
recursive: true,
30-
})
30+
});
3131
fs.rmSync(path.join(codecept_dir_js, 'step_definitions'), {
3232
recursive: true,
33-
})
33+
});
3434
} catch (e) {
3535
// catch some error
3636
}
3737
try {
38-
fs.rmSync(path.join(codecept_dir_ts, 'codecept.conf.ts'))
38+
fs.rmSync(path.join(codecept_dir_ts, 'codecept.conf.ts'));
3939
fs.rmSync(path.join(codecept_dir_ts, 'features'), {
4040
recursive: true,
41-
})
41+
});
4242
fs.rmSync(path.join(codecept_dir_ts, 'step_definitions'), {
4343
recursive: true,
44-
})
44+
});
4545
} catch (e) {
4646
// catch some error
4747
}
48-
})
49-
;[
48+
});
49+
[
5050
{
5151
codecept_dir_test: codecept_dir_js,
5252
extension: 'js',
@@ -58,23 +58,23 @@ describe('gherkin bdd commands', () => {
5858
].forEach(({ codecept_dir_test, extension }) => {
5959
it(`prepare CodeceptJS to run feature files (codecept.conf.${extension})`, (done) => {
6060
exec(`${runner} gherkin:init ${codecept_dir_test}`, (err, stdout) => {
61-
let dir = path.join(codecept_dir_test, 'features')
61+
let dir = path.join(codecept_dir_test, 'features');
6262

63-
stdout.should.include('Initializing Gherkin (Cucumber BDD) for CodeceptJS')
64-
stdout.should.include(`Created ${dir}, place your *.feature files in it`)
65-
stdout.should.include('Created sample feature file: features/basic.feature')
63+
stdout.should.include('Initializing Gherkin (Cucumber BDD) for CodeceptJS');
64+
stdout.should.include(`Created ${dir}, place your *.feature files in it`);
65+
stdout.should.include('Created sample feature file: features/basic.feature');
6666

67-
dir = path.join(codecept_dir_test, 'step_definitions')
68-
stdout.should.include(`Created ${dir}, place step definitions into it`)
69-
stdout.should.include(`Created sample steps file: step_definitions/steps.${extension}`)
70-
assert(!err)
67+
dir = path.join(codecept_dir_test, 'step_definitions');
68+
stdout.should.include(`Created ${dir}, place step definitions into it`);
69+
stdout.should.include(`Created sample steps file: step_definitions/steps.${extension}`);
70+
assert(!err);
7171

72-
const configResult = fs.readFileSync(path.join(codecept_dir_test, `codecept.conf.${extension}`)).toString()
73-
configResult.should.contain("features: './features/*.feature'")
74-
configResult.should.contain(`steps: ['./step_definitions/steps.${extension}']`)
75-
done()
76-
})
77-
})
78-
})
79-
})
80-
})
72+
const configResult = fs.readFileSync(path.join(codecept_dir_test, `codecept.conf.${extension}`)).toString();
73+
configResult.should.contain("features: './features/*.feature'");
74+
configResult.should.contain(`steps: ['./step_definitions/steps.${extension}']`);
75+
done();
76+
});
77+
});
78+
});
79+
});
80+
});

test/runner/scenario_stale_test.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
const { expect } = require('expect')
2-
const path = require('path')
3-
const { exec } = require('child_process')
1+
import { expect } from 'expect';
2+
import path from 'path';
3+
import { exec } from 'child_process';
4+
import { fileURLToPath } from 'url';
45

5-
const runner = path.join(__dirname, '/../../bin/codecept.js')
6-
const codecept_dir = path.join(__dirname, '/../data/sandbox')
7-
const codecept_run = `${runner} run`
8-
const config_run_config = (config) => `${codecept_run} --config ${codecept_dir}/${config}`
6+
// ESM doesn't have __dirname, so we calculate it from import.meta.url
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
const runner = path.join(__dirname, '/../../bin/codecept.js');
10+
const codecept_dir = path.join(__dirname, '/../data/sandbox');
11+
const codecept_run = `${runner} run`;
12+
const config_run_config = (config) => `${codecept_run} --config ${codecept_dir}/${config}`;
913

1014
describe('Scenario termination check', () => {
1115
before(() => {
12-
process.chdir(codecept_dir)
13-
})
16+
process.chdir(codecept_dir);
17+
});
1418

1519
it('Should always fail and terminate', (done) => {
1620
exec(config_run_config('codecept.scenario-stale.js'), (err, stdout) => {
17-
expect(stdout).toContain('should not stale scenario error') // feature
18-
expect(err).toBeTruthy()
19-
done()
20-
})
21-
})
22-
})
21+
expect(stdout).toContain('should not stale scenario error'); // feature
22+
expect(err).toBeTruthy();
23+
done();
24+
});
25+
});
26+
});

0 commit comments

Comments
 (0)