Skip to content

Commit 4a9bc7b

Browse files
committed
fixed auto-update issues
1 parent 6b4e462 commit 4a9bc7b

19 files changed

+11754
-9138
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
An interactive, graphical test runner for CodeceptJS.
44

5-
![codepress video](./codepress.gif)
5+
6+
![codepress video](./codeceptui.gif)
67

78
## Quickstart
89

910
Install CodeceptUI in a project where CodeceptJS is already used
1011

1112
```
12-
npm i @codecept-js/ui#master --save
13+
npm i @codecept-js/ui --save
1314
```
1415

1516
Execute it:
1617

1718
```
18-
npx codepress
19+
npx codecept-ui
1920
```
2021

2122
## Development Mode
@@ -29,10 +30,10 @@ codepress uses the debug package to output debug information. This is useful to
2930

3031
```
3132
# verbose: get all debug information
32-
DEBUG=codepress:* npx codepress
33+
DEBUG=codepress:* npx codeceptui
3334
3435
# just get debug output of one module
35-
DEBUG=codepress:codeceptjs-factory npx codepress
36+
DEBUG=codepress:codeceptjs-factory npx codeceptui
3637
```
3738

3839
# Credits

codeceptui.gif

510 KB
Loading

codepress.gif

-608 KB
Binary file not shown.

demo.gif

-797 KB
Binary file not shown.

lib/api/new-test.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ module.exports = async (req, res) => {
1111
const { codecept, container } = codeceptjsFactory.getInstance();
1212

1313
const mocha = container.mocha();
14-
14+
mocha.grep();
15+
mocha.files = [];
16+
mocha.suite.suites = [];
17+
1518
const code = eval(req.body.code);
1619
const test = scenario.test(new Test('new test', code));
1720
test.id = 'new-test';
@@ -35,7 +38,6 @@ module.exports = async (req, res) => {
3538
});
3639

3740
event.dispatcher.once(event.all.result, () => {
38-
mocha.suite.suites = [];
3941
pauseEnabled = false;
4042
debug('testrun finished');
4143
try {
@@ -44,10 +46,21 @@ module.exports = async (req, res) => {
4446
debug('ERROR resetting suites', err);
4547
}
4648
wsEvents.codeceptjs.exit(0);
49+
mocha.suite.suites = [];
4750
});
4851

4952
debug('codecept.run()');
50-
codecept.run();
53+
const done = () => {
54+
event.emit(event.all.result, codecept);
55+
event.emit(event.all.after, codecept);
56+
};
57+
58+
try {
59+
event.emit(event.all.before, codecept);
60+
global.runner = mocha.run(done);
61+
} catch (e) {
62+
throw new Error(e);
63+
}
5164

5265
return res.status(200).send('OK');
5366
};

