-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
cypress.config.js
61 lines (48 loc) · 1.46 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
const { defineConfig } = require('cypress')
/* eslint-disable no-console */
const fs = require('fs')
const path = require('path')
const findRecord = (title) => {
const dbFilename = path.join(__dirname, 'data.json')
const contents = JSON.parse(fs.readFileSync(dbFilename))
const todos = contents.todos
return todos.find((record) => record.title === title)
}
const hasRecordAsync = (title, ms) => {
const delay = 50
return new Promise((resolve, reject) => {
if (ms < 0) {
return reject(new Error(`Could not find record with title "${title}"`))
}
const found = findRecord(title)
if (found) {
return resolve(found)
}
setTimeout(() => {
hasRecordAsync(title, ms - delay).then(resolve, reject)
}, 50)
})
}
module.exports = defineConfig({
video: false,
e2e: {
baseUrl: 'http://localhost:3000',
supportFile: false,
setupNodeEvents (on, config) {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('task', {
hasSavedRecord (title, ms = 3000) {
console.log('looking for title "%s" in the database (time limit %dms)',
title, ms)
return hasRecordAsync(title, ms)
},
testTimings (attributes) {
console.log('Test "%s" has finished in %dms', attributes.title, attributes.duration)
console.table(attributes.commands)
return null
},
})
},
},
})