-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress.config.ts
70 lines (63 loc) · 2.13 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
import { defineConfig } from "cypress";
import getCompareSnapshotsPlugin from "cypress-visual-regression/dist/plugin";
import fs from 'fs'
import path from 'path'
import registerCodeCoverageTasks from '@cypress/code-coverage/task'
const HEIGHT: number = 710;
const WIDTH: number = 1270;
export default defineConfig({
viewportWidth: WIDTH,
viewportHeight: HEIGHT,
reporter: 'mochawesome',
reporterOptions: {
embeddedScreenshots: true,
reportDir: 'cypress/results',
overwrite: false,
html: true,
json: true,
},
env: {
SNAPSHOT_DIFF_DIRECTORY: "./cypress/results/diff",
screenshotsFolder: './cypress/snapshots/actual',
trashAssetsBeforeRuns: true,
video: false,
failSilently: false,
type: 'actual' //'base',
},
e2e: {
specPattern: 'cypress/e2e/*',
experimentalStudio : true,
setupNodeEvents(on, config) {
registerCodeCoverageTasks(on, config);
getCompareSnapshotsPlugin(on, config);
on('before:browser:launch', (browser, launchOptions) => {
launchOptions.args.push(`--window-size=${WIDTH + 10},${HEIGHT + 10}`)
return launchOptions
})
on('after:screenshot', (details) => {
var newPath = details.path
const basePath = './cypress/results/screenshots/'
if (!fs.existsSync(path.resolve(basePath))){
if (!fs.existsSync(path.resolve('./cypress/results/'))) {
fs.mkdirSync(path.resolve('./cypress/results/'));
}
fs.mkdirSync(path.resolve(basePath));
}
if (details.testFailure) {
newPath = path.resolve(basePath + path.parse(details.path).base)
}
return new Promise((resolve, reject) => {
// fs.rename moves the file to the existing directory 'new/path/to'
// and renames the image to 'screenshot.png'
fs.rename(details.path, newPath, (err) => {
if (err) return reject(err)
// because we renamed and moved the image, resolve with the new path
// so it is accurate in the test results
resolve({ path: newPath })
})
})
});
return config
},
}
});