prisma-labs / konn

MIT License
89 stars 4 forks source link

Should `providers.page()` really create a new context? #23

Closed KATT closed 3 years ago

KATT commented 3 years ago

Perceived Problem

I was expecting to reuse the same auth and only do auth once in beforeAll (speeds tests up a lot).

https://github.com/prisma-labs/kont/blob/b3cd265545ea39e4c0d908be5b2e9b84787f832f/src/Providers/Page/Page.ts#L62-L66

Ideas / Proposed Solution(s)

Further context

My draft PR with adding kont with our existing jest/Playwright setup: https://github.com/calendso/calendso/pull/931

I've written my own loginProvider and trying to use this code:


  const ctx = kont()
    .useBeforeAll(providers.browser())
    .useBeforeEach(providers.page())
    .useBeforeAll(loginProvider("pro") // <-- I only wanna do this once
    .beforeEach(async ({ page }) => {
      await page.goto("http://localhost:3000/myPage"); // <-- the loged in page i wanna test in this test - i expect to be logged in here
    })
    .done();
KATT commented 3 years ago

You are obviously also using Playwright + Jest, but I'm getting a feeling our setups look a bit differently. Would be amazing to see how you use it, either if you explained a bit more in detail or maybe did an examples/react-app 🙏


Edit - on further inspection, it doesn't really seem to to work to first open a page in a BrowserContext to login and then simply doing a .newPage() and assume being logged in..

KATT commented 3 years ago

Closing this - did a workaround with a custom useBeforeEach(loginProvider(...))

jasonkuhrt commented 3 years ago

After login it is necessary to save the browser context for later reuse.

Ideas welcome on how we can improve the standard provider library.

But yeah it is trivial to roll your own too.