Skip to content

Commit 6e9dc17

Browse files
authored
Update README.md
1 parent dc9afd4 commit 6e9dc17

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

README.md

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# 🤖 puppet-run
1+
<h1 align="center">🤖&nbsp;&nbsp;puppet-run</h1>
22

3-
Run anything JavaScript in Chrome with puppeteer and pipe it's output back to your terminal 🔥
3+
<p align="center">
4+
<a href="https://www.npmjs.com/package/puppet-run" target="_blank"><img alt="npm (tag)" src="https://img.shields.io/npm/v/puppet-run.svg?style=flat-square"></a>
5+
</p>
46

5-
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!
610

711
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.
812

@@ -19,28 +23,25 @@ How does it relate to [Karma](https://karma-runner.github.io)? It's everything t
1923
npm install puppet-run
2024
```
2125

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.
2331

2432
```sh
2533
npx puppet-run [<arguments>]
2634

27-
# equal to:
28-
# node ./node_modules/.bin/puppet-run [<arguments>]
35+
# without npx
36+
node ./node_modules/.bin/puppet-run [<arguments>]
2937
```
3038

31-
32-
## Usage
33-
34-
### Basics
39+
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.
3540

3641
```sh
37-
npx puppet-run ./path/to/script.js [arguments and options here will be passed to the script]
42+
npx puppet-run [...puppet-run options] ./path/to/script.js [...script options]
3843
```
3944

40-
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`.
43-
4445
### Run mocha tests
4546

4647
```sh
@@ -63,48 +64,41 @@ npx puppet-run --plugin=mocha --help
6364

6465
## Example
6566

66-
This is how a simple script might look like:
67-
6867
```js
69-
import { detect } from "detect-browser"
70-
71-
const browser = detect()
72-
73-
// You can use window.*, since this will be run in Chrome
74-
const text = window.atob("SSBydW4gaW4gYSBicm93c2Vy")
68+
// sample.js
7569

7670
// 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}`)
7972

8073
// Explicitly terminate the script when you are done
8174
puppet.exit()
8275
```
8376

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)`.
8578

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.
8780

8881
Let's run the sample script!
8982

9083
```sh
91-
npm install detect-browser puppet-run
9284
npx puppet-run ./sample.js
9385
```
9486

87+
You should now see the output of the script on your terminal:
88+
9589
```
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
9891
```
9992

10093
Have fun!
10194

10295

10396
## Plugins
10497

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.
106101

107-
Check out the 👉 [plugins repository](https://github.com/andywer/puppet-run-plugins).
108102

109103
## Scripting API
110104

@@ -114,7 +108,7 @@ The script runner will inject a `puppet` object into the browser window's global
114108

115109
Contains all the command line arguments and options passed to `puppet-run` after the script file path.
116110

117-
#### `puppet.exit(exitCode: number = 0)`
111+
#### `puppet.exit(exitCode?: number = 0)`
118112

119113
Causes the script to end. The `puppet-run` process will exit with the exit code you pass here.
120114

0 commit comments

Comments
 (0)