
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
thehelp-test
Advanced tools
One-step install for client/server testing tools: chai, mocha, sinon and code coverage via blanket
One install gets you standard testing tools for both the client and the server, including client-side test coverage under requirejs via blanket.
mocha, sinon, and chai available on the client and on the servergrunt-mochaWinstonTestHelper to verify that calls were made as expected and/or prevent logs from hitting consoleblanket on the client-side, with some key tweaks to make it work seamlessly under requirejswinston is installed, automatic setup of winston console logging transport both for the default logger and default collection.Sadly, chai, the assertion library used in this project, doesn't support IE8 (okay, maybe a little). Has been tested on as low as iOS 4.3, but usage is so low for pre-6.0 versions that they are not part of the standard run.
Include the project in your dependencies:
npm install thehelp-test --save-dev
To write tests very quickly, just pull in the project and start using it!
Here's some node.js code using it:
var test = require('thehelp-test');
var expect = test.expect;
var sinon = test.sinon;
var WinstonTestHelper = test.WinstonTestHelper;
var stub = sinon.stub();
stub();
expect(stub).to.have.property('callCount', 1);
var winston = new WinstonTestHelper({showLogs: false});
winston.info('blah');
expect(winston).to.have.deep.property('info.callCount', 1);
This same code also works on the client, assuming that you've set things up properly. you'll need to set up requirejs paths for several dependencies. Your client-side test setup file 'setup.js' can look like this:
'use strict';
requirejs.config({
baseUrl: '/',
paths: {
'thehelp-test': 'node_modules/thehelp-test/dist/thehelp-test',
// if you'd like to measure test coverage
'thehelp-test-coverage': 'node_modules/thehelp-test/dist/thehelp-test-coverage',
// if you'd like to run tests from the command line grunt-mocha
'grunt-mocha-bridge': 'node_modules/thehelp-test/dist/thehelp-test-coverage'
}
});
require([window.entrypoint], function() {});
And the HTML file hosting your tests can look like this:
<script>
window.entrypoint = '../../node_modules/thehelp-test/dist/thehelp-test-harness';
window.thehelp = {
test: {
files: [
'test/unit/client/test_index',
'test/unit/both/test_something',
],
mochaCss: '../../node_modules/thehelp-test/dist/mocha.css'
}
};
</script>
<script data-main='setup.js' src="../../bower_components/requirejs/require.js"></script>
The test file files themselves are easy:
// basic boilerplate so this file runs client and server
if (typeof define !== 'function') {
var define = require('amdefine')(module);
}
define(['thehelp-test', '../../../src/both/something'], function(test, something) {
'use strict';
var expect = test.expect;
describe('something', function() {
it('covered should return 20', function() {
expect(something.covered()).to.equal(20);
});
});
});
For all the details and a working example, take a look at the integration tests under 'test/integration' in this project.
You've got a few more options than just files and mochaCss on the client side. Here are the complete set of options:
window.thehelp = {
test: {
// these two are required:
files: ['the', 'test', 'file', 'paths', 'for', 'requirejs'],
mochaCss: 'path to mocha.css',
// optional blanket options, defaults are:
blanket: {
filter: '/src/',
antifilter: '["/bower_components/", "node_modules", "/test/","/lib/"]'
},
// optional, defaults to true, for code coverage in browser
coverage: false
// optional, defaults to false, auto-starting tests on load
waitToRun: true
}
}
Lastly, you can set the environment variable THEHELP_TEST_LEVEL to customize the winston logging level for your tests. It defaults to 'info.'
Detailed docs be found at this project's GitHub Pages, thanks to groc and thehelp-project: http://thehelp.github.io/test/. A good place to start is thehelp-test-harnest.
The end-to-end tests under 'test/integration' will be your friend. :0) It will help you ensure that the client-side part of this library is working properly. Use grunt connect:keepalive to test it in your browser.
Please cover as many browsers as you can, or use grunt cross-browser with your Sauce Credentials in env.json. When you have some changes ready, please submit a pull request with:
grunt docnpm link command :0)I may ask you to use a git rebase to ensure that your commits are not interleaved with commits already in the history. And of course, make sure grunt completes successfully. :0)
(The MIT License)
Copyright (c) 2013 Scott Nonnenberg <scott@nonnenberg.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
One-step install for client/server testing tools: chai, mocha, sinon and code coverage via blanket
We found that thehelp-test 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.