-
Notifications
You must be signed in to change notification settings - Fork 58
/
puppeteer.integration.js
81 lines (70 loc) · 2.17 KB
/
puppeteer.integration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
const fs = require('fs');
const path = require('path');
const { assert } = require('@sinonjs/referee-sinon');
const execa = require('execa');
describe('puppeteer', () => {
async function run(file, ...extra_args) {
try {
return await execa(
'../../index.js',
[file, '--driver', 'puppeteer', ...extra_args],
{
cwd: path.join(__dirname, 'fixture')
}
);
} catch (error) {
return error;
}
}
it('passes', async () => {
const result = await run('passes.js');
assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(json.tests[0].fullTitle, 'test passes');
});
it('reads from stdin', async () => {
let result;
try {
const cp = execa('../../index.js', ['--driver', 'puppeteer', '-'], {
cwd: path.join(__dirname, 'fixture')
});
const fixture = fs.createReadStream(
path.resolve(__dirname, './fixture/passes.js')
);
fixture.pipe(cp.stdin);
result = await cp;
} catch (err) {
result = err;
}
assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(json.tests[0].fullTitle, 'test passes');
});
it('fails', async () => {
const result = await run('fails.js');
assert.isTrue(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(json.tests[0].fullTitle, 'test fails');
});
it('does not leak client functions into global scope', async () => {
const result = await run('client-leak.js');
assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(
json.tests[0].fullTitle,
'test does not leak client functions into global scope'
);
});
it('handles esm', async () => {
const result = await run('esm.test.js', '--esm');
assert.isFalse(result.failed);
const json = JSON.parse(result.stdout);
assert.equals(json.tests.length, 1);
assert.equals(json.tests[0].fullTitle, 'test passes');
});
});