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