-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathcypress.config.ts
More file actions
178 lines (165 loc) · 5.14 KB
/
cypress.config.ts
File metadata and controls
178 lines (165 loc) · 5.14 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* eslint-disable no-param-reassign */
import { defineConfig } from 'cypress';
import webpackPreprocessor from '@cypress/webpack-preprocessor';
import fs from 'fs';
import path from 'path';
import MomentTimezoneInclude from './src/app/legacy/psammead/moment-timezone-include/src';
import { webpackDirAlias } from './dirAlias';
import { DefinePlugin } from 'webpack';
import dotenv from 'dotenv';
const appDirectory = fs.realpathSync(process.cwd());
const resolvePath = (relativePath: string) =>
path.resolve(appDirectory, relativePath);
export default defineConfig({
reporter: 'cypress-multi-reporters',
reporterOptions: {
configFile: 'cypress/reporter-config.json',
},
e2e: {
setupNodeEvents(on, config) {
if (!config.env.APP_ENV) {
config.env.APP_ENV = 'local';
}
const appEnv = config.env.APP_ENV;
const env = config.env[appEnv];
const { parsed: appConfig } = dotenv.config({
path: `./envConfig/${config.env.APP_ENV}.env`,
});
// @ts-expect-error appConfig is a list of keys
const envVars = Object.keys(appConfig).reduce((vars, key) => {
// @ts-expect-error appConfig is a list of keys
vars[key] = JSON.stringify(appConfig[key]);
return vars;
}, {});
config.baseUrl = env.baseUrl;
// Debugging console logs to see running config
/* eslint-disable no-console */
console.log('\n\n\n\n\n');
console.log('Cypress running config:');
console.log('SMOKE:', config.env.SMOKE);
console.log('APP_ENV:', config.env.APP_ENV);
console.log('UK:', config.env.UK);
console.log('ONLY_SERVICE:', config.env.ONLY_SERVICE || '');
console.log('SKIP_EU:', Boolean(config.env.SKIP_EU));
console.log('\n\n\n\n\n');
/* eslint-enable no-console */
const options = {
webpackOptions: {
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
...webpackDirAlias,
},
},
module: {
rules: [
// tell Webpack to use the .babelrc to know how to transform JS/JSX to ES2015 JS
{
test: /\.(js|jsx|mjs)$/,
include: [resolvePath('src')],
use: [
{
loader: 'babel-loader',
},
],
},
{
test: /\.(ts|tsx)$/,
include: [resolvePath('src'), resolvePath('ws-nextjs-app')],
use: [
'babel-loader',
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
],
},
plugins: [
// @ts-expect-error - TODO: fix types
new MomentTimezoneInclude({ startYear: 2010, endYear: 2025 }),
new DefinePlugin({
process: {
env: envVars,
},
}),
],
},
watchOptions: {
ignored: ['**/tz/**'],
},
};
on('file:preprocessor', webpackPreprocessor(options));
// Add options for the cypress terminal report (cy.logs) here
const logPrinterOptions = {
defaultTrimLength: 2000,
};
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
require('cypress-terminal-report/src/installLogsPrinter')(
on,
logPrinterOptions,
);
on('task', {
log(message) {
// eslint-disable-next-line no-console
console.log(message);
return null;
},
table(message) {
// eslint-disable-next-line no-console
console.table(message);
return null;
},
error(message) {
// eslint-disable-next-line no-console
console.error(message);
return null;
},
});
return config;
},
env: {
APP_ENV: 'local',
SMOKE: true,
UK: false,
live: {
baseUrl: 'https://www.bbc.com',
},
test: {
baseUrl: 'https://www.test.bbc.com',
},
local: {
baseUrl: 'http://localhost:7080',
},
},
testIsolation: false,
excludeSpecPattern: [
'**/README.md',
'**/pages/**/tests.js',
'**/pages/**/urls.js',
'**/pages/**/testsForAMPOnly.js',
'**/*/pages/**/testsForCanonicalOnly.js',
'**/pages/testsForAllPages.js',
'**/pages/testsForAllAMPPages.js',
'**/pages/testsForAllCanonicalPages.js',
'**/pages/**/helper.js',
'**/pages/**/helpers.js',
'**/pages/**/getErrorPath.js',
'**/pages/**/mostReadAssertions.js',
'**/specialFeatures/utilities/**',
'**/specialFeatures/**/testsForAMPOnly.js',
'**/specialFeatures/**/testsForCanonicalOnly.js',
'**/specialFeatures/**/config.js',
],
},
video: false,
screenshotOnRunFailure: false,
blockHosts: 'gn-web-assets.api.bbc.com',
defaultCommandTimeout: 10000,
pageLoadTimeout: 100000,
responseTimeout: 70000,
chromeWebSecurity: false,
});