Skip to content
This repository was archived by the owner on Feb 12, 2019. It is now read-only.

Commit e3422ee

Browse files
Merge pull request #3 from AlexanderMoskovkin/rework-merge-1
Small logging fixes
2 parents 2a66489 + 63f07b3 commit e3422ee

9 files changed

Lines changed: 78 additions & 71 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fixture `Check logged user`
152152
});
153153

154154
test('My test with logged user', async t => {
155-
// perform any action here as a logger user
155+
// perform any action here as a logged user
156156
});
157157
```
158158

lib/controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class Controller extends EventEmitter {
2828
this.testRunner.on(this.testRunner.TEST_RUN_STARTED, () => logger.testsStarted());
2929

3030
this.testRunner.on(this.testRunner.TEST_RUN_DONE_EVENT, e => {
31-
logger.testsFinished();
31+
if (!this.restarting)
32+
logger.testsFinished();
3233

3334
this.running = false;
3435

lib/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ process.stdin.on('keypress', function (ch, key) {
3232

3333
else if (key.name === 'w')
3434
controller.toggleWatching();
35-
3635
}
3736
});
3837

lib/log-update-async-hook/cli-cursor.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,37 @@ var restoreCursor = require('./restore-cursor');
44
var hidden = false;
55

66
exports.show = function (stream) {
7-
var s = stream || process.stderr;
7+
var s = stream || process.stderr;
88

9-
if (!s.isTTY) {
10-
return;
11-
}
9+
if (!s.isTTY) {
10+
return;
11+
}
1212

13-
hidden = false;
14-
s.write('\u001b[?25h');
13+
hidden = false;
14+
s.write('\u001b[?25h');
1515
};
1616

1717
exports.hide = function (stream) {
18-
var s = stream || process.stderr;
18+
var s = stream || process.stderr;
1919

20-
if (!s.isTTY) {
21-
return;
22-
}
20+
if (!s.isTTY) {
21+
return;
22+
}
2323

24-
restoreCursor();
25-
hidden = true;
26-
s.write('\u001b[?25l');
24+
restoreCursor();
25+
hidden = true;
26+
s.write('\u001b[?25l');
2727
};
2828

2929
exports.toggle = function (force, stream) {
30-
if (force !== undefined) {
31-
hidden = force;
32-
}
33-
34-
if (hidden) {
35-
exports.show(stream);
36-
} else {
37-
exports.hide(stream);
38-
}
30+
if (force !== undefined) {
31+
hidden = force;
32+
}
33+
34+
if (hidden) {
35+
exports.show(stream);
36+
}
37+
else {
38+
exports.hide(stream);
39+
}
3940
};

lib/log-update-async-hook/index.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
'use strict';
22
var ansiEscapes = require('ansi-escapes');
3-
var wrapAnsi = require('wrap-ansi');
4-
var cliCursor = require('./cli-cursor');
3+
var wrapAnsi = require('wrap-ansi');
4+
var cliCursor = require('./cli-cursor');
55

66

77
function main (stream) {
8-
var prevLineCount = 0;
9-
10-
var render = function () {
11-
cliCursor.hide();
12-
var out = [].join.call(arguments, ' ') + '\n';
13-
out = wrapAnsi(out, process.stdout.columns || 80, {wordWrap: false});
14-
stream.write(ansiEscapes.eraseLines(prevLineCount) + out);
15-
prevLineCount = out.split('\n').length;
16-
};
17-
18-
render.clear = function () {
19-
stream.write(ansiEscapes.eraseLines(prevLineCount));
20-
prevLineCount = 0;
21-
};
22-
23-
render.done = function () {
24-
prevLineCount = 0;
25-
cliCursor.show();
26-
};
27-
28-
return render;
8+
var prevLineCount = 0;
9+
10+
var render = function () {
11+
cliCursor.hide();
12+
13+
var out = [].join.call(arguments, ' ') + '\n';
14+
15+
out = wrapAnsi(out, process.stdout.columns || 80, { wordWrap: false });
16+
stream.write(ansiEscapes.eraseLines(prevLineCount) + out);
17+
prevLineCount = out.split('\n').length;
18+
};
19+
20+
render.clear = function () {
21+
stream.write(ansiEscapes.eraseLines(prevLineCount));
22+
prevLineCount = 0;
23+
};
24+
25+
render.done = function () {
26+
prevLineCount = 0;
27+
cliCursor.show();
28+
};
29+
30+
return render;
2931
}
3032

31-
module.exports = main(process.stdout);
33+
module.exports = main(process.stdout);
3234
module.exports.stderr = main(process.stderr);
3335
module.exports.create = main;

lib/log-update-async-hook/restore-cursor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var onetime = require('onetime');
33
var exitHook = require('async-exit-hook');
44

55
module.exports = onetime(function () {
6-
exitHook(function () {
7-
process.stderr.write('\u001b[?25h');
8-
});
6+
exitHook(function () {
7+
process.stderr.write('\u001b[?25h');
8+
});
99
});

lib/logger/base.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = class BaseLogger {
55
this.testingStarted = false;
66
this.aborted = false;
77
this.running = false;
8+
this.watching = true;
89

910
process.stdout.write = (...args) => this._onStdoutWrite(...args);
1011

@@ -21,15 +22,16 @@ You can use the following keys in the terminal:
2122
2223
`,
2324

