Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80606 views
1
/**
2
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
3
*
4
* This source code is licensed under the BSD-style license found in the
5
* LICENSE file in the root directory of this source tree. An additional grant
6
* of patent rights can be found in the PATENTS file in the same directory.
7
*/
8
'use strict';
9
10
var optimist = require('optimist');
11
//var q = require('q');
12
var TestRunner = require('./TestRunner');
13
var workerUtils = require('node-worker-pool/nodeWorkerUtils');
14
15
if (require.main === module) {
16
try {
17
process.on('uncaughtException', workerUtils.respondWithError);
18
19
var argv = optimist.demand(['config']).argv;
20
var config = JSON.parse(argv.config);
21
22
var testRunner = null;
23
/* jshint -W082:true */
24
function onMessage(message) {
25
if (testRunner === null) {
26
testRunner = new TestRunner(config, {
27
useCachedModuleLoaderResourceMap: true,
28
});
29
30
// Start require()ing config dependencies now.
31
//
32
// Config dependencies are entries in the config that are require()d (in
33
// order to be pluggable) such as 'moduleLoader' or
34
// 'testEnvironment'.
35
testRunner.preloadConfigDependencies();
36
37
// Start deserializing the resource map to get a potential head-start on
38
// that work before the first "run-test" message comes in.
39
//
40
// This is just a perf optimization -- and it is only an optimization
41
// some of the time (when the there is any significant idle time between
42
// this first initialization message and the first "run-rest" message).
43
//
44
// It is also only an optimization so long as deserialization of the
45
// resource map is a bottleneck (which is the case at the time of this
46
// writing).
47
testRunner.preloadResourceMap();
48
}
49
50
return testRunner.runTest(message.testFilePath)
51
.catch(function(err) {
52
throw (err.stack || err.message || err);
53
});
54
}
55
56
workerUtils.startWorker(null, onMessage);
57
} catch (e) {
58
workerUtils.respondWithError(e);
59
}
60
}
61
62