1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const child_process = require("child_process");
|
4 | const events_1 = require("events");
|
5 | const q = require("q");
|
6 | const configParser_1 = require("./configParser");
|
7 | const runner_1 = require("./runner");
|
8 | const taskLogger_1 = require("./taskLogger");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | class TaskRunner extends events_1.EventEmitter {
|
22 | constructor(configFile, additionalConfig, task, runInFork) {
|
23 | super();
|
24 | this.configFile = configFile;
|
25 | this.additionalConfig = additionalConfig;
|
26 | this.task = task;
|
27 | this.runInFork = runInFork;
|
28 | }
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | run() {
|
37 | let runResults = {
|
38 | taskId: this.task.taskId,
|
39 | specs: this.task.specs,
|
40 | capabilities: this.task.capabilities,
|
41 |
|
42 | failedCount: 0,
|
43 | exitCode: -1,
|
44 | specResults: []
|
45 | };
|
46 | let configParser = new configParser_1.ConfigParser();
|
47 | if (this.configFile) {
|
48 | configParser.addFileConfig(this.configFile);
|
49 | }
|
50 | if (this.additionalConfig) {
|
51 | configParser.addConfig(this.additionalConfig);
|
52 | }
|
53 | let config = configParser.getConfig();
|
54 | config.capabilities = this.task.capabilities;
|
55 | config.specs = this.task.specs;
|
56 | if (this.runInFork) {
|
57 | let deferred = q.defer();
|
58 | let childProcess = child_process.fork(__dirname + '/runnerCli.js', process.argv.slice(2), { cwd: process.cwd(), silent: true });
|
59 | let taskLogger = new taskLogger_1.TaskLogger(this.task, childProcess.pid);
|
60 |
|
61 | childProcess.stdout.on('data', (data) => {
|
62 | taskLogger.log(data);
|
63 | });
|
64 |
|
65 | childProcess.stderr.on('data', (data) => {
|
66 | taskLogger.log(data);
|
67 | });
|
68 | childProcess
|
69 | .on('message', (m) => {
|
70 | if (config.verboseMultiSessions) {
|
71 | taskLogger.peek();
|
72 | }
|
73 | switch (m.event) {
|
74 | case 'testPass':
|
75 | process.stdout.write('.');
|
76 | break;
|
77 | case 'testFail':
|
78 | process.stdout.write('F');
|
79 | break;
|
80 | case 'testsDone':
|
81 | runResults.failedCount = m.results.failedCount;
|
82 | runResults.specResults = m.results.specResults;
|
83 | break;
|
84 | }
|
85 | })
|
86 | .on('error', (err) => {
|
87 | taskLogger.flush();
|
88 | deferred.reject(err);
|
89 | })
|
90 | .on('exit', (code) => {
|
91 | taskLogger.flush();
|
92 | runResults.exitCode = code;
|
93 | deferred.resolve(runResults);
|
94 | });
|
95 | childProcess.send({
|
96 | command: 'run',
|
97 | configFile: this.configFile,
|
98 | additionalConfig: this.additionalConfig,
|
99 | capabilities: this.task.capabilities,
|
100 | specs: this.task.specs
|
101 | });
|
102 | return deferred.promise;
|
103 | }
|
104 | else {
|
105 | let runner = new runner_1.Runner(config);
|
106 | runner.on('testsDone', (results) => {
|
107 | runResults.failedCount = results.failedCount;
|
108 | runResults.specResults = results.specResults;
|
109 | });
|
110 | return runner.run().then((exitCode) => {
|
111 | runResults.exitCode = exitCode;
|
112 | return runResults;
|
113 | });
|
114 | }
|
115 | }
|
116 | }
|
117 | exports.TaskRunner = TaskRunner;
|
118 |
|
\ | No newline at end of file |