haven-cypress-integration 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/support.js +15 -1
- package/templates/run-filtered.sh +97 -16
package/package.json
CHANGED
package/support.js
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
const addContext = require('mochawesome/addContext');
|
|
12
12
|
|
|
13
|
+
// Sanitize filename to match Cypress's screenshot naming behavior
|
|
14
|
+
// Cypress replaces filesystem-unsafe characters with double spaces
|
|
15
|
+
function sanitizeFilename(name) {
|
|
16
|
+
// Characters Cypress replaces: / \ ? % * : | " < >
|
|
17
|
+
return name.replace(/[/\\?%*:|"<>]/g, ' ');
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
// Attach failed test screenshots to mochawesome report
|
|
14
21
|
// This enables screenshots to appear inline in the mochawesome HTML report
|
|
15
22
|
Cypress.on('test:after:run', (test, runnable) => {
|
|
@@ -26,8 +33,15 @@ Cypress.on('test:after:run', (test, runnable) => {
|
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
// Cypress screenshot naming: {specName}/{all describes joined by ' -- '} -- {testTitle} (failed).png
|
|
36
|
+
// Must sanitize same way Cypress does for filesystem-safe filenames
|
|
29
37
|
const fullTitle = [...titleParts, test.title].join(' -- ');
|
|
30
|
-
const
|
|
38
|
+
const sanitizedTitle = sanitizeFilename(fullTitle);
|
|
39
|
+
const screenshotPath = `screenshots/${specName}/${sanitizedTitle} (failed).png`;
|
|
40
|
+
|
|
41
|
+
// Debug: Log the generated path
|
|
42
|
+
console.log('[Haven] Screenshot path generated:', screenshotPath);
|
|
43
|
+
console.log('[Haven] Title parts:', titleParts);
|
|
44
|
+
console.log('[Haven] Test title:', test.title);
|
|
31
45
|
|
|
32
46
|
// Add screenshot to mochawesome context (will appear in HTML report)
|
|
33
47
|
addContext({ test }, screenshotPath);
|
|
@@ -23,6 +23,42 @@ done
|
|
|
23
23
|
echo "automationIds: ${AUTOMATION_IDS}"
|
|
24
24
|
echo "customTags: ${CUSTOM_TAGS}"
|
|
25
25
|
|
|
26
|
+
# =============================================================================
|
|
27
|
+
# HAVEN ENV VAR BRIDGE
|
|
28
|
+
# =============================================================================
|
|
29
|
+
# Collect all custom env vars from Haven and build Cypress --env args.
|
|
30
|
+
# This bridges Haven's env vars to Cypress's expected format.
|
|
31
|
+
#
|
|
32
|
+
# System/internal vars are excluded; everything else is passed to Cypress.
|
|
33
|
+
# =============================================================================
|
|
34
|
+
|
|
35
|
+
# Pattern for system/internal vars to EXCLUDE from Cypress --env
|
|
36
|
+
EXCLUDE_VARS="^(PATH|HOME|USER|SHELL|PWD|OLDPWD|TERM|LANG|LC_.*|AWS_.*|HOSTNAME|SHLVL|_|NODE_.*|NPM_.*|HAVEN_GREP_PATTERN|ADO_REPO|ADO_PAT|ADO_BRANCH|RUN_ID|PLAN_ID|PRODUCT_NAME|BUCKET_NAME|TRIGGERED_BY|INSTANCE_TYPE|E2E_COMMAND|TEST_ENVIRONMENT|CUSTOM_TAGS|AUTOMATION_IDS|HAVEN_BROWSERS|LS_COLORS|SSH_.*|XDG_.*|DISPLAY|COLORTERM|LESSOPEN|LESSCLOSE|MAIL|LOGNAME|EDITOR|VISUAL|PAGER|MANPATH|INFOPATH|HISTSIZE|HISTFILESIZE|HISTCONTROL|PS1|PS2|PROMPT_COMMAND|IFS)$"
|
|
37
|
+
|
|
38
|
+
echo "=== Building Cypress env vars from Haven ==="
|
|
39
|
+
CUSTOM_ENV_ARGS=""
|
|
40
|
+
|
|
41
|
+
while IFS='=' read -r key value; do
|
|
42
|
+
# Skip empty keys or excluded system vars
|
|
43
|
+
if [ -z "$key" ] || echo "$key" | grep -qE "$EXCLUDE_VARS"; then
|
|
44
|
+
continue
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
# Add to Cypress env args
|
|
48
|
+
if [ -n "$CUSTOM_ENV_ARGS" ]; then
|
|
49
|
+
CUSTOM_ENV_ARGS="${CUSTOM_ENV_ARGS},${key}=${value}"
|
|
50
|
+
else
|
|
51
|
+
CUSTOM_ENV_ARGS="${key}=${value}"
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
# Also export with CYPRESS_ prefix as fallback for test code access
|
|
55
|
+
export "CYPRESS_${key}=${value}"
|
|
56
|
+
|
|
57
|
+
echo " -> ${key}=*** (bridged to Cypress)"
|
|
58
|
+
done < <(env | grep -v "^_=" | sort)
|
|
59
|
+
|
|
60
|
+
echo "Custom env vars collected: $(echo "$CUSTOM_ENV_ARGS" | tr ',' '\n' | wc -l | tr -d ' ') variables"
|
|
61
|
+
|
|
26
62
|
TIMESTAMP=$(date +%m%d%Y_%H%M%S)
|
|
27
63
|
PRODUCT_NAME=${PRODUCT_NAME:-unknown_product}
|
|
28
64
|
PLAN_ID=${PLAN_ID:-unknown_plan}
|
|
@@ -126,46 +162,91 @@ if [ -z "$GREP_TAGS" ] && [ -z "$GREP_INVERT_TAGS" ]; then
|
|
|
126
162
|
fi
|
|
127
163
|
fi
|
|
128
164
|
|
|
129
|
-
#
|
|
130
|
-
CYPRESS_GREP_ARGS=""
|
|
165
|
+
# Export grep patterns for downstream use
|
|
131
166
|
if [ -n "$GREP_TAGS" ]; then
|
|
132
167
|
export HAVEN_GREP_INCLUDE="${GREP_TAGS}"
|
|
133
|
-
|
|
134
|
-
echo "Include pattern (HAVEN_GREP_INCLUDE): ${GREP_TAGS}"
|
|
168
|
+
echo "Include pattern: ${GREP_TAGS}"
|
|
135
169
|
fi
|
|
136
170
|
|
|
137
171
|
if [ -n "$GREP_INVERT_TAGS" ]; then
|
|
138
172
|
export HAVEN_GREP_EXCLUDE="${GREP_INVERT_TAGS}"
|
|
139
|
-
|
|
140
|
-
if [ -n "$CYPRESS_GREP_ARGS" ]; then
|
|
141
|
-
CYPRESS_GREP_ARGS="${CYPRESS_GREP_ARGS},grepInvert='${GREP_INVERT_TAGS}'"
|
|
142
|
-
else
|
|
143
|
-
CYPRESS_GREP_ARGS="--env grepInvert='${GREP_INVERT_TAGS}'"
|
|
144
|
-
fi
|
|
145
|
-
echo "Exclude pattern (HAVEN_GREP_EXCLUDE): ${GREP_INVERT_TAGS}"
|
|
173
|
+
echo "Exclude pattern: ${GREP_INVERT_TAGS}"
|
|
146
174
|
fi
|
|
147
175
|
|
|
148
176
|
if [ -z "$GREP_TAGS" ] && [ -z "$GREP_INVERT_TAGS" ]; then
|
|
149
|
-
echo "No
|
|
177
|
+
echo "No tag filters provided. Running all tests..."
|
|
150
178
|
fi
|
|
151
179
|
|
|
152
180
|
# Run Cypress
|
|
153
181
|
echo "Running Cypress tests..."
|
|
154
182
|
set +e
|
|
155
183
|
|
|
184
|
+
# Build final --env string combining custom vars and grep patterns
|
|
185
|
+
FINAL_ENV_ARGS=""
|
|
186
|
+
|
|
187
|
+
# Add custom env vars from Haven
|
|
188
|
+
if [ -n "$CUSTOM_ENV_ARGS" ]; then
|
|
189
|
+
FINAL_ENV_ARGS="${CUSTOM_ENV_ARGS}"
|
|
190
|
+
fi
|
|
191
|
+
|
|
192
|
+
# Add grep patterns (include)
|
|
193
|
+
if [ -n "$GREP_TAGS" ]; then
|
|
194
|
+
if [ -n "$FINAL_ENV_ARGS" ]; then
|
|
195
|
+
FINAL_ENV_ARGS="${FINAL_ENV_ARGS},grepTags=${GREP_TAGS}"
|
|
196
|
+
else
|
|
197
|
+
FINAL_ENV_ARGS="grepTags=${GREP_TAGS}"
|
|
198
|
+
fi
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
# Add grep patterns (exclude) - Cypress uses negative pattern with - prefix
|
|
202
|
+
if [ -n "$GREP_INVERT_TAGS" ]; then
|
|
203
|
+
# Append exclude tags with - prefix to grepTags
|
|
204
|
+
EXCLUDE_WITH_PREFIX=$(echo "$GREP_INVERT_TAGS" | sed 's/ / -/g' | sed 's/^/-/')
|
|
205
|
+
if [ -n "$FINAL_ENV_ARGS" ]; then
|
|
206
|
+
# If grepTags already exists, append exclude patterns
|
|
207
|
+
if echo "$FINAL_ENV_ARGS" | grep -q "grepTags="; then
|
|
208
|
+
FINAL_ENV_ARGS=$(echo "$FINAL_ENV_ARGS" | sed "s/grepTags=\([^,]*\)/grepTags=\1 ${EXCLUDE_WITH_PREFIX}/")
|
|
209
|
+
else
|
|
210
|
+
FINAL_ENV_ARGS="${FINAL_ENV_ARGS},grepTags=${EXCLUDE_WITH_PREFIX}"
|
|
211
|
+
fi
|
|
212
|
+
else
|
|
213
|
+
FINAL_ENV_ARGS="grepTags=${EXCLUDE_WITH_PREFIX}"
|
|
214
|
+
fi
|
|
215
|
+
fi
|
|
216
|
+
|
|
217
|
+
# Add standard grep options
|
|
218
|
+
if [ -n "$FINAL_ENV_ARGS" ]; then
|
|
219
|
+
FINAL_ENV_ARGS="${FINAL_ENV_ARGS},grepFilterSpecs=true,grepUntagged=false,grepEnabled=true"
|
|
220
|
+
else
|
|
221
|
+
FINAL_ENV_ARGS="grepFilterSpecs=true,grepUntagged=false,grepEnabled=true"
|
|
222
|
+
fi
|
|
223
|
+
|
|
224
|
+
# Add TEST_ENVIRONMENT
|
|
225
|
+
FINAL_ENV_ARGS="${FINAL_ENV_ARGS},TEST_ENVIRONMENT=${TEST_ENVIRONMENT}"
|
|
226
|
+
|
|
227
|
+
echo "Final Cypress --env args: ${FINAL_ENV_ARGS}"
|
|
228
|
+
|
|
156
229
|
if [ -n "$E2E_COMMAND" ]; then
|
|
157
230
|
echo "Using custom E2E command: $E2E_COMMAND"
|
|
158
|
-
|
|
231
|
+
|
|
232
|
+
# If E2E_COMMAND contains "cypress run", inject --env args
|
|
233
|
+
if echo "$E2E_COMMAND" | grep -q "cypress run"; then
|
|
234
|
+
MODIFIED_COMMAND=$(echo "$E2E_COMMAND" | sed "s/cypress run/cypress run --env '${FINAL_ENV_ARGS}'/")
|
|
235
|
+
echo "Modified command with env args: $MODIFIED_COMMAND"
|
|
236
|
+
eval "$MODIFIED_COMMAND" 2>&1 | tee ${RESULTS_DIR}/logs.txt
|
|
237
|
+
else
|
|
238
|
+
# For npm scripts like "npm run test:cy", env vars are already exported with CYPRESS_ prefix
|
|
239
|
+
echo "Note: Custom command doesn't contain 'cypress run'. CYPRESS_* env vars exported as fallback."
|
|
240
|
+
eval "$E2E_COMMAND" 2>&1 | tee ${RESULTS_DIR}/logs.txt
|
|
241
|
+
fi
|
|
159
242
|
else
|
|
160
243
|
echo "Using default: npx cypress run"
|
|
161
|
-
echo "Final grep args: $CYPRESS_GREP_ARGS"
|
|
162
244
|
eval "npx cypress run \
|
|
163
245
|
--headless \
|
|
164
246
|
--browser chrome \
|
|
165
247
|
--reporter mochawesome \
|
|
166
248
|
--reporter-options 'reportDir=${MOCHAWESOME_DIR},overwrite=false,html=false,json=true,timestamp=mmddyyyy_HHMMss' \
|
|
167
|
-
--env
|
|
168
|
-
$CYPRESS_GREP_ARGS" 2>&1 | tee ${RESULTS_DIR}/logs.txt
|
|
249
|
+
--env '${FINAL_ENV_ARGS}'" 2>&1 | tee ${RESULTS_DIR}/logs.txt
|
|
169
250
|
fi
|
|
170
251
|
|
|
171
252
|
EXIT_CODE=${PIPESTATUS[0]}
|