Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is possible to implement a solution to write a XML File for jUnit ? #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ Show test cases:
```bash
$ phantomjs path/to/runner-list.js [url-of-your-qunit-testsuite]
```
## Use with jUnit and write an result.xml file
In that case to output a xml file for the testresults, it's possible to load the QUnit Plugin [https://github.com/JamesMGreene/qunit-reporter-junit] and write at the top of you QUnit HTML File:

```html
<script>
if (typeof window.callPhantom === 'function') {
window.callPhantom({jUnitReportFile: 'test1.xml'});
}
</script>
```

after that, a "test1.xml" file will be written in you root directory.

## Timeout
In `v2.0`, a default timeout of 5 seconds was added. The timeout was optional before. This could cause tests to break, which is the reason for the major version bump.

Expand Down
37 changes: 36 additions & 1 deletion runner-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
var url, page, timeout,
args = require('system').args;

var jUnitReportFile;

// arg[0]: scriptName, args[1...]: arguments
if (args.length < 2) {
console.error('Usage:\n phantomjs [phantom arguments] runner.js [url-of-your-qunit-testsuite] [timeout-in-seconds]');
Expand Down Expand Up @@ -33,7 +35,27 @@
var result,
failed;

if (message) {
if (message && 'jUnitReportFile' in message)
{
jUnitReportFile = message.jUnitReportFile;
}
else if (message && 'jUnitReport' in message)
{
if (jUnitReportFile)
{
console.log("Write jUnit to File: " + jUnitReportFile);
var fs = require('fs');
try
{
fs.write(jUnitReportFile, message.jUnitReport, 'w');
}
catch(e)
{
console.log(e);
}
}
}
else if (message) {
if (message.name === 'QUnit.done') {
result = message.data;
failed = !result || !result.total || result.failed;
Expand Down Expand Up @@ -138,6 +160,19 @@
});
}
});

if ('jUnitReport' in QUnit)
{
QUnit.jUnitReport = function (result) {
if ('xml' in result)
{
if (typeof window.callPhantom === 'function') {
window.callPhantom({ jUnitReport: result.xml });
}
}
};
}

}, false);
}

Expand Down