You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Transparently bundles your input files and runs them in a headless Chromium browser. Great for running tests in an actual browser!
7
+
Run any JavaScript or TypeScript code in a headless browser using puppeteer and pipe it's output back to your terminal 🔥
8
+
9
+
Transparently bundles input files, so you can use `require()` and ES module imports. You can even simulate connectivity issues and serve static files. Great for testing client-side code in an actual browser!
6
10
7
11
How does it relate to [Karma](https://karma-runner.github.io)? It's everything that Karma is not: It's small, it's fast and trivial to set up.
8
12
@@ -19,28 +23,25 @@ How does it relate to [Karma](https://karma-runner.github.io)? It's everything t
19
23
npm install puppet-run
20
24
```
21
25
22
-
We can use npm's [npx tool](https://blog.npmjs.org/post/162869356040/introducing-npx-an-npm-package-runner) to run the locally installed puppet-run program:
26
+
## Usage
27
+
28
+
### Basics
29
+
30
+
Running `puppet-run` from the command line is simple. We can use npm's [npx tool](https://blog.npmjs.org/post/162869356040/introducing-npx-an-npm-package-runner) for convenience.
Pass any JavaScript or TypeScript file to `puppet-run` as an entrypoint. It will be transpiled by Babel using `@babel/preset-env`, `@babel/preset-react` & `@babel/preset-typescript` and bundled using `browserify`. It normally works out-of-the-box with zero configuration.
35
40
36
41
```sh
37
-
npx puppet-run ./path/to/script.js [arguments and options here will be passed to the script]
The script can be any JavaScript or TypeScript file. It will be transparently transpiled via Babel using `@babel/preset-env`, `@babel/preset-react` & `@babel/preset-typescript` and bundled using `browserify`. It usually works out-of-the-box with zero configuration.
41
-
42
-
You just need to call `puppet.exit()` or optionally `puppet.exit(statusCode: number)` when the script is done, so `puppet-run` knows that the script is finished. The `puppet` object is a global, injected by `puppet-run`.
// You can use window.*, since this will be run in Chrome
74
-
consttext=window.atob("SSBydW4gaW4gYSBicm93c2Vy")
68
+
// sample.js
75
69
76
70
// Everything logged here will be piped to your host terminal
77
-
console.log(text)
78
-
console.log(`I am being run in a ${browser.name}${browser.version}`)
71
+
console.log(`I am being run in a browser: ${navigator.userAgent}`)
79
72
80
73
// Explicitly terminate the script when you are done
81
74
puppet.exit()
82
75
```
83
76
84
-
Recognize the final `puppet.exit()`? You need to tell `puppet-run`when the script has finished.
77
+
Don't forget to call `puppet.exit()` when the script is done, so `puppet-run`knows that the script is finished. You can also exit with a non-zero exit code using `puppet.exit(statusCode: number)`.
85
78
86
-
Have a look at the section "Scripting API" below to learn more about that globally available `puppet` object.
79
+
Check out the "Scripting API" section below if you want to learn more about the globally available `puppet` object.
87
80
88
81
Let's run the sample script!
89
82
90
83
```sh
91
-
npm install detect-browser puppet-run
92
84
npx puppet-run ./sample.js
93
85
```
94
86
87
+
You should now see the output of the script on your terminal:
88
+
95
89
```
96
-
I live in a browser now
97
-
I am being run in a chrome 75.0
90
+
I am being run in a browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
98
91
```
99
92
100
93
Have fun!
101
94
102
95
103
96
## Plugins
104
97
105
-
Plugins make it easy to integrate your script with testing frameworks or other extra functionality.
98
+
Plugins make it easy to integrate your script with testing frameworks.
99
+
100
+
Check out the 👉 [plugins repository](https://github.com/andywer/puppet-run-plugins) to see what's on offer.
106
101
107
-
Check out the 👉 [plugins repository](https://github.com/andywer/puppet-run-plugins).
108
102
109
103
## Scripting API
110
104
@@ -114,7 +108,7 @@ The script runner will inject a `puppet` object into the browser window's global
114
108
115
109
Contains all the command line arguments and options passed to `puppet-run` after the script file path.
116
110
117
-
#### `puppet.exit(exitCode: number = 0)`
111
+
#### `puppet.exit(exitCode?: number = 0)`
118
112
119
113
Causes the script to end. The `puppet-run` process will exit with the exit code you pass here.
0 commit comments