
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
mocha-headless-chrome
Advanced tools
Run client-side mocha tests in the command line through headless Chrome
This is the tool which runs client-side mocha tests in the command line through headless Chrome (puppeteer is used).
Node 10.18.1+ and Mocha 2.3.0+ are supported.
First you need to install mocha-headless-chrome:
npm i mocha-headless-chrome
Then prepare the test page (see the example).
Note. It is necessary to add the <meta charset="utf-8"> tag. Otherwise browser may use another encoding and test results will be shown incorrectly.
Then run the CLI and specify your test page path using -f parameter.
mocha-headless-chrome -f test-page.html
Run test on the "test.html" page:
mocha-headless-chrome -f test.html
Run tests on the remote page:
mocha-headless-chrome -f http://localhost:8080
Output test results using "nyan" reporter:
mocha-headless-chrome -f test.html -r nyan
Pass the Chrome --no-sandbox and --disable-setuid-sandbox arguments:
mocha-headless-chrome -f test.html -a no-sandbox -a disable-setuid-sandbox
All mocha reporters are supported. Specify the reporter name through -r parameter. All reporter output (include cursor manipulations) will be redirected to stdout as like it works in console.
For usage of third-party reporter just include it's code to the page by <script> tag and specify it's name in the -r parameter.
Also special reporter named "none" is available which does not output anything. This reporter will be useful when you want to process test result without output to console (for example, when saving data to a file).
You can use mocha-headless-chrome programmatically. Just require the mocha-headless-chrome node module and pass proper parameters into it. Function result is a Promise.
const {runner} = require('mocha-headless-chrome');
const options = {
file: 'test.html', // test page path
reporter: 'dot', // mocha reporter name
width: 800, // viewport width
height: 600, // viewport height
timeout: 120000, // timeout in ms
polling: 'raf', // polling mechanism
executablePath: '/usr/bin/chrome-unstable', // chrome executable path
visible: true, // show chrome window
args: ['no-sandbox'] // chrome arguments
};
runner(options)
.then(result => {
let json = JSON.stringify(result);
console.log(json);
});
See also the TypeScript example.
FAQs
Run client-side mocha tests in the command line through headless Chrome
The npm package mocha-headless-chrome receives a total of 3,441 weekly downloads. As such, mocha-headless-chrome popularity was classified as popular.
We found that mocha-headless-chrome demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.