UNPKG

3.33 kBJavaScriptView Raw
1'use strict';
2
3var test = require('tape');
4var path = require('path');
5var http = require('http');
6var spawn = require('child_process').spawn;
7var parser = require('tap-parser');
8
9var runNode = require('../lib/run-node');
10var runElectron = require('../lib/run-electron');
11
12var cliPath = path.join(process.cwd(), 'bin/cli.js');
13
14var passingEntry = path.join(__dirname, 'fixtures/passing.js');
15var failingEntry = path.join(__dirname, 'fixtures/failing.js');
16var mockEntry = path.join(__dirname, 'fixtures/mock-entry.js');
17var errorEntry = path.join(__dirname, 'fixtures/error-entry.js');
18var exit123Entry = path.join(__dirname, 'fixtures/exit-123.js');
19
20test('basic node coverage reporting', function (t) {
21 t.plan(1);
22 runNode(mockEntry, function onCoverage(coverage) {
23 t.deepEqual(coverage, {});
24 });
25});
26
27test('basic electron coverage reporting', function (t) {
28 t.plan(1);
29 runElectron(mockEntry, function onCoverage(coverage) {
30 t.deepEqual(coverage, {});
31 });
32});
33
34test('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
45test('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
56test('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
66test('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
77test('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
88test('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
99test('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
110test('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
121test('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
132test('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});