-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
105 lines (82 loc) · 2.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
var fork = require('child_process').fork;
var which = require('shelljs').which;
var fs = require('fs');
var os = require('os');
var path = require('path');
var URL = require('url');
var util = require('util');
var TEST_RUNNER_DIR = path.join(__dirname, 'runner');
function getTnsCliExecutablePath() {
var pathToTnsExecutable = which('tns');
return path.join(path.dirname(pathToTnsExecutable), "nativescript.js");
}
function NativeScriptLauncher(baseBrowserDecorator, logger, config, args, emitter, executor) {
var self = this;
baseBrowserDecorator(self);
self.log = logger.create('launcher');
if (!args.platform) {
self.log.error('No platform specified.');
process.exit(1);
}
self.platform = args.platform;
var launcherConfig = config._NS || {};
emitter.on('browser_register', function(browser) {
if (!browser.id || browser.id.indexOf('NativeScript') !== 0) {
return;
}
self.markCaptured();
// In case --watch is passed to CLI, each change in file should restart the tests.
// When a new browser is registered, in case `singleRun` is false (that's when --watch is not passed)
// tests should be scheduled.
// When `singleRun` is true, karma automatically runs the tests when browser is registered,
// so do not schedule them in this case.
if(launcherConfig.options.watch) {
executor.schedule();
}
});
function logDebugOutput(data) {
process.stdout.write(data);
}
// Consider removing this in case we drop support for `tns dev-test` command
self.liveSyncAndRun = function() {
var tnsArgs = ['dev-test', self.platform, '--port', self.parsedUrl.port];
if (args.arguments) {
tnsArgs = tnsArgs.concat(args.arguments);
}
if (launcherConfig.log) {
tnsArgs = tnsArgs.concat(['--log', launcherConfig.log]);
}
if (typeof launcherConfig.path !== 'undefined') {
tnsArgs = tnsArgs.concat(['--path', launcherConfig.path]);
}
var tnsCli = launcherConfig.tns || getTnsCliExecutablePath();
self.log.debug('Starting "' + tnsCli + '" ' + tnsArgs.join(' '));
var runner = fork(tnsCli, tnsArgs);
runner.on('message', function(data) {
if (data === "ready") {
// Child process is ready to read the data
var optionsStr = JSON.stringify(launcherConfig.options);
runner.send(optionsStr);
}
});
runner.on('error', logDebugOutput);
runner.on('data', logDebugOutput);
runner.on('exit', function(code) {
self.log.info('NativeScript deployment completed with code ' + code);
if (code) {
process.exit(code);
}
});
}
self.start = function(url) {
self.parsedUrl = URL.parse(url);
process.send({ url: self.parsedUrl, launcherConfig: JSON.stringify(launcherConfig.options) });
}
}
NativeScriptLauncher.prototype = {
name: 'NativeScript Unit Test Runner'
}
module.exports = {
'launcher:NS': ['type', NativeScriptLauncher]
};