Skip to content

Jest's runInBand not compatible with incognito context #585

Description

@opyate

From my package.json:

{
  "scripts": {
    "test": "SLOWMO=50 jest --runInBand",
    "testfast": "jest"
  },
  "dependencies": {
    "@types/jest": "^29.5.12",
    "@types/jest-environment-puppeteer": "^5.0.6",
    "@types/node": "^20.14.10",
    "@types/puppeteer": "^7.0.4",
    "@types/supertest": "^6.0.2",
    "dotenv": "^16.4.5",
    "jest": "^29.7.0",
    "jest-puppeteer": "^10.0.1",
    "puppeteer": "^22.13.0",
    "supertest": "^7.0.0",
    "ts-jest": "^29.2.2"
  }
}

Locally, I use test, and in CI environment I use testci. As tests are executed serially locally, I still expect cookies to be cleared for each test as I'm using an incognito context, but they aren't.

I've tried resetting the page in-between each test:

  beforeEach(async () => {
    jestPuppeteer.resetPage();
  });

But then I just get an error:

Error: Protocol error: Connection closed. Most likely the page has been closed.

I also thought about calling page.close() at the end of each test, then:

  beforeEach(async () => {
    page.isClosed() && (page = await browser.newPage());
  });

...but page can't be re-assigned, as it's a const.

Any suggestions would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions