add abort signals for tests
This commit is contained in:
parent
571a86127a
commit
47548708e6
4 changed files with 86 additions and 21 deletions
|
|
@ -12,9 +12,16 @@ const UpdateNotification: React.FC<UpdateNotificationProps> = ({ isRemoteMode =
|
|||
const [currentVersion] = useState(getVersion());
|
||||
|
||||
useEffect(() => {
|
||||
// Skip update check in test environment
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
return;
|
||||
}
|
||||
|
||||
const abortController = new AbortController();
|
||||
|
||||
const checkForUpdate = async () => {
|
||||
try {
|
||||
const latest = await getLatestVersion();
|
||||
const latest = await getLatestVersion(abortController.signal);
|
||||
if (latest) {
|
||||
setLatestVersion(latest);
|
||||
const comparison = compareVersions(currentVersion, latest);
|
||||
|
|
@ -22,12 +29,19 @@ const UpdateNotification: React.FC<UpdateNotificationProps> = ({ isRemoteMode =
|
|||
}
|
||||
} catch (error) {
|
||||
// Silently fail - we don't want to interrupt the user experience
|
||||
console.debug("Failed to check for updates:", error);
|
||||
if (error instanceof Error && error.name !== 'AbortError') {
|
||||
console.debug("Failed to check for updates:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Check for updates but don't block
|
||||
checkForUpdate();
|
||||
|
||||
// Cleanup function to abort the request when component unmounts
|
||||
return () => {
|
||||
abortController.abort();
|
||||
};
|
||||
}, [currentVersion]);
|
||||
|
||||
if (!updateAvailable) {
|
||||
|
|
|
|||
|
|
@ -57,8 +57,9 @@ export function runTest(
|
|||
serverSetup(server);
|
||||
}
|
||||
|
||||
let renderResult: RenderResult | null = null;
|
||||
try {
|
||||
const renderResult = render(
|
||||
renderResult = render(
|
||||
React.createElement(TUIChat, { ...createProps({ remoteUrl, ...props }) })
|
||||
) as RenderResult;
|
||||
|
||||
|
|
@ -69,18 +70,31 @@ export function runTest(
|
|||
remoteUrl,
|
||||
});
|
||||
} finally {
|
||||
// Clean up render instance first
|
||||
if (renderResult) {
|
||||
renderResult.unmount();
|
||||
}
|
||||
// Then stop the server
|
||||
await server.stop();
|
||||
}
|
||||
} else {
|
||||
// Normal mode
|
||||
const renderResult = render(
|
||||
React.createElement(TUIChat, { ...createProps(props) })
|
||||
) as RenderResult;
|
||||
let renderResult: RenderResult | null = null;
|
||||
try {
|
||||
renderResult = render(
|
||||
React.createElement(TUIChat, { ...createProps(props) })
|
||||
) as RenderResult;
|
||||
|
||||
await testFn({
|
||||
mode: "normal",
|
||||
renderResult,
|
||||
});
|
||||
await testFn({
|
||||
mode: "normal",
|
||||
renderResult,
|
||||
});
|
||||
} finally {
|
||||
// Clean up render instance
|
||||
if (renderResult) {
|
||||
renderResult.unmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -126,8 +140,9 @@ export function runTestSuite(
|
|||
options.serverSetup(server);
|
||||
}
|
||||
|
||||
let renderResult: RenderResult | null = null;
|
||||
try {
|
||||
const renderResult = render(
|
||||
renderResult = render(
|
||||
React.createElement(TUIChat, { ...createProps({ remoteUrl, ...options.props }) })
|
||||
) as RenderResult;
|
||||
|
||||
|
|
@ -138,18 +153,31 @@ export function runTestSuite(
|
|||
remoteUrl,
|
||||
});
|
||||
} finally {
|
||||
// Clean up render instance first
|
||||
if (renderResult) {
|
||||
renderResult.unmount();
|
||||
}
|
||||
// Then stop the server
|
||||
await server.stop();
|
||||
}
|
||||
} else {
|
||||
// Normal mode
|
||||
const renderResult = render(
|
||||
React.createElement(TUIChat, { ...createProps(options.props) })
|
||||
) as RenderResult;
|
||||
let renderResult: RenderResult | null = null;
|
||||
try {
|
||||
renderResult = render(
|
||||
React.createElement(TUIChat, { ...createProps(options.props) })
|
||||
) as RenderResult;
|
||||
|
||||
await testFn({
|
||||
mode: "normal",
|
||||
renderResult,
|
||||
});
|
||||
await testFn({
|
||||
mode: "normal",
|
||||
renderResult,
|
||||
});
|
||||
} finally {
|
||||
// Clean up render instance
|
||||
if (renderResult) {
|
||||
renderResult.unmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export class MockRemoteServer {
|
|||
responseInProgress: false,
|
||||
};
|
||||
private onMessageCallbacks: Array<(message: string) => void> = [];
|
||||
private pendingTimeouts: Set<NodeJS.Timeout> = new Set();
|
||||
|
||||
constructor() {}
|
||||
|
||||
|
|
@ -84,9 +85,11 @@ export class MockRemoteServer {
|
|||
});
|
||||
|
||||
// Notify callbacks after state is set up
|
||||
setTimeout(() => {
|
||||
const timeout = setTimeout(() => {
|
||||
this.onMessageCallbacks.forEach(cb => cb(message));
|
||||
this.pendingTimeouts.delete(timeout);
|
||||
}, 10);
|
||||
this.pendingTimeouts.add(timeout);
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ success: true }));
|
||||
|
|
@ -123,6 +126,13 @@ export class MockRemoteServer {
|
|||
this.streamInterval = null;
|
||||
}
|
||||
|
||||
// Clear any pending timeouts
|
||||
this.pendingTimeouts.forEach(timeout => clearTimeout(timeout));
|
||||
this.pendingTimeouts.clear();
|
||||
|
||||
// Clear callbacks to prevent memory leaks
|
||||
this.onMessageCallbacks = [];
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (this.server) {
|
||||
// Force close all connections
|
||||
|
|
@ -195,6 +205,14 @@ export class MockRemoteServer {
|
|||
}
|
||||
|
||||
reset() {
|
||||
// Clear any intervals/timeouts before resetting
|
||||
if (this.streamInterval) {
|
||||
clearInterval(this.streamInterval);
|
||||
this.streamInterval = null;
|
||||
}
|
||||
this.pendingTimeouts.forEach(timeout => clearTimeout(timeout));
|
||||
this.pendingTimeouts.clear();
|
||||
|
||||
this.state = {
|
||||
messages: [],
|
||||
isResponding: false,
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ export function getVersion(): string {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getLatestVersion(): Promise<string | null> {
|
||||
export async function getLatestVersion(signal?: AbortSignal): Promise<string | null> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
"https://registry.npmjs.org/@continuedev/cli/latest"
|
||||
"https://registry.npmjs.org/@continuedev/cli/latest",
|
||||
{ signal }
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
|
|
@ -26,6 +27,10 @@ export async function getLatestVersion(): Promise<string | null> {
|
|||
const data = await response.json();
|
||||
return data.version;
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === 'AbortError') {
|
||||
// Request was aborted, don't log
|
||||
return null;
|
||||
}
|
||||
console.warn("Warning: Could not fetch latest version from npm registry");
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue