Skip to content

Commit 5922761

Browse files
committed
restructure mocha test runner
1 parent 68fa2a7 commit 5922761

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+541
-966
lines changed

lib/constants.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/import-paths.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/index.js

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,27 @@
11
"use strict";
2-
var constants_1 = require('./constants');
3-
var runner_process_1 = require('./runner-process');
4-
var write_test_1 = require('./write-test');
5-
var process_console_log_1 = require('process-console-log');
6-
function runner(_a) {
7-
var testString = _a.testString, config = _a.config, handleResult = _a.handleResult;
8-
write_test_1.default(config, testString);
9-
var runner = runner_process_1.default(config);
10-
var final = null;
11-
var signalMatch = new RegExp(constants_1.signal);
12-
return new Promise(function run(resolve, reject) {
13-
runner.stdout.on('data', function onData(data) {
14-
data = data.toString();
15-
var match = signalMatch.exec(data);
16-
if (!match) {
17-
try {
18-
process_console_log_1.parseLog(data);
19-
}
20-
catch (e) {
21-
process_console_log_1.parseLog(data);
22-
}
23-
return;
24-
}
25-
var resultString = data.substring(match.index + constants_1.signal.length);
26-
var result = JSON.parse(JSON.stringify(resultString));
27-
if (typeof result === 'string') {
28-
result = JSON.parse(result);
29-
}
30-
switch (result.pass) {
31-
case true:
32-
final = result.passes[result.passes.length - 1];
33-
break;
34-
case false:
35-
final = result.failures[0];
36-
break;
37-
default:
38-
console.log('error processing result: ', result);
39-
}
40-
final.change = final.taskPosition - config.taskPosition;
41-
final.pass = final.change > 0;
42-
final.completed = result.pass;
43-
handleResult(final);
44-
});
45-
runner.stderr.on('data', function onError(data) {
46-
console.log('test error', data.toString());
47-
});
48-
runner.on('close', function onClose(code) {
49-
resolve(final);
50-
});
2+
var writeTests_1 = require('./writeTests');
3+
var runner_1 = require('./runner');
4+
var testPath_1 = require('./testPath');
5+
var settings = {
6+
dir: null,
7+
tutorial: null,
8+
tests: '',
9+
step: 0,
10+
testPath: '',
11+
};
12+
exports.combineTests = function (options) {
13+
options.testPath = testPath_1.default(options);
14+
settings = Object.assign(settings, options);
15+
writeTests_1.default(options);
16+
};
17+
function start(_a) {
18+
var taskPosition = _a.taskPosition, handleResult = _a.handleResult;
19+
var dir = settings.dir;
20+
runner_1.default({
21+
dir: dir,
22+
taskPosition: taskPosition,
23+
handleResult: handleResult,
5124
});
5225
}
5326
Object.defineProperty(exports, "__esModule", { value: true });
54-
exports.default = runner;
27+
exports.default = start;

lib/reporter.js renamed to lib/reporter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var constants_1 = require('./constants');
2+
var constants_1 = require('../helpers/constants');
33
exports = module.exports = reporter;
44
function reporter(runner) {
55
var result = {

lib/runner-process.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

lib/runner/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
exports.signal = '@@@CodeRoad Results@@@';

lib/runner/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
var start_runner_1 = require('./start-runner');
3+
var runner_process_1 = require('./runner-process');
4+
function runner(options) {
5+
var runner = runner_process_1.default(options);
6+
return start_runner_1.default(runner, options.handleResult);
7+
}
8+
Object.defineProperty(exports, "__esModule", { value: true });
9+
exports.default = runner;

lib/runner/paths/mocha.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
var node_file_exists_1 = require('node-file-exists');
3+
var path_1 = require('path');
4+
function getMocha() {
5+
var mocha = path_1.join(__dirname, '..', '..', '..', '..', 'mocha', 'bin', 'mocha');
6+
if (!node_file_exists_1.default(mocha)) {
7+
mocha = path_1.join(__dirname, '..', '..', '..', 'node_modules', 'mocha', 'bin', 'mocha');
8+
if (!node_file_exists_1.default(mocha)) {
9+
var error = 'Error finding mocha';
10+
throw (error);
11+
}
12+
}
13+
return mocha;
14+
}
15+
Object.defineProperty(exports, "__esModule", { value: true });
16+
exports.default = getMocha;

lib/runner/paths/node.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
var path_1 = require('path');
3+
function getNode() {
4+
if (process.platform === 'darwin' && process.resourcesPath) {
5+
return path_1.resolve(process.resourcesPath, '..', 'Frameworks', 'Atom Helper.app', 'Contents', 'MacOS', 'Atom Helper');
6+
}
7+
else if (process.platform.match(/win/)) {
8+
return 'node';
9+
}
10+
return process.execPath;
11+
}
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
exports.default = getNode;

lib/runner/runner-process.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
var path_1 = require('path');
3+
var child_process_1 = require('child_process');
4+
var mocha_1 = require('./paths/mocha');
5+
var node_1 = require('./paths/node');
6+
var reporterPath = path_1.join(__dirname, '..', 'reporter', 'reporter.js');
7+
var node = node_1.default();
8+
var mocha = mocha_1.default();
9+
function spawnRunnerProcess(_a) {
10+
var dir = _a.dir, taskPosition = _a.taskPosition, testPath = _a.testPath;
11+
var options = {
12+
cwd: dir
13+
};
14+
if (options.env == null) {
15+
options.env = Object.create(process.env);
16+
}
17+
Object.assign(options.env, {
18+
ATOM_SHELL_INTERNAL_RUN_AS_NODE: 1,
19+
DIR: dir,
20+
TASK_POSITION: taskPosition,
21+
NODE_PATH: path_1.join(dir, 'node_modules'),
22+
});
23+
return child_process_1.spawn(node, [
24+
mocha,
25+
'--bail',
26+
'--harmony',
27+
'--no-colors',
28+
'--timeout=3000',
29+
'--require babelhook',
30+
("--reporter=" + reporterPath),
31+
testPath,
32+
], options);
33+
}
34+
Object.defineProperty(exports, "__esModule", { value: true });
35+
exports.default = spawnRunnerProcess;

0 commit comments

Comments
 (0)