Skip to content

Commit

Permalink
fix: global retry
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored and Thanh Nguyen committed May 26, 2023
1 parent 98ebc91 commit 14c7277
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/listener/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = function () {
if (!retryConfig) return;

if (Number.isInteger(+retryConfig)) {
if (test.retries() === -1) test.retries(retryConfig);
return;
}

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

if (config.Scenario) {
if (isNotSet(test.retries())) test.retries(config.Scenario);
if (test.retries() === -1) test.retries(config.Scenario);
output.log(`Retries: ${config.Scenario}`);
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/data/sandbox/configs/retryHooks/codecept.retry.global.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
CustomHelper: {
require: './helper.js',
},
},
retry: 2,
bootstrap: null,
mocha: {},
name: 'retryHooks',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
exports.config = {
tests: './*_test.js',
output: './output',
helpers: {
CustomHelper: {
require: './helper.js',
},
},
retry: {
Scenario: 3,
},
bootstrap: null,
mocha: {},
name: 'retryHooks',
};
10 changes: 10 additions & 0 deletions test/data/sandbox/configs/retryHooks/retry_global_scenario_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature('Retry scenario global config');

let i = 0;

Scenario('#globalScenarioRetry works', () => {
console.log('ok', i, new Date());
i++;
if (i < 3) throw new Error('not works');
console.log('works');
});
10 changes: 10 additions & 0 deletions test/data/sandbox/configs/retryHooks/retry_global_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature('Retry global config');

let i = 0;

Scenario('#globalRetry works', () => {
console.log('ok', i, new Date());
i++;
if (i < 3) throw new Error('not works');
console.log('works');
});
20 changes: 18 additions & 2 deletions test/runner/retry_hooks_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('CodeceptJS Retry Hooks', function () {
it(`run ${retryHook} config`, (done) => {
exec(config_run_config('codecept.conf.js', retryHook), (err, stdout) => {
debug_this_test && console.log(stdout);
expect(stdout).toContain('OK | 1 passed');
expect(stdout).toContain('1 passed');
done();
});
});
Expand All @@ -23,7 +23,7 @@ describe('CodeceptJS Retry Hooks', function () {
it(`should ${retryHook} set hook retries from global config`, (done) => {
exec(config_run_config('codecept.retry.obj.conf.js', retryHook), (err, stdout) => {
debug_this_test && console.log(stdout);
expect(stdout).toContain('OK | 1 passed');
expect(stdout).toContain('1 passed');
done();
});
});
Expand All @@ -38,4 +38,20 @@ describe('CodeceptJS Retry Hooks', function () {
done();
});
});

it('should set global retry', (done) => {
exec(config_run_config('codecept.retry.global.conf.js', '#globalRetry'), (err, stdout) => {
debug_this_test && console.log(stdout);
expect(stdout).toContain('1 passed');
done();
});
});

it('should set global scenario retry', (done) => {
exec(config_run_config('codecept.retry.global.scenario.conf.js', '#globalScenarioRetry'), (err, stdout) => {
debug_this_test && console.log(stdout);
expect(stdout).toContain('1 passed');
done();
});
});
});

0 comments on commit 14c7277

Please sign in to comment.