Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stagas/run-in-client
runs a single function in the client using puppeteer and esbuild
https://github.com/stagas/run-in-client
esbuild function puppeteer test testing typescript
Last synced: about 1 month ago
JSON representation
runs a single function in the client using puppeteer and esbuild
- Host: GitHub
- URL: https://github.com/stagas/run-in-client
- Owner: stagas
- Created: 2021-12-22T19:30:09.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-04T11:35:39.000Z (almost 3 years ago)
- Last Synced: 2024-12-16T20:33:13.369Z (about 1 month ago)
- Topics: esbuild, function, puppeteer, test, testing, typescript
- Language: TypeScript
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
run-in-client
runs a single function in the client using puppeteer and esbuild
🔧 Install
· 🧩 Example
· 📜 API docs
· 🔥 Releases
· 💪🏼 Contribute
· 🖐️ Help***
## Install
```sh
$ npm i run-in-client
```## API
#### Table of Contents
* [runInClient](#runinclient)
* [Parameters](#parameters)### runInClient
[src/index.ts:43-92](https://github.com/stagas/run-in-client/blob/73a6c003203299a30c1469173e1a00bcd43a986d/src/index.ts#L43-L92 "Source code on GitHub")
Creates a static server with esbuild transforms, creates a puppeteer instance,
executes a single function, returns its result and tears down.```ts
const setup = {
root: path.resolve(path.join(__dirname, '..')),
include: `
import { someModule } from './some-module.ts' // note we can import .ts files
window.someModule = someModule
`,
}// this is how our function below gets intellisense
declare window: WindowOrWorkerGlobalScope & { someModule: typeof someModule }// the function runs in the client, as such doesn't have access to the scope!
const result = await runInClient(setup, async () => {
const output = await window.someModule.doSomething()
return output
})
// => `result` is now `output`
```#### Parameters
* `setup` **ClientSetup** A setup object
* `setup.root` The static root directory to serve and esbuild transform files from
* `setup.include` JavaScript to run before the function, like import statements
* `setup.buildOptions` Esbuild build options (@see )
* `setup.launchOptions` Puppeteer launch options (@see )
* `fn` **function (): any** The function to run. This will be passed in `page.evaluate(fn)`Returns **any** The result value of `page.evaluate(fn)`
## Contribute
[Fork](https://github.com/stagas/run-in-client/fork) or
[edit](https://github.dev/stagas/run-in-client) and submit a PR.All contributions are welcome!
## License
MIT © 2021
[stagas](https://github.com/stagas)