1 | 'use strict';
|
2 |
|
3 | var test = require('tape');
|
4 | var path = require('path');
|
5 | var http = require('http');
|
6 | var spawn = require('child_process').spawn;
|
7 | var parser = require('tap-parser');
|
8 |
|
9 | var runNode = require('../lib/run-node');
|
10 | var runElectron = require('../lib/run-electron');
|
11 |
|
12 | var cliPath = path.join(process.cwd(), 'bin/cli.js');
|
13 |
|
14 | var passingEntry = path.join(__dirname, 'fixtures/passing.js');
|
15 | var failingEntry = path.join(__dirname, 'fixtures/failing.js');
|
16 | var mockEntry = path.join(__dirname, 'fixtures/mock-entry.js');
|
17 | var errorEntry = path.join(__dirname, 'fixtures/error-entry.js');
|
18 | var exit123Entry = path.join(__dirname, 'fixtures/exit-123.js');
|
19 |
|
20 | test('basic node coverage reporting', function (t) {
|
21 | t.plan(1);
|
22 | runNode(mockEntry, function onCoverage(coverage) {
|
23 | t.deepEqual(coverage, {});
|
24 | });
|
25 | });
|
26 |
|
27 | test('basic electron coverage reporting', function (t) {
|
28 | t.plan(1);
|
29 | runElectron(mockEntry, function onCoverage(coverage) {
|
30 | t.deepEqual(coverage, {});
|
31 | });
|
32 | });
|
33 |
|
34 | test('both passing status code', function (t) {
|
35 | t.plan(1);
|
36 | var child = spawn('node', [cliPath,
|
37 | '--node', passingEntry,
|
38 | '--browser', passingEntry
|
39 | ]);
|
40 | child.on('close', function (code) {
|
41 | t.equal(code, 0);
|
42 | });
|
43 | });
|
44 |
|
45 | test('node failing only status code', function (t) {
|
46 | t.plan(1);
|
47 | var child = spawn('node', [cliPath,
|
48 | '--node', failingEntry,
|
49 | '--browser', passingEntry
|
50 | ]);
|
51 | child.on('close', function (code) {
|
52 | t.ok(code);
|
53 | });
|
54 | });
|
55 |
|
56 | test('node failing only status code without browser', function (t) {
|
57 | t.plan(1);
|
58 | var child = spawn('node', [cliPath,
|
59 | '--node', exit123Entry,
|
60 | ]);
|
61 | child.on('close', function (code) {
|
62 | t.equal(code, 123);
|
63 | });
|
64 | });
|
65 |
|
66 | test('browser failing only status code', function (t) {
|
67 | t.plan(1);
|
68 | var child = spawn('node', [cliPath,
|
69 | '--node', passingEntry,
|
70 | '--browser', failingEntry
|
71 | ]);
|
72 | child.on('close', function (code) {
|
73 | t.ok(code);
|
74 | });
|
75 | });
|
76 |
|
77 | test('both failing status code', function (t) {
|
78 | t.plan(1);
|
79 | var child = spawn('node', [cliPath,
|
80 | '--node', failingEntry,
|
81 | '--browser', failingEntry
|
82 | ]);
|
83 | child.on('close', function (code) {
|
84 | t.ok(code);
|
85 | });
|
86 | });
|
87 |
|
88 | test('browser error status code', function (t) {
|
89 | t.plan(1);
|
90 | var child = spawn('node', [cliPath,
|
91 | '--node', passingEntry,
|
92 | '--browser', errorEntry
|
93 | ]);
|
94 | child.on('close', function (code) {
|
95 | t.ok(code);
|
96 | });
|
97 | });
|
98 |
|
99 | test('node error status code', function (t) {
|
100 | t.plan(1);
|
101 | var child = spawn('node', [cliPath,
|
102 | '--node', errorEntry,
|
103 | '--browser', passingEntry
|
104 | ]);
|
105 | child.on('close', function (code) {
|
106 | t.ok(code);
|
107 | });
|
108 | });
|
109 |
|
110 | test('both error status code', function (t) {
|
111 | t.plan(1);
|
112 | var child = spawn('node', [cliPath,
|
113 | '--node', errorEntry,
|
114 | '--browser', errorEntry
|
115 | ]);
|
116 | child.on('close', function (code) {
|
117 | t.ok(code);
|
118 | });
|
119 | });
|
120 |
|
121 | test('tap merging', function (t) {
|
122 | t.plan(1);
|
123 | var child = spawn('node', [cliPath,
|
124 | '--node', passingEntry,
|
125 | '--browser', passingEntry
|
126 | ]);
|
127 | child.stdout.pipe(parser(function (results) {
|
128 | t.equal(results.asserts.length, 2);
|
129 | }));
|
130 | });
|
131 |
|
132 | test('redirect protocol relative url to http', function (t) {
|
133 | t.plan(1);
|
134 | var child = spawn('node', [cliPath,
|
135 | '--browser', path.join(__dirname, 'fixtures/protocol-relative-request.js')
|
136 | ]);
|
137 | child.on('close', function (code) {
|
138 | t.equal(code, 0);
|
139 | });
|
140 | });
|