-
Notifications
You must be signed in to change notification settings - Fork 321
/
.testcaferc.js
182 lines (164 loc) · 5.44 KB
/
.testcaferc.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
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
const { readFileSync } = require('fs');
const { RequestMock } = require('testcafe');
const waitOn = require('wait-on');
/**
* Escapes special regex chars in string so it can be used as the pattern for
* RegExp constructor. Useful when trying to match strings that frequently
* contain special chars, e.g., (parts of) a URL,
* currency, dates.
*
* NOTE: all special chars including "^" and "$" are escaped
*
* Examples:
*
* escapeRegex("http://example.com/path") // "http:\\/\\/example\\.com\\/path"
*
* escapeRegex('$12.34') // "\\$12\\.34"
*
* escapeRegex('7/12/2021') // "7\\/12\\/2021"
*
* @param s {string} the string to escape
* @returns {string} the escaped string
*/
const escapeRegex = (s) => s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
/**
* Creates an escaped regex from a string template literal.
*
* Example: regex`$12.34` // new RegExp("\\$12\\.34")
*/
const regex = (strings, ...values) => {
const pattern = strings[0] + values.map(
(v, i) => escapeRegex(v) + strings[i + 1]
).join('');
return RegExp(pattern);
};
// common/shared mocks
const mocks = RequestMock()
.onRequestTo({ url: regex`/app/UserHome` })
.respond(readFileSync('./playground/mocks/app/UserHome.html', 'utf8'), 200, { 'content-type': 'text/html; charset=utf-8' })
.onRequestTo({ url: regex`/oauth2/default/.well-known/openid-configuration` })
.respond(require('./playground/mocks/data/oauth2/well-known-openid-configuration.json'))
.onRequestTo({ url: regex`/sso/idps/facebook-123` })
.respond('');
// NOTE: process.env always returns type 'string'
const {
OKTA_SIW_ONLY_FLAKY,
OKTA_SIW_SKIP_FLAKY,
OKTA_SIW_GEN3,
OKTA_SIW_EN_LEAKS,
UPDATE_SCREENSHOTS,
OKTA_SIW_MOBILE,
CI,
CHROME_HEADLESS,
} = process.env;
// Normalize process.env to type 'boolean'
const env = {
OKTA_SIW_ONLY_FLAKY: OKTA_SIW_ONLY_FLAKY === 'true',
OKTA_SIW_SKIP_FLAKY: OKTA_SIW_SKIP_FLAKY === 'true',
OKTA_SIW_GEN3: OKTA_SIW_GEN3 === 'true',
OKTA_SIW_EN_LEAKS: OKTA_SIW_EN_LEAKS === 'true',
OKTA_SIW_MOBILE: OKTA_SIW_MOBILE === 'true',
CHROME_HEADLESS: (CHROME_HEADLESS === 'true' || CI === 'true'),
CI: CI === 'true',
UPDATE_SCREENSHOTS: UPDATE_SCREENSHOTS === 'true',
};
const chromeName = env.CHROME_HEADLESS ? 'chrome:headless' : 'chrome';
const chromeOptions = env.OKTA_SIW_MOBILE ? ':emulation:device=iphone X' : '';
const chromeFlags = env.CHROME_HEADLESS ? '' : ' --disable-search-engine-choice-screen';
const chromeFullName = `${chromeName}${chromeOptions}${chromeFlags}`;
const config = {
browsers: [chromeFullName],
hostname: env.CHROME_HEADLESS ? undefined : 'localhost',
clientScripts: env.OKTA_SIW_EN_LEAKS ? [
] : [
{ module: 'axe-core/axe.min.js' },
{ module: '@testing-library/dom/dist/@testing-library/dom.umd.js' }
],
src: env.OKTA_SIW_MOBILE ? [
'test/testcafe/spec/EnrollAuthenticatorOktaVerify_spec.js',
] : env.OKTA_SIW_EN_LEAKS ? [
'test/testcafe/spec-en-leaks/*_spec.js',
] : [
'test/testcafe/spec/*_spec.js',
'test/testcafe/spec/v1/*_spec.js'
],
hooks: {
fixture: {
before: async () => {
await waitOn({ resources: ['http-get://localhost:3000'] });
}
},
request: mocks,
},
userVariables: {
gen3: env.OKTA_SIW_GEN3,
mobile: env.OKTA_SIW_MOBILE,
updateScreenshots: env.UPDATE_SCREENSHOTS,
},
// OKTA-575629 Remove this when gen3 parity test flakiness is resolved
...(env.OKTA_SIW_GEN3 && {
assertionTimeout: 20000,
}),
// limit concurrency when running flaky tests
// OKTA_SIW_ONLY_FLAKY: 1 ← flaky
// !CHROME_HEADLESS: 1 ← for debugging tests
// OKTA_SIW_EN_LEAKS: 2 ← somewhat flaky
// !OKTA_SIW_EN_LEAKS: 4 ← most tests
concurrency: (OKTA_SIW_ONLY_FLAKY || !env.CHROME_HEADLESS)
? 1
: (env.OKTA_SIW_EN_LEAKS ? 2 : 4),
// retry failed tests
quarantineMode: env.OKTA_SIW_EN_LEAKS ? false : {
successThreshold: 1,
attemptLimit: 3,
},
filter: (_testName, _fixtureName, fixturePath, testMeta, fixtureMeta) => {
// only check one of {gen3 | gen2} conditionals. without this guard, a
// fixture or test will always get skipped in both testcafe runs
if (env.OKTA_SIW_GEN3) {
// Do not execute Gen 1 tests in parity suite
if (fixturePath.includes('spec/v1')) {
return false;
}
// skip fixture on gen3
// fixture('my tests').meta('gen3', false)
if (fixtureMeta.gen3 === false) {
return false;
}
// skip test on gen3
// test.meta('gen3', false)('my test', (t) => {})
if (testMeta.gen3 === false) {
return false;
}
} else {
// skip fixture on gen2
// fixture('my tests').meta('gen2', false)
if (fixtureMeta.gen2 === false) {
return false;
}
// skip test on gen2
// test.meta('gen2', false)('my test', (t) => {})
if (testMeta.gen2 === false) {
return false;
}
}
// flaky tests
// flaky tests should be run with low or no concurrency:
// yarn testcafe -c1
// fixture('my fixture').meta('flaky', true)
// test.meta('flaky', true)('my test', (t) => {})
if (fixtureMeta.flaky || testMeta.flaky) {
// OKTA_SIW_ONLY_FLAKY supercedes OKTA_SIW_SKIP_FLAKY
return env.OKTA_SIW_ONLY_FLAKY || !env.OKTA_SIW_SKIP_FLAKY;
}
// skip tests that are not intended to work on mobile devices
if (testMeta.mobile === false) {
return !env.OKTA_SIW_MOBILE;
}
return true;
},
screenshots: {
thumbnails: false,
},
}
module.exports = config;