-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcypress.config.js
135 lines (96 loc) · 4.48 KB
/
cypress.config.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
const { defineConfig } = require( 'cypress' )
// Video recording sizing
const browser_width = 1920
const browser_height = 1080
const viewport_width = 1024
const viewport_height = 1024*1.5
module.exports = defineConfig( {
// General options
defaultCommandTimeout: process.env.NODE_ENV == 'development' ? 60000 : 60000,
requestTimeout: process.env.NODE_ENV == 'development' ? 60000 : 60000,
watchForFileChanges: false,
// Video recording options
video: true,
videoCompression: false,
screenscreenshotOnRunFailureshots: true,
chromeWebSecurity: false,
// Browser viewport sizing
viewportWidth: viewport_width,
viewportHeight: viewport_height,
// Retries
retries: {
runMode: 1,
openMode: 1
},
// E2e conifg
e2e: {
// Experimental flag that restores the old "run all" button, may have bugs
experimentalRunAllSpecs: true,
setupNodeEvents( on, config ) {
console.log( `Setting up Cypress` )
// Cypress preprocessing
const webpackPreprocessor = require( '@cypress/webpack-preprocessor' )
on( 'file:preprocessor', webpackPreprocessor( {} ) )
/* ///////////////////////////////
// Browser configuration
// /////////////////////////////*/
on( 'before:browser:launch', ( browser = {}, launchOptions ) => {
const { name, family, isHeadless } = browser
/* ///////////////////////////////
// Open devtools */
if( family === 'chromium' && name !== 'electron' ) launchOptions.args.push( '--auto-open-devtools-for-tabs' )
if( family === 'firefox' ) launchOptions.args.push( '-devtools' )
if( name === 'electron' ) launchOptions.preferences.devTools = true
/* ///////////////////////////////
// Browser sizing */
console.log(
'launching browser %s is headless? %s',
name,
isHeadless
)
if( !isHeadless ) return launchOptions
console.log( 'setting the browser window size to %d x %d', browser_width, browser_height )
if( name === 'chrome' ) {
launchOptions.args.push( `--window-size=${ browser_width },${ browser_height }` )
// force screen to be non-retina and just use our given resolution
launchOptions.args.push( '--force-device-scale-factor=1' )
}
if( name === 'electron' ) {
// might not work on CI for some reason
launchOptions.preferences.width = browser_width
launchOptions.preferences.height = browser_height
}
if( name === 'firefox' ) {
launchOptions.args.push( `--width=${ browser_width }` )
launchOptions.args.push( `--height=${ browser_height }` )
}
return launchOptions
} )
// Config failfast module
require( "cypress-fail-fast/plugin" )( on, config )
// Load environment variables
let envFile = '.env.production'
// If in offline dev, use development env
if( process.env.NODE_ENV == 'development' ) envFile = '.env.development'
// If in CI use .env since the workflows write to that file on run
if( process.env.CI ) envFile = '.env'
const dotenvConfig = {
path: `${ __dirname }/${ envFile }`
}
console.log( `Runing cypress with ${ process.env.NODE_ENV } and ${ envFile }` )
// Set up environment variables in cypress tests
require( 'dotenv' ).config( dotenvConfig )
// Environment variables to pass to cypress because we need them in tests
const env_to_pass = [ 'VITE_projectId', 'VITE_useEmulator', 'VITE_publicUrl' ]
env_to_pass.map( key => {
if( process.env[ key ] ) config.env[ key ] = process.env[ key ]
else console.log( `Missing ${ key } in env` )
} )
// Setting up sorry cypress
const { cloudPlugin } = require( "cypress-cloud/plugin" )
return cloudPlugin( on, config )
},
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
baseUrl: "http://localhost:3000/#",
}
} )