Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix types resolution for expect-puppeteer #599

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading