/
require.js
73 lines (64 loc) · 1.56 KB
/
require.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
'use strict';
var tap = require('tap');
var spawn = require('child_process').spawn;
var concat = require('concat-stream');
var stripFullStack = require('./common').stripFullStack;
function tape(args) {
var bin = __dirname + '/../bin/tape';
return spawn(process.execPath, [bin].concat(args.split(' ')), { cwd: __dirname });
}
tap.test('requiring a single module', function (t) {
t.plan(2);
var tc = function (rows) {
t.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# module-a',
'ok 1 loaded module a',
'# test-a',
'ok 2 module-a loaded in same context',
'ok 3 test ran after module-a was loaded',
'',
'1..3',
'# tests 3',
'# pass 3',
'',
'# ok',
'',
''
]);
};
var ps = tape('-r ./require/a require/test-a.js');
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
});
tap.test('requiring multiple modules', function (t) {
t.plan(2);
var tc = function (rows) {
t.same(rows.toString('utf8'), [
'TAP version 13',
'# module-a',
'ok 1 loaded module a',
'# module-b',
'ok 2 loaded module b',
'# test-a',
'ok 3 module-a loaded in same context',
'ok 4 test ran after module-a was loaded',
'# test-b',
'ok 5 module-b loaded in same context',
'ok 6 test ran after module-b was loaded',
'',
'1..6',
'# tests 6',
'# pass 6',
'',
'# ok'
].join('\n') + '\n\n');
};
var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js');
ps.stdout.pipe(concat(tc));
ps.on('exit', function (code) {
t.equal(code, 0);
});
});