Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Updates the test-suite command for better reporting to the console. Also #478

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ test/test-app/js/jasmine-html.js
#Test-suite
test-runner.json
test/test-suite/data
test/test-suite/Apps/wwTest
test/test-suite/Apps/wwTest-automation
5 changes: 5 additions & 0 deletions build/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ module.exports = {

},

cp: function (srcFile, dstFile) {
var fileBuffer = fs.readFileSync(srcFile);
fs.writeFileSync(dstFile, fileBuffer);
},

listFiles: function (directory, filter) {
var files = wrench.readdirSyncRecursive(directory),
filteredFiles = [];
Expand Down
29 changes: 23 additions & 6 deletions build/test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var utils = require('./build/utils'),
CLITest = require('../test/test-suite/helpers/CLITest');

module.exports = function (done, custom) {
var jasmine = require('jasmine-node'),
verbose = false,
Expand Down Expand Up @@ -60,10 +64,23 @@ module.exports = function (done, custom) {
}
}

jasmine.executeSpecsInFolder(specs, function (runner, log) {
var failed = runner.results().failedCount === 0 ? 0 : 1;
setTimeout(function () {
(typeof done !== "function" ? process.exit : done)(failed);
}, 10);
}, verbose, colored);
utils.displayOutput("STARTING TEST SUITE");

jasmine.executeSpecsInFolder(specs, null, verbose, colored);

function noop () {}

jasmine.getEnv().reporter = {
log: noop,
reportSpecStarting: noop,
reportRunnerStarting: noop,
reportSuiteResults: noop,
reportSpecResults: noop,
reportRunnerResults: function (runner) {
failed = runner.results().failedCount === 0 ? 0 : 1;
CLITest.reportFinalResults();
utils.displayOutput("TEST SUITE COMPLETED");
process.exit(failed);
}
};
};
99 changes: 87 additions & 12 deletions test/test-app/automatic/SpecRunner.htm
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,73 @@
<script type="text/javascript" src="local:///chrome/webworks.js"></script>

<script type="text/javascript">
function sendReport(report, data) {
var xmlhttp = new XMLHttpRequest();
console.log("Sending testing result now...");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log(xmlhttp.responseText);
}
}
xmlhttp.open("POST", "http://169.254.0.2:9644", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(JSON.stringify({status: report, data: data}));
}

var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;

var htmlReporter = new jasmine.HtmlReporter();
var htmlReporter = new jasmine.HtmlReporter(),
originalReportSuiteResults = htmlReporter.reportSuiteResults,
originalReportSpecResults = htmlReporter.reportSpecResults,
originalReportRunnerResults = htmlReporter.reportRunnerResults,
originalReportRunnerStarting = htmlReporter.reportRunnerStarting,
knownFailures;

htmlReporter.reportSuiteResults = function (suite) {
function createNonCyclicalSuite(suite) {
if (suite) {
return {
results: suite.results(),
description: suite.description,
parentSuite: createNonCyclicalSuite(suite.parentSuite)
};
} else {
return suite
}
}
sendReport("SuiteResults", createNonCyclicalSuite(suite));
originalReportSuiteResults(suite);
};

htmlReporter.reportSpecResults = function (spec) {
var data = {
results: spec.results()
};
sendReport("SpecResults", data);
originalReportSpecResults(spec);
};

htmlReporter.reportRunnerResults = function (runner) {
var data = {
results: runner.results(),
suites: {
length: runner.suites().length
}
};

if (data.results.totalCount) {
sendReport("finished", data);
originalReportRunnerResults(runner);
}
}

htmlReporter.reportRunnerStarting = function (runner) {
sendReport("RunnerStarting", "Grrrrrrrrrrrrrreat");
originalReportRunnerStarting(runner);
}
jasmineEnv.addReporter(htmlReporter);

jasmineEnv.specFilter = function(spec) {
Expand All @@ -37,15 +99,17 @@
jasmineEnv.execute();
}

function addChosenSpecs() {
function addChosenSpecs(beQuiet) {
var checkBoxes = document.getElementById('featureList').elements;
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].checked)
{
addScript("spec/" + checkBoxes[i].value + ".js");
}
}
alert("The selected tests have been added, click the Run Jasmine button to execute the SpecRunner");
if (!beQuiet) {
alert("The selected tests have been added, click the Run Jasmine button to execute the SpecRunner");
}
}

function addScript(filePath) {
Expand All @@ -65,6 +129,15 @@
}
}

function runSelectedSpecs () {
var oldTests = document.getElementsByClassName('jasmine_reporter');
for (var i = 0; i < oldTests.length; i++)
{
oldTests[i].parentNode.removeChild(oldTests[i]);
}
execJasmine();
}

document.addEventListener("webworksready", function () {
document.getElementById('addSpecs').onclick = addChosenSpecs;
document.getElementById('selectAll').onclick = function () {
Expand All @@ -73,15 +146,17 @@
document.getElementById('deselectAll').onclick = function () {
setAllBoxes(false);
}
document.getElementById('start').onclick = function () {
var oldTests = document.getElementsByClassName('jasmine_reporter');
for (var i = 0; i < oldTests.length; i++)
{
oldTests[i].parentNode.removeChild(oldTests[i]);
}
execJasmine();
};
});
document.getElementById('start').onclick = runSelectedSpecs;
//Check whether the URL contains index.html
//In this case we are being run in test-suite so just execute
var runAllTests = document.URL.match(/index.html/i);
if (runAllTests) {
setAllBoxes(true);
addChosenSpecs(true);
window.setTimeout(runSelectedSpecs, 1000);
}

});

