qunit-harness
A library for running qunit tests on a local machine and in the SauceLabs environment.
##Install
$ npm install qunit-harness
##Usage
var QUnitHarness = require('qunit-harness');
function configQunitServerApp (app) {
app.post('/my-custom-request', function (req, res) {
res.end('ok');
});
}
var qunitHarness = new QUnitHarness
.fixtures('/tests/')
.port(2000)
.crossDomainPort(2001)
.scripts([{ src: '/tested-script.js', path: '/lib/index.js' }])
.css([{ src: '/style.css', path: '/lib/style.css' }])
.configApp(configQunitServerApp)
.create();
var BROWSERS = [
{
platform: 'Windows 10',
browserName: 'chrome'
},
{
platform: 'Windows 10',
browserName: 'firefox'
},
{
platform: 'Windows 10',
browserName: 'internet explorer',
version: '11.0'
}
];
var SAUCELABS_SETTINGS = {
username: <saucelabs_username>,
accessKey: <saucelabs_accessKey>,
build: 'build',
tags: ['master'],
browsers: BROWSERS,
name: 'qunit tests',
timeout: 180
};
qunitHarness
.saucelabs(SAUCELABS_SETTINGS)
.tests(['/tests/test1-test.js', '/tests/test2-test.js'])
.run()
.then(function () {
console.log('Tests done');
})
.catch(function (err) {
console.log(err);
});
##QUnit tests
####Get test server hostname
window.QUnitGlobals.hostname;
window.QUnitGlobals.crossDomainHostname;
####Get test resource
window.QUnitGlobals.getResourceUrl(pathToResourceFile[, urlAlias])
By default the resource has the http://<hostname>/test-resource?filePath=<resourceFilePath>&base=<currentTestFilePath>
url.
To customize the url, use the urlAlias
argument:
window.QUnitGlobals.getResourceUrl('../data/script.js', 'my-custom-script/script.js');
Example:
<!DOCTYPE html>
<html>
<head>
<title>Iframe page</title>
<meta charset="utf-8">
</head>
<body>
Some content
</body>
</html>
asyncTest('iframe test', function () {
var iframeSrc = window.QUnitGlobals.getResourceUrl('../data/iframe.html', 'iframe.html');
$('<iframe></iframe>').src(iframeSrc).appendTo('body');
...
});
Run a test with some markup on the page
Put the testname-test.js
and testname.html
files to the folder with the -test
postfix. Then, the markup from the .html
file will be included into the testname-test.js
test page.
Example:
<div id="#test-element"></div>
test('check element', function () {
ok($('#test-element').length);
});