UNPKG

2.82 kBJavaScriptView Raw
1/*
2 * Licensed to Cloudkick, Inc ('Cloudkick') under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * Cloudkick licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18var path = require('path');
19
20var sprintf = require('sprintf').sprintf;
21
22var common = require('./common');
23var testUtil = require('./util');
24var coverage = require('./coverage');
25var constants = require('./constants');
26
27var ARGUMENTS = {
28 'test_path': {
29 'pos': 2
30 },
31 'socket_path': {
32 'pos': 3
33 },
34 'cwd': {
35 'pos': 4
36 },
37 'lib_cov_dir': {
38 'pos': 5
39 },
40 'scope_leaks': {
41 'pos': 6
42 },
43 'chdir': {
44 'pos': 7
45 },
46 'custom_assert_module': {
47 'pos': 8
48 },
49 'init_file': {
50 'pos': 9
51 },
52 'timeout': {
53 'pos': 10,
54 'type': 'number'
55 },
56 'concurrency': {
57 'pos': 11,
58 'type': 'pos'
59 },
60 'pattern': {
61 'pos': 12
62 },
63};
64
65if (process.argv.length < 6) {
66 console.log('No enough argumentes provided');
67 process.exit(1);
68}
69
70var args = testUtil.parseArguments(ARGUMENTS, process.argv);
71
72var testPath = args['test_path'];
73var socketPath = args['socket_path'];
74var cwd = args['cwd'];
75var libCovDir = args['lib_cov_dir'];
76var scopeLeaks = args['scope_leaks'];
77var chdir = args['chdir'];
78var customAssertModule = args['custom_assert_module'];
79var testInitFile = args['init_file'];
80var timeout = args['timeout'];
81var concurrency = args['concurrency'];
82var pattern = args['pattern'];
83
84if (customAssertModule) {
85 var exportedFunctions = require(customAssertModule.replace(/$\.js/, ''));
86 common.registerCustomAssertionFunctions(exportedFunctions);
87}
88
89if (chdir && path.existsSync(chdir)) {
90 process.chdir(chdir);
91}
92
93var options = { 'cwd': cwd, 'socket_path': socketPath,
94 'init_file': testInitFile, 'timeout': timeout,
95 'concurrency': concurrency, 'scope_leaks': scopeLeaks,
96 'pattern': pattern};
97var testFile = new common.TestFile(testPath, options);
98testFile.runTests(function onTestFileEnd() {
99 if (libCovDir && typeof _$jscoverage === 'object') {
100 testFile._reportTestCoverage(_$jscoverage);
101 }
102
103 testFile._reportTestFileEnd();
104});
105
106process.on('uncaughtException', function(err) {
107 testFile.addUncaughtException(err);
108});