forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase-config.ts
More file actions
219 lines (195 loc) · 8.43 KB
/
base-config.ts
File metadata and controls
219 lines (195 loc) · 8.43 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* eslint-disable no-console */
import { defineConfig } from 'cypress';
import websocketTasks from './support/utils/webSocket-utils';
import path from 'path';
import fs from 'fs';
const { removeDirectory } = require('cypress-delete-downloads-folder');
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
// Required for env vars to be available in cypress
require('dotenv').config();
/**
* Filter test spec paths based on env var configuration
*/
const getSpecPattern = (dirs: string[], envs: NodeJS.ProcessEnv): string[] => {
// Gets paths with only
const onlyDirs = dirs.filter((dir) => (envs.TEST_ONLY?.split(',').map((env) => env.trim()).includes(dir)));
// List the test directories to be included
const activeDirs = dirs.filter((dir) => !(envs.TEST_SKIP?.split(',').map((env) => env.trim()).includes(dir)));
const finalDirs = onlyDirs.length ? onlyDirs : activeDirs;
const paths = finalDirs.map((dir) => `cypress/e2e/tests/${ dir }/**/*.spec.ts`);
if (process.env.NODE_ENV !== 'test') {
// eslint-disable-next-line no-console
console.log(`Running tests for paths: ${ paths.join(', ') }`);
}
return paths;
};
/**
* VARIABLES
*/
const hasCoverage = (process.env.TEST_INSTRUMENT === 'true') || false; // Add coverage if instrumented
let testDirs = ['priority', 'components', 'setup', 'pages', 'navigation', 'global-ui', 'features', 'extensions'];
const skipSetup = process.env.TEST_SKIP?.includes('setup');
const baseUrl = (process.env.TEST_BASE_URL || 'https://localhost:8005').replace(/\/$/, '');
const DEFAULT_USERNAME = 'admin';
const username = process.env.TEST_USERNAME || DEFAULT_USERNAME;
const apiUrl = process.env.API || (baseUrl.endsWith('/dashboard') ? baseUrl.split('/').slice(0, -1).join('/') : baseUrl);
if (process.env.TEST_A11Y) {
testDirs = ['accessibility'];
}
/**
* LOGS:
* Summary of the environment variables that we have detected (or are going ot use)
* We won't show any passwords
*/
console.log('E2E Test Configuration');
console.log('');
console.log(` Username: ${ username }`);
if (!process.env.CATTLE_BOOTSTRAP_PASSWORD && !process.env.TEST_PASSWORD) {
console.log(' ❌ You must provide either CATTLE_BOOTSTRAP_PASSWORD or TEST_PASSWORD');
}
if (process.env.CATTLE_BOOTSTRAP_PASSWORD && process.env.TEST_PASSWORD) {
console.log(' ❗ If both CATTLE_BOOTSTRAP_PASSWORD and TEST_PASSWORD are provided, the first will be used');
}
if (!skipSetup && !process.env.CATTLE_BOOTSTRAP_PASSWORD) {
console.log(' ❌ You must provide CATTLE_BOOTSTRAP_PASSWORD when running setup tests');
}
if (skipSetup && !process.env.TEST_PASSWORD) {
console.log(' ❌ You must provide TEST_PASSWORD when running the tests without the setup tests');
}
console.log(` Setup tests will ${ skipSetup ? 'NOT' : '' } be run`);
console.log(` Dashboard URL: ${ baseUrl }`);
console.log(` Rancher API URL: ${ apiUrl }`);
// Check API - sometimes in dev, you might have API set to a different system to the base url - this won't work
// as the login cookie will be for the base url and any API requests will fail as not authenticated
if (apiUrl && !baseUrl.startsWith(apiUrl)) {
console.log('\n ❗ API variable is different to TEST_BASE_URL - tests may fail due to authentication issues');
}
console.log('');
/**
* Base Cypress configuration for Rancher Dashboard E2E tests
*/
const baseConfig = defineConfig({
defaultCommandTimeout: process.env.TEST_TIMEOUT ? +process.env.TEST_TIMEOUT : 10000,
trashAssetsBeforeRuns: true,
chromeWebSecurity: false,
retries: {
runMode: 2,
openMode: 0
},
env: {
grepFilterSpecs: true,
grepOmitFiltered: true,
baseUrl,
coverage: hasCoverage,
codeCoverage: {
exclude: [
'cypress/**/*.*',
'**/__tests__/**/*.*',
'**/__mocks__/**/*.*',
'**/shell/scripts/**/*.*',
'docusaurus/**/*.*',
'stories/**/*.*',
'drone/**/*.*',
],
include: [
'shell/**/*.{vue,ts,js}',
'pkg/rancher-components/src/components/**/*.{vue,ts,js}',
]
},
api: apiUrl,
username,
password: process.env.CATTLE_BOOTSTRAP_PASSWORD || process.env.TEST_PASSWORD,
bootstrapPassword: process.env.CATTLE_BOOTSTRAP_PASSWORD,
grepTags: process.env.GREP_TAGS,
VAI_ENABLED: process.env.VAI_ENABLED,
// the below env vars are only available to tests that run in Jenkins
awsAccessKey: process.env.AWS_ACCESS_KEY_ID,
awsSecretKey: process.env.AWS_SECRET_ACCESS_KEY,
azureSubscriptionId: process.env.AZURE_AKS_SUBSCRIPTION_ID,
azureClientId: process.env.AZURE_CLIENT_ID,
azureClientSecret: process.env.AZURE_CLIENT_SECRET,
customNodeIp: process.env.CUSTOM_NODE_IP,
customNodeKey: process.env.CUSTOM_NODE_KEY,
customNodeUser: process.env.CUSTOM_NODE_USER || 'ec2-user',
accessibility: !!process.env.TEST_A11Y, // Are we running accessibility tests?
a11yFolder: path.join('.', 'cypress', 'accessibility'),
gkeServiceAccount: process.env.GKE_SERVICE_ACCOUNT,
// Set to 'true' to allow skipping when a chart is filtered from the UI catalog.
allowFilteredCatalogSkip: process.env.CYPRESS_ALLOW_FILTERED_CATALOG_SKIP,
},
reporter: 'cypress-mochawesome-reporter',
reporterOptions: {
saveJson: true,
saveAllAttempts: true,
reportDir: 'cypress/reports'
},
e2e: {
fixturesFolder: 'cypress/e2e/blueprints',
setupNodeEvents(on, config) {
// For more info: https://docs.cypress.io/guides/tooling/code-coverage
require('@cypress/code-coverage/task')(on, config);
require('@cypress/grep/src/plugin')(config);
// For more info: https://www.npmjs.com/package/cypress-delete-downloads-folder
on('task', { removeDirectory });
websocketTasks(on, config);
require('cypress-terminal-report/src/installLogsPrinter')(on, {
outputRoot: `${ config.projectRoot }/browser-logs/`,
outputTarget: { 'out.html': 'html' },
logToFilesOnAfterRun: true,
printLogsToConsole: 'never',
// printLogsToFile: 'always', // default prints on failures
});
// Load Accessibility plugin if configured
// as per https://github.com/rancher/dashboard/pull/15865 load order matters
// this need to go after "cypress-terminal-report" always
if (process.env.TEST_A11Y) {
require('./support/plugins/accessibility').default(on, config);
} else {
// Add in the cypress-mochawesome-reporter reporter hooks
on('before:run', async(details) => {
await beforeRunHook(details);
});
// Done this way to catch errors when there are no tests run
on('after:run', async() => {
// We need to wait for the cypress-terminal-report plugin to finish writing the browser logs
// There's a race condition where the mochawesome afterRunHook can finish and exit the process
// before the terminal report is written.
const logFile = path.join(config.projectRoot, 'browser-logs', 'out.html');
const timeout = 5000; // 5 seconds
const interval = 100; // 100 ms
let waited = 0;
const fileExists = () => {
try {
return fs.existsSync(logFile);
} catch (e) {
return false;
}
};
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
while (waited < timeout && !fileExists()) {
await wait(interval);
waited += interval;
}
if (!fileExists()) {
console.warn(`\n\n⚠️ Browser log file not found at ${ logFile } after ${ timeout }ms. Proceeding without it.\n\n`);
}
try {
await afterRunHook();
} catch (error) {
console.error(error); // eslint-disable-line no-console
}
});
}
return config;
},
experimentalSessionAndOrigin: true,
specPattern: getSpecPattern(testDirs, process.env),
baseUrl
},
videoCompression: 15,
videoUploadOnPasses: false,
screenshotOnRunFailure: process.env.TEST_NO_SCREENSHOTS !== 'true',
video: process.env.TEST_NO_VIDEOS !== 'true'
});
// Default export is the base config
export default baseConfig;