-
Notifications
You must be signed in to change notification settings - Fork 43
/
cypress.config.js
97 lines (90 loc) · 3.85 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
const AllureWriter = require('./writer');
const webpack = require('@cypress/webpack-preprocessor');
const {
addCucumberPreprocessorPlugin
} = require('@badeball/cypress-cucumber-preprocessor');
const fs = require('fs');
const path = require('path');
const { defineConfig } = require('cypress');
module.exports = defineConfig({
e2e: {
setupNodeEvents: async function (on, config) {
await addCucumberPreprocessorPlugin(on, config);
on(
'file:preprocessor',
webpack({
webpackOptions: {
resolve: { extensions: ['.ts', '.js'] },
module: {
rules: [
{
test: /\.feature$/,
use: [
{
loader: '@badeball/cypress-cucumber-preprocessor/webpack',
options: config
}
]
}
]
}
}
})
);
AllureWriter(on, config);
on('task', {
readAllureResults: () => {
try {
const dir = 'cypress/fixtures';
const subdirs = ['basic', 'cucumber', 'statuses'];
return subdirs.reduce((dirMap, subdir) => {
const dirFiles = fs.readdirSync(
path.join(dir, subdir)
);
dirMap[subdir] = dirFiles.reduce((fileMap, f) => {
const getType = (file) => {
const types = {
suites: (f) => f.includes('-container'),
tests: (f) => f.includes('-result'),
attachments: (f) =>
f.includes('-attachment')
};
return Object.keys(types).find((type) =>
types[type](file)
);
};
const resultType = getType(f);
const fileContent = fs.readFileSync(
path.join(dir, subdir, f),
{
encoding: 'utf-8'
}
);
const fileValue = f.endsWith('.json')
? {
...JSON.parse(fileContent),
fileName: f
}
: {
content: fileContent.substr(0, 20),
fileName: f
};
!fileMap[resultType] &&
(fileMap[resultType] = []);
fileMap[resultType].push(fileValue);
return fileMap;
}, {});
return dirMap;
}, {});
} catch (e) {
return e;
}
}
});
return config;
},
env: {
stepDefinitions: `cypress/e2e/cucumber/**/*.cy.js`
}
}
});