-
Notifications
You must be signed in to change notification settings - Fork 3
/
cypress.config.ts
93 lines (83 loc) · 2.91 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
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
import { defineConfig } from "cypress";
import * as webpack from "@cypress/webpack-preprocessor";
import { addCucumberPreprocessorPlugin } from "@badeball/cypress-cucumber-preprocessor";
import fs = require('fs');
const getFiles = (path: string) => {
return fs.readdirSync(`${__dirname}/${path}`)
}
async function setupNodeEvents(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): Promise<Cypress.PluginConfigOptions> {
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
await addCucumberPreprocessorPlugin(on, config);
on('task', {
log(message) { console.log(message);return null;},
// info(message) { console.info(message);return null;},
// warn(message) { console.warn(message);return null;},
error(message) { console.error(message);return null;},
resolve(result) { return result;},
});
on(
"file:preprocessor",
webpack({
webpackOptions: {
resolve: {
extensions: [".ts", ".js"],
fallback: {
"string_decoder": require.resolve("string_decoder/"),
},
},
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: "ts-loader",
},
],
},
{
test: /\.feature$/,
use: [
{
loader: "@badeball/cypress-cucumber-preprocessor/webpack",
options: config,
},
],
},
],
},
},
})
);
// add simulator ParkAndRide data set
const parkAndRideDataFolder = './data/parkAndRide';
config.env.parkAndRide = getFiles(parkAndRideDataFolder).map(x => `${parkAndRideDataFolder}/${x}`);
const geomobilityDataFolder = './data/geomobility';
config.env.geomobility = getFiles(geomobilityDataFolder).map(x => `${geomobilityDataFolder}/${x}`);
// read user environment file
function parseEnvironmentFile(filePath: string) {
const content = filePath && fs.existsSync(filePath) && fs.readFileSync(filePath, 'utf-8');
const lines = content?.split('\n').filter(x => !!x);
const parsed = lines?.reduce((aggregated, line, _) => {
const keyValue = line.split('=').map(x => x.trim());
const key = keyValue[0];
const value = keyValue[1];
aggregated[key] = value;
return aggregated;
}, {});
return parsed;
}
config.env.userEnvironment = parseEnvironmentFile(config.env.userEnv);
if (config.env.userEnvironment) console.log("User Environment: ", config.env.userEnvironment);
// Make sure to return the config object as it might have been modified by the plugin.
return config;
}
export default defineConfig({
e2e: {
specPattern: "**/*.feature",
video: false,
// videoUploadOnPasses: false,
setupNodeEvents,
},
});