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): fix exports issues #547

Merged
merged 2 commits into from
Mar 24, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "CI"
on:
pull_request:
branches: [main]
push:
branches:
- master
branches: [main]

jobs:
Test:
Expand Down
14 changes: 14 additions & 0 deletions packages/jest-environment-puppeteer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ async function getConfig() {
module.exports = getConfig();
```

## Create custom environment

It is possible to create a custom environment from the Jest Puppeteer's one. It is not different from creating a custom environment from "jest-environment-node". See [Jest `testEnvironment` documentation](https://jestjs.io/docs/configuration#testenvironment-string) to learn more about it.

```js
// my-custom-environment
const JestPuppeteerEnvironment =
require("jest-environment-puppeteer").TestEnvironment;

class CustomEnvironment extends JestPuppeteerEnvironment {
// Implement your own environment
}
```

## Inspiration

Thanks to Fumihiro Xue for his great [Jest example](https://github.com/xfumihiro/jest-puppeteer-example).
3 changes: 1 addition & 2 deletions packages/jest-environment-puppeteer/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default [
file: "dist/index.js",
format: "cjs",
interop: "compat",
exports: "default",
},
plugins: [swcPlugin],
}),
Expand All @@ -44,7 +43,7 @@ export default [
output: {
file: "dist/index.d.ts",
format: "es",
exports: "default",
interop: "compat",
},
}),
];
13 changes: 0 additions & 13 deletions packages/jest-environment-puppeteer/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ type StrictGlobal = {

export type JestPuppeteerGlobal = Required<StrictGlobal>;

declare global {
// @ts-ignore
var browser: Global["browser"];
// @ts-ignore
var page: Global["page"];
// @ts-ignore
var context: Global["context"];
// @ts-ignore
var puppeteerConfig: Global["puppeteerConfig"];
// @ts-ignore
var jestPuppeteer: Global["jestPuppeteer"];
}

const testTimeoutSymbol = Symbol.for("TEST_TIMEOUT_SYMBOL");

const handlePageError = (error: Error) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-environment-puppeteer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { PuppeteerEnvironment as TestEnvironment } from "./env";
export { PuppeteerEnvironment as default } from "./env";

export type { JestPuppeteerGlobal } from "./env";
export type { JestPuppeteerConfig } from "./config";
7 changes: 1 addition & 6 deletions packages/jest-puppeteer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import type { JestPuppeteerGlobal } from "jest-environment-puppeteer";

declare global {
// @ts-ignore
var browser: JestPuppeteerGlobal["browser"];
// @ts-ignore
var page: JestPuppeteerGlobal["page"];
// @ts-ignore
var context: JestPuppeteerGlobal["context"];
// @ts-ignore
var puppeteerConfig: JestPuppeteerGlobal["puppeteerConfig"];
// @ts-ignore
var jestPuppeteer: JestPuppeteerGlobal["jestPuppeteer"];
}

module.exports = {
export = {
globalSetup: require.resolve("jest-environment-puppeteer/setup"),
globalTeardown: require.resolve("jest-environment-puppeteer/teardown"),
testEnvironment: require.resolve("jest-environment-puppeteer"),
Expand Down