From a234d60b7cb54c75bf9cd0be7808b8183280a65e Mon Sep 17 00:00:00 2001 From: Gadi Cohen Date: Fri, 4 Oct 2024 13:15:19 +0100 Subject: [PATCH] Revert "chore(tests): temporarily disable getCrumb tests on CI" This reverts commit 4827e3f3e79711cc4116c51c3734f165d65a3e38. --- src/lib/getCrumb.spec.ts | 143 +++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 75 deletions(-) diff --git a/src/lib/getCrumb.spec.ts b/src/lib/getCrumb.spec.ts index 36e20a90..138ea070 100644 --- a/src/lib/getCrumb.spec.ts +++ b/src/lib/getCrumb.spec.ts @@ -17,77 +17,70 @@ describe("getCrumb", () => { }); afterAll(consoleRestore); - // XXX TODO failing on CI why?? seems to not be using cached copy just for this file? - if (!process.env.CI) - describe("_getCrumb", () => { - it("finds crumb in context", async () => { - const fetch = await env.fetchDevel(); + describe("_getCrumb", () => { + it("finds crumb in context", async () => { + const fetch = await env.fetchDevel(); - const crumb = await _getCrumb( - new ExtendedCookieJar(), - fetch, - { devel: true }, - logger, - "https://finance.yahoo.com/quote/AAPL", - "getCrumb-quote-AAPL.json", - true, - ); - expect(crumb).toBe("mloUP8q7ZPH"); - }); + const crumb = await _getCrumb( + new ExtendedCookieJar(), + fetch, + { devel: true }, + logger, + "https://finance.yahoo.com/quote/AAPL", + "getCrumb-quote-AAPL.json", + true, + ); + expect(crumb).toBe("mloUP8q7ZPH"); + }); - it("ditto with shared cookie jar (don't use it for other tests)", async () => { - const fetch = await env.fetchDevel(); + it("ditto with shared cookie jar (don't use it for other tests)", async () => { + const fetch = await env.fetchDevel(); - const crumb = await _getCrumb( - cookieJar, - fetch, - { devel: true }, - logger, - ); - expect(crumb).toBe("mloUP8q7ZPH"); - }); + const crumb = await _getCrumb(cookieJar, fetch, { devel: true }, logger); + expect(crumb).toBe("mloUP8q7ZPH"); + }); - it("re-uses cookie", async () => { - const fetch = await env.fetchDevel(); + it("re-uses cookie", async () => { + const fetch = await env.fetchDevel(); - let crumb = await _getCrumb( - cookieJar, - fetch, - { devel: true }, - logger, - "https://finance.yahoo.com/quote/AAPL", - ); - expect(crumb).toBe("mloUP8q7ZPH"); + let crumb = await _getCrumb( + cookieJar, + fetch, + { devel: true }, + logger, + "https://finance.yahoo.com/quote/AAPL", + ); + expect(crumb).toBe("mloUP8q7ZPH"); - // TODO, at tests to see how many times fetch was called, etc. + // TODO, at tests to see how many times fetch was called, etc. - crumb = await _getCrumb( - cookieJar, + crumb = await _getCrumb( + cookieJar, + fetch, + { devel: true }, + logger, + "https://finance.yahoo.com/quote/AAPL", + ); + expect(crumb).toBe("mloUP8q7ZPH"); + }); + + it("throws on no cookies", async () => { + const fetch = await env.fetchDevel(); + + await expect(() => + _getCrumb( + new ExtendedCookieJar(), fetch, { devel: true }, logger, "https://finance.yahoo.com/quote/AAPL", - ); - expect(crumb).toBe("mloUP8q7ZPH"); - }); - - it("throws on no cookies", async () => { - const fetch = await env.fetchDevel(); - - await expect(() => - _getCrumb( - new ExtendedCookieJar(), - fetch, - { devel: true }, - logger, - "https://finance.yahoo.com/quote/AAPL", - "getCrumb-quote-AAPL-no-cookies.fake.json", - true, - ), - ).rejects.toThrowError(/No set-cookie/); - }); - - /* + "getCrumb-quote-AAPL-no-cookies.fake.json", + true, + ), + ).rejects.toThrowError(/No set-cookie/); + }); + + /* test for commented out code. it("throws on no context", async () => { const fetch = await env.fetchDevel(); @@ -138,23 +131,23 @@ describe("getCrumb", () => { }); */ - it("redirect https://guce.yahoo.com/consent?brandType=nonEu", async () => { - // consoleRestore(); - const fetch = await env.fetchDevel(); + it("redirect https://guce.yahoo.com/consent?brandType=nonEu", async () => { + // consoleRestore(); + const fetch = await env.fetchDevel(); - const crumb = await _getCrumb( - new ExtendedCookieJar(), - fetch, - { devel: true }, - logger, - "https://finance.yahoo.com/quote/AAPL", - "getCrumb-quote-AAPL-pre-consent-VPN-UK.json", - true, - ); - expect(crumb).toBe("mloUP8q7ZPH"); - // consoleSilent(); - }); + const crumb = await _getCrumb( + new ExtendedCookieJar(), + fetch, + { devel: true }, + logger, + "https://finance.yahoo.com/quote/AAPL", + "getCrumb-quote-AAPL-pre-consent-VPN-UK.json", + true, + ); + expect(crumb).toBe("mloUP8q7ZPH"); + // consoleSilent(); }); + }); describe("getCrumb", () => { it("works", async () => {