Skip to content

Commit 7bf65a6

Browse files
authored
Improved pause (#1400)
* updated helper formatting in docs * improved interactive pause * fixed linting
1 parent 566203d commit 7bf65a6

File tree

9 files changed

+39
-14
lines changed

9 files changed

+39
-14
lines changed

examples/codecept.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"stepByStepReport": {},
3737
"autoDelay": {
3838
"enabled": true
39+
},
40+
"retryFailedStep": {
41+
"enabled": true
3942
}
4043
},
4144
"tests": "./*_test.js",

examples/github_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Scenario('Visit Home Page @retry', async (I) => {
1414

1515
Scenario('search @grop', (I) => {
1616
I.amOnPage('https://github.com/search');
17+
pause();
1718
I.fillField('Search GitHub', 'CodeceptJS');
1819
I.pressKey('Enter');
1920
I.wait(1);

lib/codecept.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fsPath = require('path');
22
const readFileSync = require('fs').readFileSync;
3-
const Container = require('./container');
3+
const container = require('./container');
44
const Config = require('./config');
55
const event = require('../lib/event');
66
const glob = require('glob');
@@ -52,7 +52,7 @@ class Codecept {
5252
init(dir) {
5353
this.initGlobals(dir);
5454
// initializing listeners
55-
Container.create(this.config, this.opts);
55+
container.create(this.config, this.opts);
5656
this.runHooks();
5757
}
5858

@@ -151,7 +151,7 @@ class Codecept {
151151
* @param {string} [test]
152152
*/
153153
run(test) {
154-
const mocha = Container.mocha();
154+
const mocha = container.mocha();
155155
mocha.files = this.testFiles;
156156
if (test) {
157157
test = fsPath.join(global.codecept_dir, test);

lib/listener/steps.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const event = require('../event');
2+
const store = require('../store');
23

34
let currentTest;
45
let currentHook;
@@ -52,6 +53,7 @@ module.exports = function () {
5253
});
5354

5455
event.dispatcher.on(event.step.started, (step) => {
56+
if (store.debugMode) return;
5557
if (currentHook && Array.isArray(currentHook.steps)) {
5658
return currentHook.steps.push(step);
5759
}

lib/pause.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const container = require('./container');
2+
const store = require('./store');
23
const recorder = require('./recorder');
34
const event = require('./event');
45
const output = require('./output');
@@ -29,19 +30,18 @@ const pause = function () {
2930

3031
function pauseSession() {
3132
recorder.session.start('pause');
32-
output.print(colors.yellow(' Interactive shell started'));
33-
output.print(colors.yellow(` Press ${colors.bold('ENTER')} to run the next step`));
34-
output.print(colors.yellow(` Enter ${colors.bold('exit')} to exit the interactive shell and resume the test`));
3533
if (!next) {
36-
output.print(colors.yellow(' - Use JavaScript syntax to try steps in action'));
37-
output.print(colors.yellow(` - Press ${colors.bold('TAB')} twice to see all available commands`));
34+
output.print(colors.yellow(' Interactive shell started'));
35+
output.print(colors.yellow(' Use JavaScript syntax to try steps in action'));
3836
output.print(colors.yellow(` - Press ${colors.bold('ENTER')} to run the next step`));
37+
output.print(colors.yellow(` - Press ${colors.bold('TAB')} twice to see all available commands`));
38+
output.print(colors.yellow(` - Type ${colors.bold('exit')} + Enter to exit the interactive shell`));
3939
}
4040
rl = readline.createInterface(process.stdin, process.stdout, completer);
4141

4242
rl.on('line', parseInput);
4343
rl.on('close', () => {
44-
console.log('Exiting interactive shell....');
44+
if (!next) console.log('Exiting interactive shell....');
4545
});
4646
return new Promise(((resolve) => {
4747
finish = resolve;
@@ -52,13 +52,15 @@ function pauseSession() {
5252
function parseInput(cmd) {
5353
rl.pause();
5454
next = false;
55+
store.debugMode = false;
5556
if (cmd === '') next = true;
56-
if (!cmd || cmd === 'resume') {
57+
if (!cmd || cmd === 'resume' || cmd === 'exit') {
5758
finish();
5859
recorder.session.restore();
5960
rl.close();
6061
return nextStep();
6162
}
63+
store.debugMode = true;
6264
try {
6365
const I = container.support('I');
6466
eval(`I.${cmd}`); // eslint-disable-line no-eval
@@ -87,7 +89,6 @@ function completer(line) {
8789
const completions = methodsOfObject(I);
8890
const hits = completions.filter((c) => {
8991
if (c.indexOf(line) === 0) {
90-
// console.log('bang! ' + c);
9192
return c;
9293
}
9394
return null;

lib/plugin/autoDelay.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const Container = require('../container');
2+
const store = require('../store');
23
const recorder = require('../recorder');
34
const event = require('../event');
45
const log = require('../output').log;
@@ -82,6 +83,7 @@ module.exports = function (config) {
8283
if (config.methods.indexOf(step.helperMethod) < 0) return; // skip non-actions
8384

8485
recorder.add('auto-delay', async () => {
86+
if (store.debugMode) return; // no need to delay in debug
8587
log(`Delaying for ${config.delayBefore}ms`);
8688
return new Promise((resolve) => {
8789
setTimeout(resolve, config.delayBefore);
@@ -92,8 +94,8 @@ module.exports = function (config) {
9294
event.dispatcher.on(event.step.after, (step) => {
9395
if (config.methods.indexOf(step.helperMethod) < 0) return; // skip non-actions
9496

95-
9697
recorder.add('auto-delay', async () => {
98+
if (store.debugMode) return; // no need to delay in debug
9799
log(`Delaying for ${config.delayAfter}ms`);
98100
return new Promise((resolve) => {
99101
setTimeout(resolve, config.delayAfter);

lib/plugin/retryFailedStep.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const event = require('../event');
2+
const store = require('../store');
23
const recorder = require('../recorder');
34

45
const defaultConfig = {
@@ -40,6 +41,12 @@ const defaultConfig = {
4041
module.exports = (config) => {
4142
config = Object.assign(defaultConfig, config);
4243

44+
const when = (err) => {
45+
if (store.debugMode) return false;
46+
if (config.when) return config.when(err);
47+
};
48+
config.when = when;
49+
4350
event.dispatcher.on(event.test.before, (test) => {
4451
recorder.retry(config);
4552
});

lib/step.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const store = require('./store');
2+
13
const STACK_LINE = 4;
24

35
// using support objetcs for metastep detection
@@ -141,6 +143,7 @@ Step.MetaStep = MetaStep;
141143
module.exports = Step;
142144

143145
function detectMetaStep(stack) {
146+
if (store.debugMode) return; // no detection in debug
144147
if (!support) loadSupportObjects(); // deprecated
145148

146149
for (let i = STACK_LINE; i < stack.length; i++) {
@@ -164,9 +167,9 @@ function detectMetaStep(stack) {
164167
}
165168

166169
function loadSupportObjects() {
167-
const Config = require('./config');
170+
const config = require('./config');
168171
const path = require('path');
169-
support = Config.get('include', {});
172+
support = config.get('include', {});
170173
if (support) {
171174
for (const name in support) {
172175
const file = support[name];

lib/store.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// global values for current session
2+
const store = {
3+
debugMode: false,
4+
};
5+
6+
module.exports = store;

0 commit comments

Comments
 (0)