Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
mocha-phantomjs-core
Advanced tools
So now that you got your tests Mocha running on a simple flat HTML file, now how do you run them in your CI environment? Karma? what is this karma.conf.js
file I have to write? and some background runner task? how do I grep over just a few tests? wait I need a to also install a driver for phantomjs too? bleck.
Rather than force you to redo your test harness and local development testing, simply run phantomjs mocha-phantomjs-core.js spec tests/mytests.html
and be done with it. mocha-phantomjs-core
builds on top of what you already have, with no high barrier to entry like Karma.
This project is the core phantomjs code for mocha-phantomjs
. If you are a regular user wanting to use it from the command line, you'll want to go there. If you are a build plugin author, or want direct control over how phantomjs is invoked, you are in the right place.
npm install mocha-phantomjs-core
phantomjs mocha-phantomjs-core.js <TESTS> <REPORTER> <CONFIG as JSON>
It's best to always refer to the tests for full usage and examples.
reporter
One of mocha's built in reporters, or a full path to a file for a 3rd party reporter (see below on how to write one).
grep
a string to pass to mocha.grep()
to filter tests. also provide invert: true
if you want to invert the grep and filter out tests.
useColors
Boolean. Force or suppress color usage. Defaults to what your terminal supports.
bail
Boolean. Stop the test run at the first failure if true. Defaults to false.
ignoreResourceErrors
Boolean. Suppress the resource failure output that mocha-phantomjs-core
will output by default.
viewportSize
Sets the viewport size. Specify height
and width
, like below:
settings
If you need to pass additional settings to the phantomjs webpage, you can specify an object of settings here, including common ones like userAgent
and loadImages
.
phantomjs mocha-phantomjs-core.js dot tests/mytests.html "{\"viewportSize\":{\"width\":720,\"height\":480}}"
Previously mocha-phantomjs
required you to look for mochaPhantomJS
and then use mochaPhantomJS.run()
. That is no longer required. Call mocha.run()
as you normally would.
mocha-phantomjs-core
supports creating screenshots from your test code. For example, you could write a function like below into your test code.
function takeScreenshot() {
if (window.callPhantom) {
var date = new Date()
var filename = "screenshots/" + date.getTime()
console.log("Taking screenshot " + filename)
callPhantom({'screenshot': filename})
}
}
If you want to generate a screenshot for each test failure you could add the following into your test code.
afterEach(function () {
if (this.currentTest.state == 'failed') {
takeScreenshot()
}
})
mocha-phantomjs-core
will expose environment variables at mocha.env
Mocha has support for custom 3rd party reporters, and mocha-phantomjs does support 3rd party reporters, but keep in mind - the reporter does not run in Node.js, but in the browser, and node modules can't be required. You need to only use basic, vanilla JavaScript when using third party reporters. However, some things are available:
require
: You can only require other reporters, like require('./base')
to build off of the BaseReporterexports
, module
: Export your reporter class as normalprocess
: use process.stdout.write
preferrably to support the --file
option over console.log
(see #114)Also, no compilers are supported currently, so please provide plain ECMAScript 5 for your reporters.
npm install
npm test
Travis CI does a matrix build against phantomjs 1.9.7 and 2.0.0, currently. See .travis.yml
for the latest.
To debug an individual test, since they are just process forks, you may want to run them directly, like
phantomjs mocha-phantomjs-core.js test/timeout.html spec "{\"timeout\":500}"
Released under the MIT license. Copyright (c) 2015 Ken Collins and Nathan Black.
FAQs
Run client-side mocha tests in phantomjs or slimerjs
The npm package mocha-phantomjs-core receives a total of 5,815 weekly downloads. As such, mocha-phantomjs-core popularity was classified as popular.
We found that mocha-phantomjs-core 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.