UNPKG

1.9 kBJavaScriptView Raw
1var tap = require('tap');
2var spawn = require('child_process').spawn;
3var concat = require('concat-stream');
4
5tap.test('requiring a single module', function (t) {
6 t.plan(2);
7
8 var tc = function (rows) {
9 t.same(rows.toString('utf8'), [
10 'TAP version 13',
11 '# module-a',
12 'ok 1 loaded module a',
13 '# test-a',
14 'ok 2 module-a loaded in same context',
15 'ok 3 test ran after module-a was loaded',
16 '',
17 '1..3',
18 '# tests 3',
19 '# pass 3',
20 '',
21 '# ok'
22 ].join('\n') + '\n\n');
23 };
24
25 var ps = tape('-r ./require/a require/test-a.js');
26 ps.stdout.pipe(concat(tc));
27 ps.on('exit', function (code) {
28 t.equal(code, 0);
29 });
30});
31
32tap.test('requiring multiple modules', function (t) {
33 t.plan(2);
34
35 var tc = function (rows) {
36 t.same(rows.toString('utf8'), [
37 'TAP version 13',
38 '# module-a',
39 'ok 1 loaded module a',
40 '# module-b',
41 'ok 2 loaded module b',
42 '# test-a',
43 'ok 3 module-a loaded in same context',
44 'ok 4 test ran after module-a was loaded',
45 '# test-b',
46 'ok 5 module-b loaded in same context',
47 'ok 6 test ran after module-b was loaded',
48 '',
49 '1..6',
50 '# tests 6',
51 '# pass 6',
52 '',
53 '# ok'
54 ].join('\n') + '\n\n');
55 };
56
57 var ps = tape('-r ./require/a -r ./require/b require/test-a.js require/test-b.js');
58 ps.stdout.pipe(concat(tc));
59 ps.on('exit', function (code) {
60 t.equal(code, 0);
61 });
62});
63
64function tape(args) {
65 var proc = require('child_process')
66 var bin = __dirname + '/../bin/tape'
67
68 return proc.spawn('node', [bin].concat(args.split(' ')), { cwd: __dirname })
69}