Skip to content

Commit 248376d

Browse files
authored
Make module server configurable (#163)
1 parent ab495ac commit 248376d

24 files changed

Lines changed: 828 additions & 110 deletions

.changeset/quick-dingos-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pleasantest': minor
3+
---
4+
5+
Make module server configurable

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist
2+
.cache

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist
2+
.cache

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,28 @@ Call Signatures:
345345
- `withBrowser.headed(testFn: (context: PleasantestContext) => Promise<void>)`
346346
- `withBrowser.headed(opts: WithBrowserOpts, testFn: (context: PleasantestContext) => Promise<void>)`
347347

348-
`WithBrowserOpts`:
348+
`WithBrowserOpts` (all properties are optional):
349349

350350
- `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`.
351351
- `device`: Device Object [described here](https://pptr.dev/#?product=Puppeteer&version=v10.1.0&show=api-pageemulateoptions).
352+
- `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).
353+
- `plugins`: Array of Rollup, Vite, or WMR plugins to add.
354+
- `envVars`: Object with string keys and string values for environment variables to pass in as `import.meta.env.*` / `process.env.*`
355+
- `esbuild`: [`TransformOptions`](https://esbuild.github.io/api/#transform-api) | `false`: Options to pass to esbuild. Set to false to disable esbuild.
356+
357+
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:
358+
359+
```js
360+
import { configureDefaults } from 'pleasantest'
361+
362+
configureDefaults({
363+
device: /* ... */,
364+
moduleServer: {
365+
/* ... */
366+
},
367+
/* ... */
368+
})
369+
```
352370

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

0 commit comments

Comments
 (0)