Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit de49a70

Browse files
committed
Revert "feat(typescript): converting task files to typescript"
This reverts commit ece9c02.
1 parent ece9c02 commit de49a70

10 files changed

+374
-385
lines changed

lib/configParser.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ try {
1919
export interface Config {
2020
specs: Array<string>;
2121
multiCapabilities: Array<any>;
22-
capabilities?: any;
2322
rootElement: string;
2423
allScriptsTimeout: number;
2524
getPageTimeout: number;
@@ -36,8 +35,6 @@ export interface Config {
3635
suite?: string;
3736
suites?: any;
3837
troubleshoot?: boolean;
39-
exclude?: Array<string>| string;
40-
maxSessions?: number;
4138
}
4239

4340
export default class ConfigParser {

lib/launcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
'use strict';
66

77
var ConfigParser = require('./configParser').default,
8-
TaskScheduler = require('./taskScheduler').default,
8+
TaskScheduler = require('./taskScheduler'),
99
helper = require('./util'),
1010
log = require('./logger'),
1111
q = require('q'),
12-
TaskRunner = require('./taskRunner').default;
12+
TaskRunner = require('./taskRunner');
1313

1414
var logPrefix = '[launcher]';
1515
var RUNNERS_FAILED_EXIT_CODE = 100;

lib/taskLogger.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
var EOL = require('os').EOL;
2+
var log = require('./logger');
3+
4+
/**
5+
* Log output such that metadata are appended.
6+
* Calling log(data) will not flush to console until you call flush()
7+
*
8+
* @constructor
9+
* @param {object} task Task that is being reported.
10+
* @param {number} pid PID of process running the task.
11+
*/
12+
var TaskLogger = function(task, pid) {
13+
this.task = task;
14+
this.pid = pid;
15+
this.buffer = '';
16+
this.insertTag = true;
17+
18+
this.logHeader_();
19+
};
20+
21+
/**
22+
* Log the header for the current task including information such as
23+
* PID, browser name/version, task Id, specs being run.
24+
*
25+
* @private
26+
*/
27+
TaskLogger.prototype.logHeader_ = function() {
28+
var output = 'PID: ' + this.pid + EOL;
29+
if (this.task.specs.length === 1) {
30+
output += 'Specs: ' + this.task.specs.toString() + EOL + EOL;
31+
}
32+
this.log(output);
33+
};
34+
35+
36+
/**
37+
* Flushes the buffer to stdout.
38+
*/
39+
TaskLogger.prototype.flush = function() {
40+
if (this.buffer) {
41+
// Flush buffer if nonempty
42+
log.print(EOL + '------------------------------------' + EOL);
43+
log.print(this.buffer);
44+
log.print(EOL);
45+
this.buffer = '';
46+
}
47+
};
48+
49+
/**
50+
* Log the data in the argument such that metadata are appended.
51+
* The data will be saved to a buffer until flush() is called.
52+
*
53+
* @param {string} data
54+
*/
55+
TaskLogger.prototype.log = function(data) {
56+
var tag = '[';
57+
var capabilities = this.task.capabilities;
58+
tag += (capabilities.logName) ? capabilities.logName
59+
: (capabilities.browserName) ? capabilities.browserName : '';
60+
tag += (capabilities.version) ? (' ' + capabilities.version) : '';
61+
tag += (capabilities.platform) ? (' ' + capabilities.platform) : '';
62+
tag += (capabilities.logName && capabilities.count < 2) ?
63+
'' : ' #' + this.task.taskId;
64+
tag += '] ';
65+
66+
data = data.toString();
67+
for (var i = 0; i < data.length; i++) {
68+
if (this.insertTag) {
69+
this.insertTag = false;
70+
// This ensures that the '\x1B[0m' appears before the tag, so that
71+
// data remains correct when color is not processed.
72+
// See https://github.com/angular/protractor/pull/1216
73+
if (data[i] === '\x1B' && data.substring(i, i + 4) === '\x1B[0m') {
74+
this.buffer += ('\x1B[0m' + tag);
75+
i += 3;
76+
continue;
77+
}
78+
79+
this.buffer += tag;
80+
}
81+
if (data[i] === '\n') {
82+
this.insertTag = true;
83+
}
84+
this.buffer += data[i];
85+
}
86+
};
87+
88+
module.exports = TaskLogger;

lib/taskLogger.ts

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

lib/taskRunner.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
var child = require('child_process');
2+
var q = require('q');
3+
var TaskLogger = require('./taskLogger');
4+
var EventEmitter = require('events').EventEmitter;
5+
var util = require('util');
6+
var log = require('./logger');
7+
var ConfigParser = require('./configParser').default;
8+
9+
/**
10+
* A runner for running a specified task (capabilities + specs).
11+
* The TaskRunner can either run the task from the current process (via
12+
* './runner.js') or from a new process (via './runnerCli.js').
13+
*
14+
* @constructor
15+
* @param {string} configFile Path of test configuration.
16+
* @param {object} additionalConfig Additional configuration.
17+
* @param {object} task Task to run.
18+
* @param {boolean} runInFork Whether to run test in a forked process.
19+
* @constructor
20+
*/
21+
var TaskRunner = function(configFile, additionalConfig, task, runInFork) {
22+
this.configFile = configFile;
23+
this.additionalConfig = additionalConfig;
24+
this.task = task;
25+
this.runInFork = runInFork;
26+
};
27+
util.inherits(TaskRunner, EventEmitter);
28+
29+
/**
30+
* Sends the run command.
31+
* @return {q.Promise} A promise that will resolve when the task finishes
32+
* running. The promise contains the following parameters representing the
33+
* result of the run:
34+
* taskId, specs, capabilities, failedCount, exitCode, specResults
35+
*/
36+
TaskRunner.prototype.run = function() {
37+
var runResults = {
38+
taskId: this.task.taskId,
39+
specs: this.task.specs,
40+
capabilities: this.task.capabilities,
41+
// The following are populated while running the test:
42+
failedCount: 0,
43+
exitCode: -1,
44+
specResults: []
45+
};
46+
47+
if (this.runInFork) {
48+
var deferred = q.defer();
49+
50+
var childProcess = child.fork(
51+
__dirname + '/runnerCli.js',
52+
process.argv.slice(2), {
53+
cwd: process.cwd(),
54+
silent: true
55+
}
56+
);
57+
var taskLogger = new TaskLogger(this.task, childProcess.pid);
58+
59+
// stdout pipe
60+
childProcess.stdout.on('data', function(data) {
61+
taskLogger.log(data);
62+
});
63+
64+
// stderr pipe
65+
childProcess.stderr.on('data', function(data) {
66+
taskLogger.log(data);
67+
});
68+
69+
childProcess.on('message', function(m) {
70+
switch (m.event) {
71+
case 'testPass':
72+
log.print('.');
73+
break;
74+
case 'testFail':
75+
log.print('F');
76+
break;
77+
case 'testsDone':
78+
runResults.failedCount = m.results.failedCount;
79+
runResults.specResults = m.results.specResults;
80+
break;
81+
}
82+
})
83+
.on('error', function(err) {
84+
taskLogger.flush();
85+
deferred.reject(err);
86+
})
87+
.on('exit', function(code) {
88+
taskLogger.flush();
89+
runResults.exitCode = code;
90+
deferred.resolve(runResults);
91+
});
92+
93+
childProcess.send({
94+
command: 'run',
95+
configFile: this.configFile,
96+
additionalConfig: this.additionalConfig,
97+
capabilities: this.task.capabilities,
98+
specs: this.task.specs
99+
});
100+
101+
return deferred.promise;
102+
} else {
103+
var configParser = new ConfigParser();
104+
if (this.configFile) {
105+
configParser.addFileConfig(this.configFile);
106+
}
107+
if (this.additionalConfig) {
108+
configParser.addConfig(this.additionalConfig);
109+
}
110+
var config = configParser.getConfig();
111+
config.capabilities = this.task.capabilities;
112+
config.specs = this.task.specs;
113+
114+
var Runner = require('./runner');
115+
var runner = new Runner(config);
116+
117+
runner.on('testsDone', function(results) {
118+
runResults.failedCount = results.failedCount;
119+
runResults.specResults = results.specResults;
120+
});
121+
122+
return runner.run().then(function(exitCode) {
123+
runResults.exitCode = exitCode;
124+
return runResults;
125+
});
126+
}
127+
};
128+
129+
module.exports = TaskRunner;

0 commit comments

Comments
 (0)