Skip to content

Commit

Permalink
fix(types): fix exports issues
Browse files Browse the repository at this point in the history
Fix #545
Fix #546

jest-environment-puppeteer now exports `TestEnvironment`. Since custom environment creation was not public, it is not considered as a breaking change.
  • Loading branch information
gregberge committed Mar 24, 2023
1 parent 3c92c6b commit 3ea33a7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
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
3 changes: 2 additions & 1 deletion packages/jest-environment-puppeteer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { PuppeteerEnvironment as default } from "./env";
export { PuppeteerEnvironment as TestEnvironment } 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

0 comments on commit 3ea33a7

Please sign in to comment.