Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
grunt-mocha-require-phantom
Advanced tools
Grunt plugin for testing requireJS code using mocha in phantomJS and regular browsers
Grunt plugin for testing requireJS code using mocha in phantomJS and regular browsers
The purpose of this grunt plugin is as follows:
This plugin requires Grunt ~0.4.2
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-mocha-require-phantom --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-mocha-require-phantom');
In your project's Gruntfile, add a section named mocha_require_phantom
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
mocha_require_phantom: {
options: {
base: 'some/path/to/script',
main: 'test-bootstrap',
requireLib: 'libs/require.js',
files: ['tests/**/*.js'],
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
});
Type: String
Default value: ' '
Path to where your script files are within your project. Assumes that all source, libraries and test script files are within this directory.
Type: String
Default value: 'test-bootstrap'
The path to your test bootstrap file that will be specified in requireJS's data-main attribute.
Type: String
Default value: data-main
The attribute appended to the script tag that specifies the module defined in options.main.
Type: String
Default value: 'require.js'
The path to the requireJS library within your application.
Type: Array
Default value: []
An array of additional scripts to include.
Type: Array
Default value: []
An array of paths to your test files.
Type: Number
Default value: 3000
Type: Function
Default value: null
A function that takes the instace of Express as a parameter. This can be used to define routes etc if your tests require back-end interaction. See example for more info.
Type: Boolean
Default value: false
Setting this option to true will keep the server alive and the task will never complete. The purpose of this is to allow you to debug your unit tests within a browser environment if necessary (sometimes you just need a browser's dev tools).
Comma-separated list of files to test relative to the "base" option. If this option is passed in then the list of files will take precedence over the files passed in via the GruntFile.js.
This file is used to kick off your test code. You should do any requireJS and Mocha configuration in this file. e.g.
require.config({
paths: {
chai: '/node_modules/chai/chai'
}
});
mocha.setup({
ui: 'bdd'
});
Within your bootstrap file you will need to use requireJS to load your unit tests and execute Mocha. To do this a global var named testPathname is made available and should be used like so:
require([
//require other modules from your application if necessary here,
testPathname
], function(){
if(window.mochaPhantomJS){
mochaPhantomJS.run();
}
else{
mocha.run();
}
});
You do not need to create any HTML runner files. Simply create an AMD module that runs your test like so:
define([
'chai',
//define application modules to be tested here
], function(chai){
var expect = chai.expect;
describe('test suite 1', function(){
it('should work', function(){
expect(true).to.equal(true);
});
});
});
The main purpose of this plugin is to provide automated testing via phantomJS. However, you can manually run tests in regular browsers also - sometimes this is necessary for debugging. To do so you need to
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
FAQs
Grunt plugin for testing requireJS code using mocha in phantomJS and regular browsers
We found that grunt-mocha-require-phantom 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.