Skip to content

Commit

Permalink
put back the setTimeout mock
Browse files Browse the repository at this point in the history
And just disable it for login checks
  • Loading branch information
Cass Fridkin committed Mar 29, 2022
1 parent ba16694 commit 7aa4794
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/wrangler/src/__tests__/helpers/mock-oauth-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const mockOpenInBrowser = async (url: string, ..._args: unknown[]) => {
const queryParams = toQueryParams(oauthGrantResponse, searchParams);
// don't await this -- it will block the rest of the login flow
fetch(`${searchParams.get("redirect_uri")}?${queryParams}`).catch((e) => {
fail(e);
throw new Error(
"Failed to send OAuth Grant to wrangler, maybe the server was closed?",
e as Error
);
});
return new ChildProcess();
}
Expand Down
18 changes: 18 additions & 0 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,26 @@ describe("publish", () => {
const std = mockConsoleMethods();
const { mockGrantAccessToken, mockGrantAuthorization } = mockOAuthFlow();

beforeEach(() => {
// @ts-expect-error we're using a very simple setTimeout mock here
jest.spyOn(global, "setTimeout").mockImplementation((fn, _period) => {
setImmediate(fn);
});
});

afterEach(() => {
unsetAllMocks();
unsetMockFetchKVGetValues();
});

describe("authentication", () => {
mockApiToken({ apiToken: null });
beforeEach(() => {
// @ts-expect-error disable the mock we'd setup earlier
// or else our server won't bother listening for oauth requests
// and will timeout and fail
global.setTimeout.mockRestore();
});

it("drops a user into the login flow if they're unauthenticated", async () => {
writeWranglerToml();
Expand Down Expand Up @@ -1972,6 +1985,11 @@ export default{
});

describe("custom builds", () => {
beforeEach(() => {
// @ts-expect-error disable the mock we'd setup earlier
// or else custom builds will timeout immediately
global.setTimeout.mockRestore();
});
it("should run a custom build before publishing", async () => {
writeWranglerToml({
build: {
Expand Down

0 comments on commit 7aa4794

Please sign in to comment.