Skip to content

Commit

Permalink
fix: fix types resolution for expect-puppeteer (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
mulekick authored Oct 10, 2024
1 parent ced391e commit 37e3271
Show file tree
Hide file tree
Showing 23 changed files with 2,804 additions and 1,041 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function getConfig() {
module.exports = getConfig();
```

## Recipes
## <a name="recipes"></a>Recipes

### Enhance testing with `expect-puppeteer` lib

Expand Down Expand Up @@ -490,6 +490,30 @@ beforeEach(async () => {

TypeScript is natively supported from v8.0.0, for previous versions, you have to use [community-provided types](https://github.com/DefinitelyTyped/DefinitelyTyped).

Note though that it still requires installation of the [type definitions for jest](https://www.npmjs.com/package/@types/jest) :

```bash
npm install --save-dev @types/jest
```

Once setup, import the modules to enable types resolution for the exposed globals, then write your test logic [the same way you would in Javascript](#recipes).

```ts
// import globals
import "jest-puppeteer";
import "expect-puppeteer";

describe("Google", (): void => {
beforeAll(async (): Promise<void> => {
await page.goto("https://google.com");
});

it('should display "google" text on page', async (): Promise<void> => {
await expect(page).toMatchTextContent("google");
});
});
```

### CI Timeout

Most Continuous Integration (CI) platforms restrict the number of threads you can use. If you run multiple test suites, the tests may timeout due to Jest attempting to run Puppeteer in parallel, and the CI platform being unable to process all parallel jobs in time.
Expand Down
3,179 changes: 2,396 additions & 783 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"packages/*"
],
"scripts": {
"typecheck": "npx tsc && echo 'type checking was successful'",
"build": "cross-env NODE_ENV=production lerna run build",
"dev": "lerna watch -- lerna run build --scope=\\$LERNA_PACKAGE_NAME",
"format": "prettier --write .",
Expand Down
6 changes: 5 additions & 1 deletion packages/expect-puppeteer/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getDefaultOptions, setDefaultOptions } from ".";
import { getDefaultOptions, setDefaultOptions } from "expect-puppeteer";

// import globals
import "jest-puppeteer";
import "expect-puppeteer";

expect.addSnapshotSerializer({
print: () => "hello",
Expand Down
Loading

0 comments on commit 37e3271

Please sign in to comment.