-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcypress.setup.config.js
More file actions
67 lines (62 loc) · 2.54 KB
/
Copy pathcypress.setup.config.js
File metadata and controls
67 lines (62 loc) · 2.54 KB
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
const { defineConfig } = require('cypress')
require('dotenv').config()
const port = process.env.SETUP_PORT || 3001
module.exports = defineConfig({
retries: {
runMode: 1,
openMode: 0
},
video: false,
screenshotOnRunFailure: true,
e2e: {
baseUrl: `http://localhost:${port}`,
specPattern: 'cypress/e2e-setup/**/*.{js,jsx,ts,tsx}',
supportFile: 'cypress/support/e2e.js',
fixturesFolder: 'cypress/fixtures',
setupNodeEvents (on, config) {
const fs = require('fs')
const { prepareSetupDb, dropSetupDbs, CONSOLE_UUID } = require('./cypress/scripts/prepare-setup-db')
on('task', {
// Returns the directory the file was written into so callers can chain
// multiple files into the same dir by passing it back in `directory`.
writeBmConfigFixture ({ filename, contents, directory }) {
const path = require('path')
const os = require('os')
const tmp = directory || fs.mkdtempSync(path.join(os.tmpdir(), 'bm-setup-fixture-'))
if (!fs.existsSync(tmp)) fs.mkdirSync(tmp, { recursive: true })
const target = path.join(tmp, filename)
fs.writeFileSync(target, contents, 'utf8')
return tmp
},
prepareSetupDb (opts = {}) {
return prepareSetupDb(opts)
},
dropSetupDbs (opts = {}) {
return dropSetupDbs(opts)
},
readEnvFile (filePath) {
if (!fs.existsSync(filePath)) return null
return fs.readFileSync(filePath, 'utf8')
},
clearEnvFile (filePath) {
if (fs.existsSync(filePath)) fs.unlinkSync(filePath)
return null
},
getSetupConsoleUuid () {
return CONSOLE_UUID
},
sleep (ms) {
return new Promise((resolve) => setTimeout(() => resolve(null), ms))
}
})
config.env.setup_db_host = config.env.setup_db_host || process.env.DB_HOST || '127.0.0.1'
config.env.setup_db_port = config.env.setup_db_port || process.env.DB_PORT || '3306'
config.env.setup_db_user = config.env.setup_db_user || process.env.DB_USER || 'root'
config.env.setup_db_password = config.env.setup_db_password || process.env.DB_PASSWORD || ''
config.env.setup_dotenv_path = config.env.setup_dotenv_path || process.env.SETUP_DOTENV_PATH || '/tmp/bm-setup-test.env'
config.env.setup_db_name = config.env.setup_db_name || process.env.SETUP_DB_NAME || 'bm_e2e_setup'
config.env.setup_token = config.env.setup_token || process.env.SETUP_TOKEN || ''
return config
}
}
})