Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Timeout errors #46

Closed
thernstig opened this issue May 4, 2020 · 7 comments
Closed

Timeout errors #46

thernstig opened this issue May 4, 2020 · 7 comments

Comments

@thernstig
Copy link

For reference, see microsoft/playwright#2031

This piece of code will not work when running inside Jest:

const playwright = require('playwright');
try {
  await page.waitForSelector('.foo');
} catch (e) {
  if (e instanceof playwright.errors.TimeoutError) {
    // Do something if this is a timeout.
  }
  } else {
    console.log(err);
  }
}

It is possible that the TimeoutError is a different instance because Jest test cases is run inside a vm context, whereas PlaywrightRunnerE2E runs in Node.js.

This does work:

if (err.name === 'TimeoutError')

Note: Have not tested this with playwright-runner, but just assuming this is a problem here as well since it was with jest-playwright.

@mxschmitt
Copy link
Member

Would be awesome to fix this upstream in Jest. Simen has already a PR open to fix that.
jestjs/jest#5995
or
jestjs/jest#8220
cc @SimenB

@SimenB
Copy link

SimenB commented May 4, 2020

Agreed, I haven't been able to make the faked instanceof check work though. My current approach is hoping nodejs/node#31852 is fixed

@thernstig
Copy link
Author

Close this until that is in place?

@JoelEinbinder
Copy link
Contributor

This shouldn't be a problem with the e2e runner, because we don't use vm anywhere.

@thernstig
Copy link
Author

So e2e runner is not using Jest to run test cases?

@JoelEinbinder
Copy link
Contributor

So e2e runner is not using Jest to run test cases?

Correct. The e2e test runner runs tests in a single node process. We can do this because all of the important code being tested is in the website running in the browser. The code in node is just the small bits used to drive the test.

@thernstig
Copy link
Author

thernstig commented May 7, 2020

Ok - I will have to look into the playwright-runner e2e test runner later. Maybe I misunderstand, but I am using Jest for much more such as reporters, being able to customize runner options and many, many other of Jest's features (expect statements) etc. And I want to use Jest to run them in parallell, taking the caching. performance (run failed first) etc. into account.

Edit: The examples in the README clearly use Jest syntax, so I suppose I've just not familiarized myself yet with the implementation details.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants