Skip to content

Commit

Permalink
Make module server configurable (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebeby authored Jul 20, 2021
1 parent ab495ac commit 248376d
Show file tree
Hide file tree
Showing 24 changed files with 828 additions and 110 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-dingos-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pleasantest': minor
---

Make module server configurable
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
.cache
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
.cache
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,28 @@ Call Signatures:
- `withBrowser.headed(testFn: (context: PleasantestContext) => Promise<void>)`
- `withBrowser.headed(opts: WithBrowserOpts, testFn: (context: PleasantestContext) => Promise<void>)`

`WithBrowserOpts`:
`WithBrowserOpts` (all properties are optional):

- `headless`: `boolean`, default `true`: Whether to open a headless (not visible) browser. If you use the `withBrowser.headed` chain, that will override the value of `headless`.
- `device`: Device Object [described here](https://pptr.dev/#?product=Puppeteer&version=v10.1.0&show=api-pageemulateoptions).
- `moduleServer`: Module Server options object (all properties are optional). They will be applied to files imported through [`utils.runJS`](#pleasantestutilsrunjscode-string-promisevoid) or [`utils.loadJS`](#pleasantestutilsloadjsjspath-string-promisevoid).
- `plugins`: Array of Rollup, Vite, or WMR plugins to add.
- `envVars`: Object with string keys and string values for environment variables to pass in as `import.meta.env.*` / `process.env.*`
- `esbuild`: [`TransformOptions`](https://esbuild.github.io/api/#transform-api) | `false`: Options to pass to esbuild. Set to false to disable esbuild.

You can configure the default options (applied to all tests in current file) by using the `configureDefaults` method. If you want defaults to apply to all files, Create a [test setup file](https://jestjs.io/docs/configuration#setupfilesafterenv-array) and call `configureDefaults` there:

```js
import { configureDefaults } from 'pleasantest'

configureDefaults({
device: /* ... */,
moduleServer: {
/* ... */
},
/* ... */
})
```

By default, `withBrowser` will launch a headless Chromium browser. You can tell it to instead launch a headed (visible) browser by chaining `.headed`:

Expand Down
Loading

0 comments on commit 248376d

Please sign in to comment.