24-
sourceChanged: 'Sources have been changed. Test run is starting...',
25-
testRunStarting: 'Test run is starting...',
26-
testRunStarted: 'Test run in progress...',
27-
testRunStopping: 'Current test run is stopping...',
28-
testRunFinished: 'Make changes in the source files or press ctrl+r to restart test run.',
29-
fileWatchingEnabled: 'File watching enabled. Save changes in your files to run tests.',
30-
fileWatchingDisabled: 'File watching disabled.',
31-
nothingToStop: 'There are no tests running at the moment.',
32-
testCafeStopping: 'Stopping TestCafe Live...'
25+
sourceChanged: 'Sources have been changed. Test run is starting...',
26+
testRunStarting: 'Test run is starting...',
27+
testRunStarted: 'Test run in progress...',
28+
testRunStopping: 'Current test run is stopping...',
29+
testRunFinishedWatching: 'Make changes in the source files or press ctrl+r to restart test run.',
30+
testRunFinishedNotWatching: 'Press ctrl+r to restart test run.',
31+
fileWatchingEnabled: 'File watching enabled. Save changes in your files to run tests.',
32+
fileWatchingDisabled: 'File watching disabled.',
33+
nothingToStop: 'There are no tests running at the moment.',
34+
testCafeStopping: 'Stopping TestCafe Live...'
3335
};
3436
}
3537

@@ -72,7 +74,7 @@ You can use the following keys in the terminal:
7274
testsFinished () {
7375
this.running = false;
7476

75-
this._status(this.MESSAGES.testRunFinished);
77+
this._status(this.watching ? this.MESSAGES.testRunFinishedWatching : this.MESSAGES.testRunFinishedNotWatching);
7678
}
7779

7880
stopRunning () {
@@ -84,6 +86,8 @@ You can use the following keys in the terminal:
8486
}
8587

8688
toggleWatching (enable) {
89+
this.watching = enable;
90+
8791
if (enable)
8892
this._status(this.MESSAGES.fileWatchingEnabled);
8993
else

lib/test-run-controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const testRunCtorFactory = function (callbacks, command) {
1515
super(test, browserConnection, screenshotCapturer, warningLog, opts);
1616

1717
this[liveTestRunStorage] = { test, stopping: false, stop: false, isInRoleInitializing: false };
18+
1819
created(this, test);
20+
1921
this.injectable.scripts.push('/testcafe-live.js');
2022

2123
registerStopHandler(this, () => {

lib/test-runner.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

3-
const fs = require('fs');
4-
const path = require('path');
5-
const EventEmitter = require('events');
6-
const Module = require('module');
7-
const createTestCafe = require('testcafe');
8-
const remotesWizard = require('testcafe/lib/cli/remotes-wizard');
9-
const TestRunController = require('./test-run-controller');
3+
const fs = require('fs');
4+
const path = require('path');
5+
const EventEmitter = require('events');
6+
const Module = require('module');
7+
const createTestCafe = require('testcafe');
8+
const remotesWizard = require('testcafe/lib/cli/remotes-wizard');
9+
const TestRunController = require('./test-run-controller');
1010

1111
const CLIENT_JS = fs.readFileSync(path.join(__dirname, './client/index.js'));
1212

@@ -213,8 +213,6 @@ module.exports = class TestRunner extends EventEmitter {
213213
run () {
214214
let runError = null;
215215

216-
//this._resolveAllTestRunPromises();
217-
218216
let testRunPromise = null;
219217

220218
if (!this.tcRunner) {

0 commit comments

Comments
 (0)