在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:juliangruber/browser-run开源软件地址:https://github.com/juliangruber/browser-run开源编程语言:JavaScript 98.6%开源软件介绍:browser-runThe easiest way of running code in a browser environment. Bundles Usage$ echo "console.log('Hey from ' + location); window.close()" | browser-run
Hey from http://localhost:53227/
$ Or use var run = require('browser-run');
var browser = run();
browser.pipe(process.stdout);
browser.end('console.log(location); window.close()'); Example with browserify$ browserify main.js | browser-run or var browserify = require('browserify');
var browser = require('browser-run');
browserify('main.js').bundle().pipe(browser()).pipe(process.stdout); CLI$ browser-run --help
Run JavaScript in a browser.
Write code to stdin and receive console output on stdout.
Usage: browser-run [OPTIONS]
Options:
--version Show version number [boolean]
-b, --browser Browser to use. Always available: electron. Available if
installed: chrome, firefox, ie, safari [default: "electron"]
--sandbox Enable electron sandbox [boolean] [default: true]
--basedir Set this if you need to require node modules in node mode
-h, --help Print help [boolean]
-p, --port Starts listening on that port and waits for you to open a
browser
-s, --static Serve static assets from this directory
-m, --mock Path to code to handle requests for mocking a dynamic back-end
-i, --input Input type. Defaults to 'javascript', can be set to 'html'.
-n, --node Enable nodejs apis in electron Custom html fileBy using Dynamic back-end mockBy using mock.js needs to export a function that accepts Example: module.exports = function(req,res){
if (req.url === '/mock/echo') {
req.pipe(res)
}
} APIrun([opts])Returns a duplex stream and starts a webserver.
If only an empty string is written to it, an error will be thrown as there is nothing to execute. If you call run#stop()Stop the underlying webserver. Headless testingIn environments without a screen, you can use GitHub ActionsThis is a full example to run on:
- pull_request
- push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: npm install
- run: sudo apt-get install xvfb
- run: xvfb-run --auto-servernum npm test TravisAdd this to your travis.yml: addons:
apt:
packages:
- xvfb
install:
- export DISPLAY=':99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- npm install Any gnu/linux box$ sudo apt-get install xvfb # or equivalent
$ export DISPLAY=':99.0'
$ Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
$ browser-run ... DockerThere is also an example Docker image. Source InstallationWith npm do $ npm install browser-run # for library
$ npm install -g browser-run # for cli SponsorsThis module is proudly supported by my Sponsors! Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my Patreon. Not sure how much of my modules you're using? Try feross/thanks! License(MIT) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论