Skip to content

MargaritaLoseva/qunit-harness

 
 

Repository files navigation

qunit-harness

A library for running qunit tests on a local machine and in the SauceLabs environment.

Build Status

##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');
    });
}

//Local machine testing
var qunitHarness = new QUnitHarness
    //set path with tests
    .fixtures('/tests/')
    //set qunit server ports
    .port(2000)             //by default 1335
    .crossDomainPort(2001)  //by default 1336
    //add index.js script content as a <script src='/tested-script.js'> in the head of the test page
    .scripts([{ src: '/tested-script.js', path: '/lib/index.js' }]) 
    .css([{ src: '/style.css', path: '/lib/style.css' }])
    //extend qunit server application for test purposes
    .configApp(configQunitServerApp)
    .create();
    
//Testing in the Saucelabs environment
//Configure browsers here: https://docs.saucelabs.com/reference/platforms-configurator/
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  //sec
};

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;               //http://localhost:1335/
window.QUnitGlobals.crossDomainHostname;   //http://localhost:1336/

####Get test resource

window.QUnitGlobals.getResourceUrl(pathToResourceFile[, urlAlias])

By default the resource will have 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');
//returns "http://<hostname>/test-resource/my-custom-script/script.js?filePath=..."

Example:

<!-- data/iframe.html -->
<!DOCTYPE html>
<html>
<head>
    <title>Iframe page</title>
    <meta charset="utf-8">
</head>
<body>
    Some content
</body>
</html>
// tests/test1-test.js
asyncTest('iframe test', function () {
    var iframeSrc = window.QUnitGlobals.getResourceUrl('../data/iframe.html', 'iframe.html');
    $('<iframe></iframe>').src(iframeSrc).appendTo('body');
    //appends an iframe with url http://<hostname>/test-resource/iframe.html
    ...
});

Run a test with some markup on the page

Put testname-test.js and testname.html files to a folder with -test postfix and markup from the .html file wiil be included to the testname-test.js test page.

Example:

<!-- tests/markup-test/index.html -->
<div id="#test-element"></div>
// tests/markup-test/index-test.js
test('check element', function () {
    ok($('#test-element').length);  //success
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 78.6%
  • HTML 21.2%
  • CSS 0.2%