lib/codeceptjs/console-recorder.helper.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@ class ConsoleRecorderHelper extends Helper {
2222
page.on('pageerror', async err => {
2323
debug('Got page error', err);
2424
wsEvents.console.jsError(err);
25+
26+
this._addToLog({
27+
type: 'error',
28+
message: err.toString()
29+
});
2530
});
2631
page.on('error', async err => {
2732
debug('Got error', err);
2833
wsEvents.console.error(err);
34+
35+
this._addToLog({
36+
type: 'error',
37+
message: err.toString()
38+
});
2939
});
3040

3141
page.on('console', async msg => {
32-
// Restrict to errors for now
33-
if (msg.type() !== 'error') {
34-
return;
35-
}
36-
3742
// Parse all console.log args
3843
for (let i = 0; i < msg.args().length; ++i) {
3944
const arg = msg.args()[i];
@@ -46,14 +51,7 @@ class ConsoleRecorderHelper extends Helper {
4651
}
4752
}
4853

49-
if (!this.helpers.RealtimeReporterHelper) return;
50-
const step = this.helpers.RealtimeReporterHelper.step;
51-
52-
if (!step.logs) step.logs = [];
53-
54-
step.logs.push({
55-
id: uuid,
56-
time: Date.now(),
54+
this._addToLog({
5755
type: msg.type(),
5856
url: msg.location().url,
5957
lineNumber: msg.location().lineNumber,
@@ -65,6 +63,19 @@ class ConsoleRecorderHelper extends Helper {
6563

6664
debug('Recording console logs is enabled');
6765
}
66+
67+
_addToLog(log) {
68+
69+
if (!this.helpers.RealtimeReporterHelper) return;
70+
const step = this.helpers.RealtimeReporterHelper.step;
71+
72+
if (!step.logs) step.logs = [];
73+
74+
step.logs.push({ ...log,
75+
id: uuid,
76+
time: Date.now(),
77+
});
78+
}
6879
}
6980

7081
module.exports = ConsoleRecorderHelper;

lib/codeceptjs/reporter-utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ const takeSnapshot = async (helper, snapshotId, takeScreenshot = false) => {
135135
try {
136136
[_, pageUrl, pageTitle, scrollPosition, viewportSize] = await Promise.all([
137137
takeScreenshot ? saveScreenshot(helper, StepFileName) : Promise.resolve(undefined),
138-
helper.grabCurrentActivity ? await helper.grabCurrentActivity() : await helper.grabCurrentUrl(),
139-
helper.grabTitle(),
138+
helper.grabCurrentActivity ? helper.grabCurrentActivity() : helper.grabCurrentUrl(),
139+
helper.grabTitle ? helper.grabTitle() : '',
140140
helper.grabPageScrollPosition(),
141141
helper.executeScript(getViewportSize),
142142
]);

lib/commands/init.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ module.exports = () => {
2121

2222
if (program.config) {
2323
const configFile = program.config;
24-
let configPath = path.join(process.cwd(), configFile);
24+
let configPath = configFile;
25+
if (!path.isAbsolute(configPath)) {
26+
configPath = path.join(process.cwd(), configFile);
27+
}
2528
if (!fs.lstatSync(configPath).isDirectory()) {
2629
codeceptjsFactory.setConfigFile(path.basename(configPath));
2730
configPath = path.dirname(configPath);

lib/model/scenario-repository.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,25 @@ const groupByAttribute = attrName => (grouped, feature) => {
5858
return grouped;
5959
};
6060

61+
const watchedFiles = () => {
62+
const { config } = codeceptjsFactory.getInstance();
63+
const watchFiles = [];
64+
65+
watchFiles.push(codeceptjsFactory.getConfigFile());
66+
watchFiles.push(config.get('tests'));
67+
if (config.get('gherkin')) watchFiles.push(config.get().gherkin.features);
68+
if (config.get('include')) watchFiles.push(...Object.values(config.get('include')));
69+
debug('watching files', watchFiles);
70+
return watchFiles.filter(f => !!f);
71+
};
72+
6173
// Cache mocha suites
6274
let suites = [];
6375

6476
// NOTE could not get it to work with absolute paths
6577
// TODO Setting the default ignore pattern in my cases effectively disabled events
6678
// my test files are ending with *.test.js
67-
chokidar.watch(['./**/*.js', './**/*.feature'], {
79+
chokidar.watch(watchedFiles(), {
6880
ignored: ['**/node_modules/**/*', '**/.git/**/*'],
6981
ignoreInitial: false, // need to load suites initially
7082
ignorePermissionErrors: true,

lib/model/scenario-status-repository.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const fs = require('fs');
44
const path = require('path');
55
const mkdir = require('../utils/mkdir');
66

7-
mkdir(path.join('.', '.codepress'));
8-
const ScenarioStatusFile = path.join('.', '.codepress', 'scenario-status.json');
7+
mkdir(path.join(global.output_dir, '.ui'));
8+
const ScenarioStatusFile = path.join(global.output_dir, '.ui', 'scenario-status.json');
99

1010
const ScenarioStatus = ['passed', 'failed'];
1111

@@ -48,4 +48,4 @@ process.on('SIGINT', () => {
4848
console.log('Saving status...');
4949
saveStatus();
5050
process.exit();
51-
});
51+
});

lib/model/testrun-repository.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const fs = require('fs');
33
const path = require('path');
44
const mkdir = require('../utils/mkdir');
55

6-
mkdir(path.join('.', '.codepress'));
7-
const TestRunBaseDir = path.join('.', '.codepress', 'testruns');
6+
mkdir(path.join(global.output_dir, '.ui'));
7+
const TestRunBaseDir = path.join(global.output_dir, '.ui', 'testruns');
88
mkdir(TestRunBaseDir);
99

1010
const fileNameFromId = id => `${encodeURIComponent(id)}.json`;

0 commit comments

Comments
 (0)