forked from JeremyHeleine/Photo-Sphere-Viewer
-
-
Notifications
You must be signed in to change notification settings - Fork 691
/
cypress.config.ts
105 lines (87 loc) · 3.94 KB
/
cypress.config.ts
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
import fs from 'fs-extra';
import registerCodeCoverageTasks from '@cypress/code-coverage/task';
import { defineConfig } from 'cypress';
// @ts-ignore
import cypressOnFix from 'cypress-on-fix';
import { configureVisualRegression } from 'cypress-visual-regression';
// @ts-ignore
import cypressMochawesomeReporterPlugin from 'cypress-mochawesome-reporter/plugin';
export default defineConfig({
e2e: {
viewportWidth: 1280,
viewportHeight: 900,
baseUrl: 'https://127.0.0.1:8080',
scrollBehavior: false,
screenshotOnRunFailure: false,
env: {
visualRegressionType: 'regression',
},
setupNodeEvents(on, config) {
on = cypressOnFix(on);
fs.removeSync('.nyc_output');
registerCodeCoverageTasks(on, config);
configureVisualRegression(on);
cypressMochawesomeReporterPlugin(on);
// define browser size for screenshots (headless mode)
on('before:browser:launch', (browser, launchOptions) => {
// should be bigger than the largest viewport used + browser UI elements
const width = 1600;
const height = 1200;
if (browser.name.startsWith('chrom') && browser.isHeadless) {
launchOptions.args.push(`--window-size=${width},${height}`);
launchOptions.args.push('--force-device-scale-factor=1');
}
if (browser.name === 'electron' && browser.isHeadless) {
launchOptions.preferences.width = width;
launchOptions.preferences.height = height;
}
if (browser.name === 'firefox' && browser.isHeadless) {
launchOptions.args.push(`--width=${width}`);
launchOptions.args.push(`--height=${height}`);
}
return launchOptions
});
// move lcov html report
on('after:run', () => {
const ROOT_DIR = 'cypress/reports/';
console.log(`Move ${ROOT_DIR}lcov-viewer to ${ROOT_DIR}html/coverage`);
fs.mkdirSync(`${ROOT_DIR}html/coverage`, { recursive: true });
fs.copyFileSync(`${ROOT_DIR}lcov-viewer/report-data.js`, `${ROOT_DIR}html/coverage/report-data.js`);
let content = fs.readFileSync(`${ROOT_DIR}lcov-viewer/index.html`, 'utf-8')
.replace('src="app.js"', 'src="https://cdn.jsdelivr.net/npm/@lcov-viewer/istanbul-report@1/lib/assets/app.js"')
.replace(/<title>.*<\/title>/, '<title>Photo Sphere Viewer - E2E coverage</title>');
fs.writeFileSync(`${ROOT_DIR}html/coverage/index.html`, content, 'utf-8');
console.log(`Add link to coverage in ${ROOT_DIR}html/index.html`);
content = fs.readFileSync(`${ROOT_DIR}html/index.html`, 'utf-8')
.replace('</body>', `<script>
const list = document.querySelector('[class^="quick-summary--list"]');
const item = list.firstChild.cloneNode(true);
item.querySelector('i').innerHTML = '';
item.querySelector('span').innerHTML = '<a href="coverage" style="color:white;text-decoration:underline;">Coverage</a>';
list.prepend(item);
</script></body>`);
fs.writeFileSync(`${ROOT_DIR}html/index.html`, content, 'utf-8');
});
return config;
},
},
clientCertificates: [
{
url: 'https://127.0.0.1:8080',
certs: [{
cert: '.tmp/fake-cert.pem',
key: '.tmp/fake-cert.key',
}],
},
],
reporter: 'build/mocha-reporter.js',
reporterOptions: {
cypress: true,
// cypress-mochawesome-reporter
removeJsonsFolderAfterMerge: false,
cdn: true,
charts: true,
reportTitle: 'Photo Sphere Viewer',
reportPageTitle: 'Photo Sphere Viewer - E2E results',
},
});