AQ
What is it?
(Note: this is still a work in progress. Nonetheless, the base functioality is there, and works)
AQ allows you to automate your QUnit tests, leveraging Node.js.
To get started, create a Node.js server.
Install
Using npm:
npm install aq
Update the packages:
npm update
In your server.js
,
aq = require('aq'),
app = http.createServer( function( request, response ) {
} ).listen( port );
var options = {
log: true,
testFolder: 'unit-tests',
dir: path.normalize(__dirname + '/test/unit-tests/'),
page: '/test/index.html'
};
aq = aq.listen(app, options);
Creating the tests
The test page
Before you can automate your tests, you first need a page where the tests can run in.
In your test page (perhaps index.html), include AQ and socket.io:
<script src="/socket.io/socket.io.js"></script>
<script src="/aq/aq.js"></script>
Additionally, there has to be a target container called aq-container
where AQ can load the proper unit test into.
<div id="aq-container"></div>
AQ will begin testing only when explicitly told. You can do this by calling AQ.start()
, in the test page:
window.AQ.start();
Struture of a Unit Test file
Each unit test file within the unit test filder should be an HTML file containing a global run
function. This function must exist so the test harness can execute the tests defined therein properly.
<script>
function run() {
test('some test', function() {
ok(true, 'always true');
}
}
</script>
How does it all work?
When the server starts, AQ scans the specified directory where the unit tests are contained. Each file name is then returned to the client side. The content of each test file is loaded via an AJAX request, and inserted into aq-container
. Once iserted, the run
function is called, and the tests are executed. Upon completion of the tests, the next unit test file is loaded.
All tests results (and final results) are passed to the server.
Running the tests
Run all tests in the unit test folder
node server.js
Command line options:
Specify the browser
By default, the unit tests will run on all the browsers specified in config.js
. To specify the browser, you can use the -b
option
node server.js -b chrome
Keep browser open
By default, after all the unit tests have completed running on a browser, that browser session will close. You can choose to keep the browser open with the -k
option
node server.js -k true
How to specify which unit tests to run
Insert the unit tests to run after --
node server.js -- test1.html test2.html
Events
On the client
AQ provides a beforeTestRun
event which is executed after a unit test file is loaded. If this is event is bound, no test will run unless an explicit call to AQ.run
is made. For example, in the test page:
window.AQ.start();
$(window.AQ).on('beforeTestRun', function() {
window.AQ.run();
});
On the server
On the server side, once AQ is listening, you can bind onto certain events:
aq = aq.listen(app, options);
aq.on('test-executing', function(filename) {
console.log(filename);
});
aq.on('test-done', function(data) {
console.log(data);
});
aq.on('done', function(data) {
console.log(data);
});