Skip to content

Commit c74b94b

Browse files
committed
Attempt to fix browser logs + debug for rancher logs
1 parent 7d1d933 commit c74b94b

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

.github/workflows/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ jobs:
139139
cp -r cypress/screenshots artifacts 2>/dev/null || :
140140
cp -r cypress/videos artifacts 2>/dev/null || :
141141
cp -r cypress/reports/* artifacts || :
142+
ls -la ${{ env.E2E_RANCHER_LOG }}
142143
cp ${{ env.E2E_RANCHER_LOG }} artifacts/rancher.logs 2>/dev/null || :
144+
ls -la browser-logs/out.html
143145
cp browser-logs/out.html artifacts/browser-logs.html 2>/dev/null || :
144146
145147
- name: Upload Artifacts

cypress/base-config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { defineConfig } from 'cypress';
33
import websocketTasks from './support/utils/webSocket-utils';
44
import path from 'path';
5+
import fs from 'fs';
56
const { removeDirectory } = require('cypress-delete-downloads-folder');
67
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
78

@@ -168,6 +169,32 @@ const baseConfig = defineConfig({
168169

169170
// Done this way to catch errors when there are no tests run
170171
on('after:run', async() => {
172+
// We need to wait for the cypress-terminal-report plugin to finish writing the browser logs
173+
// There's a race condition where the mochawesome afterRunHook can finish and exit the process
174+
// before the terminal report is written.
175+
const logFile = path.join(config.projectRoot, 'browser-logs', 'out.html');
176+
const timeout = 5000; // 5 seconds
177+
const interval = 100; // 100 ms
178+
let waited = 0;
179+
const fileExists = () => {
180+
try {
181+
return fs.existsSync(logFile);
182+
} catch (e) {
183+
return false;
184+
}
185+
};
186+
187+
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
188+
189+
while (waited < timeout && !fileExists()) {
190+
await wait(interval);
191+
waited += interval;
192+
}
193+
194+
if (!fileExists()) {
195+
console.warn(`\n\n⚠️ Browser log file not found at ${ logFile } after ${ timeout }ms. Proceeding without it.\n\n`);
196+
}
197+
171198
try {
172199
await afterRunHook();
173200
} catch (error) {

0 commit comments

Comments
 (0)