</script>

Expand Down
120 changes: 99 additions & 21 deletions test/test-app/automation/SpecRunner.htm
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,94 @@
<script type="text/javascript" src="local:///chrome/webworks.js"></script>

<script type="text/javascript">
function sendReport(report, data) {
var xmlhttp = new XMLHttpRequest();
console.log("Sending testing result now...");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log(xmlhttp.responseText);
}
}
xmlhttp.open("POST", "http://169.254.0.2:9644", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(JSON.stringify({status: report, data: data}));
}

var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;

var htmlReporter = new jasmine.HtmlReporter();
var htmlReporter = new jasmine.HtmlReporter(),
originalReportSuiteResults = htmlReporter.reportSuiteResults,
originalReportSpecResults = htmlReporter.reportSpecResults,
originalReportRunnerResults = htmlReporter.reportRunnerResults,
originalReportRunnerStarting = htmlReporter.reportRunnerStarting,
knownFailures;

htmlReporter.reportSuiteResults = function (suite) {
function createNonCyclicalSuite(suite) {
if (suite) {
return {
results: suite.results(),
description: suite.description,
parentSuite: createNonCyclicalSuite(suite.parentSuite)
};
} else {
return suite
}
}
sendReport("SuiteResults", createNonCyclicalSuite(suite));
originalReportSuiteResults(suite);
};

htmlReporter.reportSpecResults = function (spec) {
var data = {
results: spec.results()
};
sendReport("SpecResults", data);
originalReportSpecResults(spec);
};

htmlReporter.reportRunnerResults = function (runner) {
var data = {
results: runner.results(),
suites: {
length: runner.suites().length
}
};

if (data.results.totalCount) {
sendReport("finished", data);
originalReportRunnerResults(runner);
}
}

htmlReporter.reportRunnerStarting = function (runner) {
sendReport("RunnerStarting", "Grrrrrrrrrrrrrreat");
originalReportRunnerStarting(runner);
}
jasmineEnv.addReporter(htmlReporter);

jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};

function addChosenSpecs() {
function execJasmine() {
jasmineEnv.execute();
}

function addChosenSpecs(beQuiet) {
var checkBoxes = document.getElementById('featureList').elements;
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].checked)
{
addScript("local:///automation/spec/" + checkBoxes[i].value + ".js");
addScript("spec/" + checkBoxes[i].value + ".js");
}
}
alert("The selected tests have been added, click the Run Jasmine button to execute the SpecRunner");
if (!beQuiet) {
alert("The selected tests have been added, click the Run Jasmine button to execute the SpecRunner");
}
}

function addScript(filePath) {
Expand All @@ -65,6 +133,15 @@
}
}

function runSelectedSpecs () {
var oldTests = document.getElementsByClassName('jasmine_reporter');
for (var i = 0; i < oldTests.length; i++)
{
oldTests[i].parentNode.removeChild(oldTests[i]);
}
execJasmine();
}

document.addEventListener("webworksready", function () {
document.getElementById('addSpecs').onclick = addChosenSpecs;
document.getElementById('selectAll').onclick = function () {
Expand All @@ -73,35 +150,36 @@
document.getElementById('deselectAll').onclick = function () {
setAllBoxes(false);
}
document.getElementById('start').onclick = function () {
var oldTests = document.getElementsByClassName('jasmine_reporter');
for (var i = 0; i < oldTests.length; i++)
{
oldTests[i].parentNode.removeChild(oldTests[i]);
}
document.getElementById('controls').style.display = "none";
jasmineEnv.execute();
jasmineEnv.currentRunner_.finishCallback = function () {
document.getElementById('controls').style.display = "block";
};
};
document.getElementById('start').onclick = runSelectedSpecs;
//Check whether the URL contains index.html
//In this case we are being run in test-suite so just execute
var runAllTests = document.URL.match(/index.html/i);
if (runAllTests) {
setAllBoxes(true);
addChosenSpecs(true);
window.setTimeout(runSelectedSpecs, 1000);
}

});

</script>

<script>
function showOverlay() {
var o = document.getElementById('overlay');
o.style.visibility = 'visible';
window.scrollTo(0,0);
}

function hideOverlay() {
var o = document.getElementById('overlay');
o.style.visibility = 'hidden';
}

function takeScreenshot() {
internal.automation.takeScreenshot("/accounts/1000/shared/camera/WebWorksScreenShot.bmp");
}

</script>
function takeScreenshot() {
internal.automation.takeScreenshot("/accounts/1000/shared/camera/WebWorksScreenShot.bmp");
}
</script>

</head>

Expand Down
2 changes: 2 additions & 0 deletions test/test-app/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@

<access uri="file:///accounts/1000/appData" />

<access uri="http://169.254.0.2:9644" />

<license href="http://www.apache.org/licenses/LICENSE-2.0">
Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
Expand Down
3 changes: 0 additions & 3 deletions test/test-suite/Apps/DisableWebSecurity/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
<param name="websecurity" value="disable"/>
</feature>

<!-- although unnecessary serves as an example-->
<access uri="http://169.254.0.2:9644" />

<author rim:copyright="Copyright 1998-2011 My Corp" email="[email protected]" href="http://www.blah.com">Research In Motion Ltd.</author>

<license href="http://www.apache.org/licenses/LICENSE-2.0">
Expand Down
Loading