-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
51 lines (41 loc) · 1.18 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
'use strict';
var configFactory = require('./lib/config')
, TestNode = require('./lib/testNode')
, path = require('path')
, fs = require('fs')
, existsSync = fs.existsSync || path.existsSync;
var Runner = require('./lib/runner');
function findConfigPath() {
var dir = path.dirname(module.parent.filename);
do {
var configPath = path.join(dir, 'trap.config.js');
if (existsSync(configPath))
return configPath;
var parent = path.dirname(dir);
} while (parent !== dir && (dir = parent));
return null;
}
function getRunner() {
if (!Runner.current) {
var config = configFactory.load(findConfigPath());
var runner = Runner.current = new Runner(config);
config.attachReporters(runner);
process.nextTick(function () {
runner.run();
});
}
return Runner.current;
}
module.exports = {
test: function (description, fn) {
getRunner().enqueue(new TestNode(description, fn));
},
defaultConfig: require('./lib/defaultConfig'),
core: {
Runner: Runner,
FileRunner: require('./lib/fileRunner'),
TestNode: TestNode,
defaultReporter: require('./lib/defaultReporter'),
defaultConig: require('./lib/defaultConfig')
}
};