Skip to content

Commit ab19c12

Browse files
committed
improved log handling
1 parent ad72c20 commit ab19c12

File tree

7 files changed

+19
-37
lines changed

7 files changed

+19
-37
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mocha-coderoad",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "mocha test runner & reporter for atom-coderoad",
55
"main": "src/runner.js",
66
"scripts": {

src/runner.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ function runner(testFile, config, handleResult, handleLog) {
88
var signalMatch = new RegExp(utils_1.signal);
99
return new Promise(function (resolve, reject) {
1010
runner.stdout.on('data', function (data) {
11+
data = data.toString();
1112
var match = signalMatch.exec(data);
1213
if (!match) {
13-
throw 'Result test data doesn\'t match signal string', data.toString();
14+
handleLog(data);
15+
return;
1416
}
15-
if (match.index > 0) {
16-
var log = data.toString().substring(0, match.index);
17-
if (!!log.length) {
18-
handleLog(log);
19-
}
20-
}
21-
var resultString = data.toString().substring(match.index + utils_1.signal.length);
17+
var resultString = data.substring(match.index + utils_1.signal.length);
2218
var result = JSON.parse(JSON.stringify(resultString));
2319
if (typeof result === 'string') {
2420
result = JSON.parse(result);

test/result-fail.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ describe('result-failure', function() {
1717
var file = path.join(__dirname, 'tests', 'fail-01.js');
1818
var run = getRunner(file);
1919
var expected = {
20+
change: 0,
21+
pass: false,
2022
taskPosition: 0,
2123
msg: 'fail-01 should fail',
2224
timedOut: false
@@ -32,6 +34,7 @@ xit('returns taskPosition 1 if second test fails', function() {
3234
var run = getRunner(files);
3335
var expected = {
3436
pass: false,
37+
change: 1,
3538
taskPosition: 1,
3639
failedAtFile: path.join(config.tutorialDir, 'fail-01.js'),
3740
msg: 'fail-01 should fail'
@@ -47,6 +50,7 @@ xit('returns taskPosition 3 if fourth test fails', function() {
4750
var run = getRunner(files);
4851
var expected = {
4952
pass: false,
53+
change: 3,
5054
taskPosition: 3,
5155
failedAtFile: path.join(config.tutorialDir, 'fail-01.js'),
5256
msg: 'fail-01 should fail'
@@ -62,6 +66,7 @@ xit('returns taskPosition 0 if any of the first tests fail', function () {
6266
var run = getRunner(files);
6367
var expected = {
6468
pass: false,
69+
change: 0,
6570
taskPosition: 0,
6671
failedAtFile: path.join(config.tutorialDir, 'fail-01.js'),
6772
msg: 'fail-01 should fail'
@@ -77,6 +82,7 @@ xit('returns the taskPosition at the correct point with arrays of tests', functi
7782
var run = getRunner(files);
7883
var expected = {
7984
pass: false,
85+
change: 2,
8086
taskPosition: 2,
8187
failedAtFile: path.join(config.tutorialDir, 'fail-01.js'),
8288
msg: 'fail-01 should fail'

test/result-pass.spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ describe('result-pass', function() {
1414
var file = path.join(__dirname, 'tests', 'pass-01.js');
1515
var run = getRunner(file);
1616
var expected = {
17+
change: 1,
18+
pass: true,
1719
taskPosition: 1,
1820
msg: 'Task 1 Complete'
1921
};
@@ -29,6 +31,8 @@ describe('result-pass', function() {
2931
var file = concatTests(path.join(__dirname, 'temp', 'pass02.js'), tests);
3032
var run = getRunner(file);
3133
var expected = {
34+
change: 3,
35+
pass: true,
3236
taskPosition: 3,
3337
msg: 'Task 3 Complete'
3438
};

test/runner.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('runner', function() {
1919
var file = path.join(__dirname, 'tests', 'env-vars.js');
2020
var run = getRunner(file);
2121
var expected = {
22+
change: 1,
23+
pass: true,
2224
taskPosition: 1,
2325
msg: 'Task 1 Complete'
2426
};

test/temp/pass02.js

-27
This file was deleted.

test/utils/runner.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var runner = require('../../src/runner').default;
44
var rootDir = __dirname.split('/');
55
var config = {
66
dir: rootDir.slice(0, rootDir.length - 1).join('/'),
7-
tutorialDir: path.join(__dirname, '..', '/tests')
7+
tutorialDir: path.join(__dirname, '..', '/tests'),
8+
taskPosition: 0
89
};
910
function handleLog(log) {
1011
return log;

0 commit comments

Comments
 (0)