mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 08:53:36 +00:00
fix: prevent response disposal race condition in E2E test
Wrap route.fetch() and response.json() in try/catch blocks to handle cases where the response is disposed before it can be accessed. Falls back to route.continue() to let the original request proceed normally. This fixes the intermittent "Response has been disposed" error in open-existing-project.spec.ts that occurs due to timing issues in CI.
This commit is contained in:
@@ -84,18 +84,24 @@ test.describe('Open Project', () => {
|
|||||||
// Intercept settings API BEFORE any navigation to prevent restoring a currentProject
|
// Intercept settings API BEFORE any navigation to prevent restoring a currentProject
|
||||||
// AND inject our test project into the projects list
|
// AND inject our test project into the projects list
|
||||||
await page.route('**/api/settings/global', async (route) => {
|
await page.route('**/api/settings/global', async (route) => {
|
||||||
const response = await route.fetch();
|
let response;
|
||||||
// Immediately consume the body to prevent disposal issues
|
try {
|
||||||
const bodyPromise = response.body();
|
response = await route.fetch();
|
||||||
const status = response.status();
|
} catch {
|
||||||
const headers = response.headers();
|
// If fetch fails, continue with original request
|
||||||
const body = await bodyPromise;
|
await route.continue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let json;
|
let json;
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(body.toString());
|
json = await response.json();
|
||||||
} catch {
|
} catch {
|
||||||
json = {};
|
// If response is disposed, continue with original request
|
||||||
|
await route.continue();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.settings) {
|
if (json.settings) {
|
||||||
// Remove currentProjectId to prevent restoring a project
|
// Remove currentProjectId to prevent restoring a project
|
||||||
json.settings.currentProjectId = null;
|
json.settings.currentProjectId = null;
|
||||||
@@ -115,11 +121,7 @@ test.describe('Open Project', () => {
|
|||||||
json.settings.projects = [testProject, ...existingProjects];
|
json.settings.projects = [testProject, ...existingProjects];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await route.fulfill({
|
await route.fulfill({ response, json });
|
||||||
status: status,
|
|
||||||
headers: headers,
|
|
||||||
json,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now navigate to the app
|
// Now navigate to the app
|
||||||
|
|||||||
Reference in New Issue
Block a user