-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest-client.js
144 lines (111 loc) · 3.08 KB
/
test-client.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const EC = require('eight-colors');
const { chromium } = require('playwright');
const puppeteer = require('puppeteer');
const MCR = require('../');
const checkSnapshot = require('./check-snapshot.js');
const coverageOptions = {
// logging: 'debug',
name: 'My V8 Client Coverage Report',
// watermarks: [60, 90],
reports: [
// ['console-details', {
// maxCols: 20
// }],
'v8'
],
assetsPath: '../assets',
// lcov: true,
entryFilter: (entry) => {
if (entry.url && entry.url.includes('src')) {
return true;
}
},
outputDir: './docs/client',
onEnd: function(coverageResults) {
checkSnapshot(coverageResults);
}
};
const getPageHtml = (key) => {
return `<html>
<head>
<title>mock ${key} anonymous</title>
<style>
body { font-size: 16px; }
h3 { display: block; }
.unused {
border: 1px solid #ccc;
}
.uncovered {
color: red;
}
.${key} {
color: green;
}
/*# sourceURL=src/${key}.css*/
</style>
</head>
<body>
<h3>mock page anonymous</h3>
<div class="${key}">${key}<div>
<script>
const sourceURL = "${key}";
const uncovered = () => {
console.log("uncovered");
};
//# sourceURL=src/${key}.js
</script>
</body>
</html>`;
};
const testPlaywright = async (coverageReport) => {
// =====================================================
const browser = await chromium.launch();
const page = await browser.newPage();
const session = await page.context().newCDPSession(page);
const client = await MCR.CDPClient({
session
});
await client.startCoverage();
await page.setContent(getPageHtml('playwright'));
const coverageData = await client.stopCoverage();
await client.close();
await browser.close();
await coverageReport.add(coverageData);
};
const testPuppeteer = async (coverageReport) => {
const browser = await puppeteer.launch({
// headless: false,
args: ['--no-sandbox']
});
const page = await browser.newPage();
// Playwright: By default, the Playwright tests run on a default viewport size of 1280x720 .
// Puppeteer: Defaults to an 800x600 viewport.
await page.setViewport({
width: 1280,
height: 720,
deviceScaleFactor: 1
});
const session = await page.target().createCDPSession();
const client = await MCR.CDPClient({
session
});
await client.startCoverage();
await page.setContent(getPageHtml('puppeteer'));
const coverageData = await client.stopCoverage();
await client.close();
await browser.close();
await coverageReport.add(coverageData);
};
const generate = async () => {
// clean cache first
const coverageReport = MCR(coverageOptions);
coverageReport.cleanCache();
await testPlaywright(coverageReport);
await testPuppeteer(coverageReport);
// test node see test-node-cdp
if (coverageReport.hasCache()) {
const coverageResults = await coverageReport.generate();
console.log('test client coverage reportPath', EC.magenta(coverageResults.reportPath));
}
};
generate();