From c5c245b9407c9f71c223ecead42328acff614698 Mon Sep 17 00:00:00 2001 From: Marcel Alburg Date: Wed, 25 Feb 2015 16:04:29 +0100 Subject: [PATCH 1/3] implement a possible solution to write an xml file for jUnit --- README.md | 11 +++++++++++ runner-json.js | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf19516..5b6ef6b 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,17 @@ 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 testresult's, 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: + +` + +` + ## 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. diff --git a/runner-json.js b/runner-json.js index 8fecfb2..ca53ede 100644 --- a/runner-json.js +++ b/runner-json.js @@ -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]'); @@ -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; @@ -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); } From 060bcf4e32421ba3ee8180426fd8f24fd35f6950 Mon Sep 17 00:00:00 2001 From: Marcel Alburg Date: Wed, 25 Feb 2015 16:05:45 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b6ef6b..b062ece 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,13 @@ $ 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 testresult's, 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 -` +``` ## 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. From 723b081f3c80340cd69c315f6962cc76f13a3fdb Mon Sep 17 00:00:00 2001 From: Marcel Alburg Date: Wed, 25 Feb 2015 16:07:12 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b062ece..de32464 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Show test cases: $ 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 testresult's, 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: +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 ``` +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.