Skip to content

Commit 5a549b6

Browse files
authored
fix: global retry (#3667)
1 parent 98ebc91 commit 5a549b6

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

lib/listener/retry.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = function () {
4444
if (!retryConfig) return;
4545

4646
if (Number.isInteger(+retryConfig)) {
47+
if (test.retries() === -1) test.retries(retryConfig);
4748
return;
4849
}
4950

@@ -59,7 +60,7 @@ module.exports = function () {
5960
}
6061

6162
if (config.Scenario) {
62-
if (isNotSet(test.retries())) test.retries(config.Scenario);
63+
if (test.retries() === -1) test.retries(config.Scenario);
6364
output.log(`Retries: ${config.Scenario}`);
6465
}
6566
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.config = {
2+
tests: './*_test.js',
3+
output: './output',
4+
helpers: {
5+
CustomHelper: {
6+
require: './helper.js',
7+
},
8+
},
9+
retry: 2,
10+
bootstrap: null,
11+
mocha: {},
12+
name: 'retryHooks',
13+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exports.config = {
2+
tests: './*_test.js',
3+
output: './output',
4+
helpers: {
5+
CustomHelper: {
6+
require: './helper.js',
7+
},
8+
},
9+
retry: {
10+
Scenario: 3,
11+
},
12+
bootstrap: null,
13+
mocha: {},
14+
name: 'retryHooks',
15+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature('Retry scenario global config');
2+
3+
let i = 0;
4+
5+
Scenario('#globalScenarioRetry works', () => {
6+
console.log('ok', i, new Date());
7+
i++;
8+
if (i < 3) throw new Error('not works');
9+
console.log('works');
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature('Retry global config');
2+
3+
let i = 0;
4+
5+
Scenario('#globalRetry works', () => {
6+
console.log('ok', i, new Date());
7+
i++;
8+
if (i < 3) throw new Error('not works');
9+
console.log('works');
10+
});

test/runner/retry_hooks_test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('CodeceptJS Retry Hooks', function () {
1313
it(`run ${retryHook} config`, (done) => {
1414
exec(config_run_config('codecept.conf.js', retryHook), (err, stdout) => {
1515
debug_this_test && console.log(stdout);
16-
expect(stdout).toContain('OK | 1 passed');
16+
expect(stdout).toContain('1 passed');
1717
done();
1818
});
1919
});
@@ -23,7 +23,7 @@ describe('CodeceptJS Retry Hooks', function () {
2323
it(`should ${retryHook} set hook retries from global config`, (done) => {
2424
exec(config_run_config('codecept.retry.obj.conf.js', retryHook), (err, stdout) => {
2525
debug_this_test && console.log(stdout);
26-
expect(stdout).toContain('OK | 1 passed');
26+
expect(stdout).toContain('1 passed');
2727
done();
2828
});
2929
});
@@ -38,4 +38,20 @@ describe('CodeceptJS Retry Hooks', function () {
3838
done();
3939
});
4040
});
41+
42+
it('should set global retry', (done) => {
43+
exec(config_run_config('codecept.retry.global.conf.js', '#globalRetry'), (err, stdout) => {
44+
debug_this_test && console.log(stdout);
45+
expect(stdout).toContain('1 passed');
46+
done();
47+
});
48+
});
49+
50+
it('should set global scenario retry', (done) => {
51+
exec(config_run_config('codecept.retry.global.scenario.conf.js', '#globalScenarioRetry'), (err, stdout) => {
52+
debug_this_test && console.log(stdout);
53+
expect(stdout).toContain('1 passed');
54+
done();
55+
});
56+
});
4157
});

0 commit comments

Comments
 (0)