-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.js
executable file
·133 lines (112 loc) · 3.23 KB
/
run.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env node
"use strict";
var path = require("path"),
Jasmine = require("jasmine/lib/jasmine.js"),
fs = require("fs");
// parse commandline params
// no getopt to reduce dependencies
var outputPath = false;
var bootScript;
var options = {
color: true
};
var specs = [];
if (process.env.JASMINE_OUTPUT) {
outputPath = process.env.JASMINE_OUTPUT;
}
// first 2 options are "node" and this script
for (var i = 2; i < process.argv.length; i++) {
var option = process.argv[i],
match;
if (option == "--noColor") {
options.color = false;
continue;
}
match = option.match(/^--output=(.*)$/);
if (match) {
outputPath = match[1];
continue;
}
match = option.match(/^--boot=(.*)$/);
if (match) {
bootScript = match[1];
continue;
}
try {
if (fs.statSync(option).isDirectory()) {
option = option.replace(/\/+$/, "") + "/**/*.js";
}
} catch (e) {
// do nothing
}
specs.push(option);
}
var jasmine = new Jasmine({ projectBaseDir: path.resolve() });
// remove default default console reporter (the one with dots)
jasmine.env.clearReporters();
// add console reporter with colors
var SpecReporter = require("jasmine-spec-reporter").SpecReporter;
var specReporterOptions = {
displayStacktrace: "summary"
};
if (!options.color) {
specReporterOptions.colors = false;
}
jasmine.addReporter(new SpecReporter(specReporterOptions));
// add junit reporter, e.g. for jenkins
if (outputPath) {
var JUnitReporter = require("jasmine-reporters").JUnitXmlReporter,
jUnitReporter = new JUnitReporter({
savePath: outputPath,
consolidateAll: true
});
jasmine.addReporter(jUnitReporter);
}
// load config, or fall back to default
function tryLoad(configPath) {
try {
if (fs.statSync(configPath).isFile()) {
jasmine.loadConfigFile(configPath);
return true;
}
return false;
} catch (e) {
return false;
}
}
function executeJasmine(error) {
if (error) {
return console.error(error);
}
if (process.env.JASMINE_CONFIG_PATH) {
jasmine.loadConfigFile(process.env.JASMINE_CONFIG_PATH);
} else {
// try to autodetect jasmine.json config
if (! (tryLoad("test/jasmine.json") || tryLoad("spec/jasmine.json"))) {
// try to autodetect specs only if no specs were given
if (!specs.length) {
var candidates = ["test", "tests", "spec", "specs", "test/spec"];
do try {
var specPath = candidates.pop();
if (fs.statSync(specPath).isDirectory()) {
jasmine.loadConfig({
"spec_dir": specPath,
"spec_files": [
"**/*.js"
]
});
break;
}
} catch(e) {
// do nothing
} while(candidates.length);
}
}
}
jasmine.execute(specs);
}
if (bootScript) {
require(bootScript)(executeJasmine, jasmine);
} else {
executeJasmine();
}