-
Notifications
You must be signed in to change notification settings - Fork 4
/
cypress.config.js
88 lines (85 loc) · 2.29 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
const { defineConfig } = require('cypress')
const xlsx = require("node-xlsx").default;
const fs = require("fs");
const { verifyDownloadTasks } = require('cy-verify-downloads');
const {downloadFile} = require('cypress-downloadfile/lib/addPlugin');
const mysql = require("mysql")
module.exports = defineConfig({
// chromeWebSecurity: false,
watchForFileChanges: false,
retries: {
runMode: 2
},
"env": {
"db": {
server: "127.0.0.1",
user: "root",
password: "12345678",
database: "ac"
}
},
e2e: {
defaultCommandTimeout: 6000,
setupNodeEvents(on, config) {
// return require('./cypress/plugins/index.js')(on, config)
require('cypress-terminal-report/src/installLogsPrinter')(on, {
printLogsToConsole: "always",
});
on("task", {
parseXlsx({ filePath }) {
return new Promise((resolve, reject) => {
try {
const jsonData = xlsx.parse(fs.readFileSync(filePath));
resolve(jsonData);
} catch (e) {
reject(e);
}
});
}
});
on('task', verifyDownloadTasks);
on('task', {downloadFile});
on("task", { deleteFileTask(fileName) {
return new Promise((resolve, reject) => {
fs.rm(fileName, {maxRetries: 10, recursive: true}, (err) => {
if (err) {
console.error(err)
return reject(err)
}
resolve(null)
})
})
}})
on("task", { deleteFolderTask(folderName) {
return new Promise((resolve, reject) => {
fs.rmdir(folderName, {maxRetries: 10, recursive: true}, (err) => {
if (err) {
console.error(err)
return reject(err)
}
resolve(null)
})
})
}})
on("task", {
queryDb: (query) => {
return queryOnDatabase (query, config)
}
})
},
},
})
function queryOnDatabase(query, config) {
const connection = mysql.createConnection(config.env.db)
connection.connect()
return new Promise((resolve, reject) => {
connection.query(query, (error, results) => {
if (error) reject(error)
else {
connection.end()
console.log(results)
return resolve(results)
}
})
})
}