Fix flakey test (#1178)

This commit is contained in:
Tommaso Sciortino 2025-06-18 08:34:22 -07:00 committed by GitHub
parent 9b34762d97
commit cd03d96b34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -67,11 +67,18 @@ describe('oauth2', () => {
typeof http.IncomingMessage,
typeof http.ServerResponse
>;
let serverListeningCallback: (value: unknown) => void;
const serverListeningPromise = new Promise(
(resolve) => (serverListeningCallback = resolve),
);
const mockHttpServer = {
listen: vi.fn((port: number, callback?: () => void) => {
if (callback) {
callback();
}
serverListeningCallback(undefined);
}),
close: vi.fn((callback?: () => void) => {
if (callback) {
@ -91,8 +98,8 @@ describe('oauth2', () => {
const clientPromise = getOauthClient();
// Wait for the server to be created
await new Promise((resolve) => setTimeout(resolve, 0));
// wait for server to start listening.
await serverListeningPromise;
const mockReq = {
url: `/oauth2callback?code=${mockCode}&state=${mockState}`,