Skip to content

Commit 1cc8402

Browse files
committed
feat: testBrowser resolves boolean telling if tests ran
1 parent cb0172d commit 1cc8402

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ const pages = {
2121

2222
async function main() {
2323
const baseURL = await startHTTPD();
24-
await testBrowser(t, 'firefox', baseURL, pages);
25-
await testBrowser(t, 'chrome', baseURL, pages);
24+
if (await testBrowser(t, 'firefox', baseURL, pages)) {
25+
console.log('Firefox tests ran');
26+
}
27+
if (await testBrowser(t, 'chrome', baseURL, pages)) {
28+
console.log('Chrome tests ran');
29+
}
2630
}
2731

2832
main().catch(t.error);

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function testBrowser(t, browser, daemon, pages) {
7070
() => {}
7171
);
7272

73-
return;
73+
return false;
7474
}
7575

7676
const baseURL = await getBaseURL(daemon);
@@ -109,4 +109,6 @@ export async function testBrowser(t, browser, daemon, pages) {
109109

110110
global.__coverage__ = coverageMap.toJSON();
111111
}
112+
113+
return true;
112114
}

tap-snapshots/test.js-TAP.test.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8-
exports[`test.js TAP chrome page2.html > must match snapshot 1`] = `
8+
exports[`test.js TAP firefox page2.html > must match snapshot 1`] = `
99
Buffer <
1010
0000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 0000 000a 0000 000a 0806 0000 008d 32cf .PNG........IHDR..............2.
1111
0020: bd00 0000 2449 4441 5478 018d c101 0100 0008 8330 a47f e75b 81ed 0623 9048 2289 ....$IDATx.........0...[...#.H".
1212
0040: 2492 4822 8924 92e8 013d 9c02 12e9 563f 9000 0000 0049 454e 44ae 4260 82 $.H".$...=....V?.....IEND.B\`.
1313
>
1414
`
1515

16-
exports[`test.js TAP firefox page2.html > must match snapshot 1`] = `
16+
exports[`test.js TAP firefox page2.html > must match snapshot 2`] = `
1717
Buffer <
1818
0000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 0000 000a 0000 000a 0806 0000 008d 32cf .PNG........IHDR..............2.
1919
0020: bd00 0000 2449 4441 5478 018d c101 0100 0008 8330 a47f e75b 81ed 0623 9048 2289 ....$IDATx.........0...[...#.H".

test.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ async function main() {
3535
const baseURL = `http://localhost:${daemon.server.address().port}/`;
3636

3737
await t.rejects(testBrowser(t), TypeError);
38-
await testBrowser(t, deadBrowser, baseURL, {
38+
let tested = await testBrowser(t, deadBrowser, baseURL, {
3939
async 'page1.html'(t) {
4040
t.fail('should not get here');
4141
}
4242
});
4343

44+
t.equal(tested, false);
45+
4446
await t.test('after deadBrowser', async t => t.same(global.__coverage__, {}));
4547

4648
let gotCoverage;
@@ -57,12 +59,20 @@ async function main() {
5759
}
5860
};
5961

60-
await testBrowser(t, 'chrome', baseURL, pages);
61-
await t.test('after chrome', async t => {
62-
t.same(JSON.parse(JSON.stringify(global.__coverage__)), gotCoverage);
63-
t.ok(Object.keys(global.__coverage__).length);
64-
});
65-
global.__coverage__ = {};
62+
const standardTest = async browser => {
63+
tested = await testBrowser(t, browser, baseURL, pages);
64+
if (tested) {
65+
await t.test(`after ${browser}`, async t => {
66+
t.same(JSON.parse(JSON.stringify(global.__coverage__)), gotCoverage);
67+
t.ok(Object.keys(global.__coverage__).length);
68+
});
69+
70+
global.__coverage__ = {};
71+
}
72+
};
73+
74+
await standardTest('chrome');
75+
await standardTest('firefox');
6676

6777
const simulateDaemon = {
6878
calls: {
@@ -81,7 +91,7 @@ async function main() {
8191
return baseURL;
8292
}
8393
};
84-
await testBrowser(t, 'firefox', simulateDaemon, {
94+
tested = await testBrowser(t, 'firefox', simulateDaemon, {
8595
async 'page1.html'(t, selenium) {
8696
t.same(simulateDaemon.calls, {
8797
start: 1,
@@ -99,15 +109,17 @@ async function main() {
99109
await pages['page2.html'](t, selenium);
100110
}
101111
});
102-
await t.test('after firefox', async t => {
103-
t.same(simulateDaemon.calls, {
104-
start: 1,
105-
stop: 1,
106-
url: 1
112+
if (tested) {
113+
await t.test('after firefox', async t => {
114+
t.same(simulateDaemon.calls, {
115+
start: 1,
116+
stop: 1,
117+
url: 1
118+
});
119+
t.same(JSON.parse(JSON.stringify(global.__coverage__)), gotCoverage);
120+
t.ok(Object.keys(global.__coverage__).length);
107121
});
108-
t.same(JSON.parse(JSON.stringify(global.__coverage__)), gotCoverage);
109-
t.ok(Object.keys(global.__coverage__).length);
110-
});
122+
}
111123

112124
t.test('platformBin for linux', platformTest('linux'));
113125
t.test('platformBin for mac', platformTest('mac'));

0 commit comments

Comments
 (0)