Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: global retry #3667

Merged
merged 1 commit into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
});