-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress.config.ts
47 lines (39 loc) · 1.9 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
import { defineConfig } from "cypress";
export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
viewportHeight: 800,
viewportWidth: 1280,
setupNodeEvents(on, config) {
// cypress-dotenv doesnt work with cypress 10 so moving plugin code here.
const cypressPrefix = 'CYPRESS_'
// load the content of the .env file, then parse each variable to the correct type (string, number, boolean, etc.)
let envVars = require('dotenv').config()
// if no env vars were parsed, then there is nothing to do here (most likely an empty or non-existing .env file)
if (envVars.parsed === undefined) {
return config
}
const dotenvParseVariables = require('dotenv-parse-variables')
envVars = dotenvParseVariables(envVars.parsed)
// get the name of all env vars that relate to cypress
const cypressEnvVarKeys = false
? Object.keys(envVars)
: Object.keys(envVars).filter((envName) => envName.startsWith(cypressPrefix))
const camelCase = require("camelcase");
cypressEnvVarKeys.forEach((originalName) => {
const pattern = new RegExp(`^${cypressPrefix}`, 'g')
const cleanName = originalName.replace(pattern, '')
const camelCaseName = camelCase(cleanName)
const parsedEnvar = envVars[originalName]
const processEnvVar = process.env[originalName]
const envVar = typeof parsedEnvar === 'string' ? processEnvVar : parsedEnvar
config.env[cleanName] = envVar
if (config.hasOwnProperty(camelCaseName) && camelCaseName !== 'env') {
config[camelCaseName] = envVar
}
})
return config
},
experimentalSessionAndOrigin: true,
},
});