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