forked from qunitjs/node-qunit
/
testrunner.js
104 lines (90 loc) · 2.5 KB
/
testrunner.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
var a = require('assert'),
chainer = require('chainer'),
_ = require('underscore');
var tr = require('../lib/testrunner'),
log = require('../lib/log');
var fixtures = __dirname + '/fixtures',
chain = chainer();
tr.options.log = {
testing: true
};
// reset log stats every time .next is called
chain.next = function() {
log.reset();
return chainer.prototype.next.apply(this, arguments);
};
chain.add('base testrunner', function() {
tr.run({
code: fixtures + '/testrunner-code.js',
tests: fixtures + '/testrunner-tests.js',
}, function(err, res) {
var stat = {
files: 1,
tests: 2,
assertions: 5,
failed: 2,
passed: 3
};
delete res.runtime;
a.deepEqual(stat, res, 'base testrunner test');
chain.next();
});
});
chain.add('attach code to global', function() {
tr.run({
code: fixtures + '/child-code-global.js',
tests: fixtures + '/child-tests-global.js',
}, function(err, res) {
var stat = {
files: 1,
tests: 1,
assertions: 2,
failed: 0,
passed: 2
};
delete res.runtime;
a.deepEqual(stat, res, 'attaching code to global works');
chain.next();
});
});
chain.add('attach code to a namespace', function() {
tr.run({
code: {
path: fixtures + '/child-code-namespace.js',
namespace: 'testns'
},
tests: fixtures + '/child-tests-namespace.js',
}, function(err, res) {
var stat = {
files: 1,
tests: 1,
assertions: 3,
failed: 0,
passed: 3
};
delete res.runtime;
a.deepEqual(stat, res, 'attaching code to specified namespace works');
chain.next();
});
});
chain.add('async testing logs', function() {
tr.run({
code: fixtures + '/async-code.js',
tests: fixtures + '/async-test.js',
}, function(err, res) {
var stat = {
files: 1,
tests: 2,
assertions: 4,
failed: 0,
passed: 4
};
delete res.runtime;
a.deepEqual(stat, res, 'async code testing works');
chain.next();
});
});
chain.add(function() {
console.log('\nAll tests done');
});
chain.start();