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);
Usage (client-side)
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:
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:
Justification - why is this change worthwhile? Link to issues, use code samples, etc.
Documentation changes for your code updates. Be sure to check the groc-generated HTML with grunt doc
A description of how you tested the change. Don't forget about the very-useful npm 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)
License
(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.
thehelp-test
One install gets you standard testing tools for both the client and the server, including client-side test coverage under
requirejsviablanket.Features
mocha,sinon, andchaiavailable on the client and on the servergrunt-mochaWinstonTestHelperto verify that calls were made as expected and/or prevent logs from hitting consoleblanketon the client-side, with some key tweaks to make it work seamlessly underrequirejswinstonis installed, automatic setup ofwinstonconsole logging transport both for the default logger and default collection.Supported browsers
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.Setup
Include the project in your dependencies:
Usage (node.js)
To write tests very quickly, just pull in the project and start using it!
Here's some node.js code using it:
Usage (client-side)
This same code also works on the client, assuming that you've set things up properly. you'll need to set up
requirejspaths for several dependencies. Your client-side test setup file 'setup.js' can look like this:And the HTML file hosting your tests can look like this:
The test file files themselves are easy:
For all the details and a working example, take a look at the integration tests under 'test/integration' in this project.
Advanced Config
You've got a few more options than just
filesandmochaCsson the client side. Here are the complete set of options:Lastly, you can set the environment variable
THEHELP_TEST_LEVELto customize the winston logging level for your tests. It defaults to 'info.'Detailed Docs
Detailed docs be found at this project's GitHub Pages, thanks to
grocandthehelp-project: http://thehelp.github.io/test/. A good place to start isthehelp-test-harnest.Contributing changes
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:keepaliveto test it in your browser.Please cover as many browsers as you can, or use
grunt cross-browserwith your Sauce Credentials in env.json. When you have some changes ready, please submit a pull request with:grunt docnpm linkcommand :0)I may ask you to use a
git rebaseto ensure that your commits are not interleaved with commits already in the history. And of course, make suregruntcompletes successfully. :0)License
(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.