This commit is contained in:
MishaBagger
2023-10-25 09:15:21 +03:00
commit b6c10cc93f
9828 changed files with 1446743 additions and 0 deletions

View File

@@ -0,0 +1,266 @@
(function(){
var env, spec, suite, reporter, runner;
function fakeSpec(suite, name) {
var s = new jasmine.Spec(env, suite, name);
suite.add(s);
return s;
}
function fakeSuite(name, parentSuite) {
var s = new jasmine.Suite(env, name, null, parentSuite || null);
if (parentSuite) {
parentSuite.add(s);
}
runner.add(s);
return s;
}
// make sure reporter is set before calling this
function triggerSuiteEvents(suites) {
for (var i=0; i<suites.length; i++) {
var s = suites[i];
for (var j=0; j<s.specs().length; j++) {
reporter.reportSpecStarting(s.specs()[j]);
reporter.reportSpecResults(s.specs()[j]);
}
reporter.reportSuiteResults(s);
}
}
describe("JUnitXmlReporter", function(){
beforeEach(function(){
env = new jasmine.Env();
env.updateInterval = 0;
runner = new jasmine.Runner(env);
suite = fakeSuite("ParentSuite");
spec = fakeSpec(suite, "should be a dummy with invalid characters: & < > \" '");
reporter = new jasmine.JUnitXmlReporter();
});
describe("constructor", function(){
it("should default path to an empty string", function(){
expect(reporter.savePath).toEqual("");
});
it("should default consolidate to true", function(){
expect(reporter.consolidate).toBe(true);
});
it("should default useDotNotation to true", function(){
expect(reporter.useDotNotation).toBe(true);
});
describe("file prepend", function(){
it("should default output file prepend to \'TEST-\'", function () {
expect(reporter.filePrefix).toBe("TEST-");
});
it("should allow the user to override the default xml output file prepend", function () {
reporter = new jasmine.JUnitXmlReporter("", true, true, "alt-prepend-");
expect(reporter.filePrefix).toBe("alt-prepend-");
});
it("should output the file with the modified prepend", function () {
reporter = new jasmine.JUnitXmlReporter("", true, true, "alt-prepend-");
spyOn(reporter, "writeFile");
triggerSuiteEvents([suite]);
reporter.reportRunnerResults(runner);
expect(reporter.writeFile).toHaveBeenCalledWith(reporter.savePath, "alt-prepend-ParentSuite.xml", jasmine.any(String));
});
});
});
describe("reportSpecStarting", function(){
it("should add start time", function(){
reporter.reportSpecStarting(spec);
expect(spec.startTime).not.toBeUndefined();
});
it("should add start time to the suite", function(){
expect(suite.startTime).toBeUndefined();
reporter.reportSpecStarting(spec);
expect(suite.startTime).not.toBeUndefined();
});
it("should not add start time to the suite if it already exists", function(){
var a = new Date();
suite.startTime = a;
reporter.reportSpecStarting(spec);
expect(suite.startTime).toBe(a);
});
});
describe("reportSpecResults", function(){
beforeEach(function(){
reporter.reportSpecStarting(spec);
//spec.results_ = fakeResults();
reporter.reportSpecResults(spec);
});
it("should compute duration", function(){
expect(spec.duration).not.toBeUndefined();
});
it("should generate <testcase> output", function(){
expect(spec.output).not.toBeUndefined();
expect(spec.output).toContain("<testcase");
});
it("should escape bad xml characters in spec description", function() {
expect(spec.output).toContain("&amp; &amp;lt; &amp;gt; &amp;quot; &amp;apos;");
});
it("should generate valid xml <failure> output if test failed", function(){
spec = fakeSpec(suite, "should be a dummy");
reporter.reportSpecStarting(spec);
var expectationResult = new jasmine.ExpectationResult({
matcherName: "toEqual", passed: false,
message: "Expected 'a' to equal '&'.",
trace: { stack: "in test1.js:12\nin test2.js:123" }
});
var results = {
passed: function() { return false; },
getItems: function() { return [expectationResult]; }
};
spyOn(spec, "results").andReturn(results);
reporter.reportSpecResults(spec);
expect(spec.output).toContain("<failure");
expect(spec.output).toContain("type=\"" + expectationResult.type + "\"");
expect(spec.output).toContain("message=\"Expected &amp;apos;a&amp;apos; to equal &amp;apos;&amp;&amp;apos;.\"");
expect(spec.output).toContain(">in test1.js:12\nin test2.js:123</failure>");
});
});
describe("reportSuiteResults", function(){
beforeEach(function(){
triggerSuiteEvents([suite]);
});
it("should compute duration", function(){
expect(suite.duration).not.toBeUndefined();
});
it("should generate startTime if no specs were executed", function(){
suite = fakeSuite("just a fake suite");
triggerSuiteEvents([suite]);
expect(suite.startTime).not.toBeUndefined();
});
it("should generate <testsuite> output", function(){
expect(suite.output).not.toBeUndefined();
expect(suite.output).toContain("<testsuite");
});
it("should contain <testcase> output from specs", function(){
expect(suite.output).toContain("<testcase");
});
});
describe("reportRunnerResults", function(){
var subSuite, subSubSuite, siblingSuite;
beforeEach(function(){
subSuite = fakeSuite("SubSuite", suite);
subSubSuite = fakeSuite("SubSubSuite", subSuite);
siblingSuite = fakeSuite("SiblingSuite With Invalid Chars & < > \" ' | : \\ /");
var subSpec = fakeSpec(subSuite, "should be one level down");
var subSubSpec = fakeSpec(subSubSuite, "should be two levels down");
var siblingSpec = fakeSpec(siblingSuite, "should be a sibling of Parent");
spyOn(reporter, "writeFile");
spyOn(reporter, "getNestedOutput").andCallThrough();
triggerSuiteEvents([suite, subSuite, subSubSuite, siblingSuite]);
});
describe("general functionality", function() {
beforeEach(function() {
reporter.reportRunnerResults(runner);
});
it("should remove invalid filename chars from the filename", function() {
expect(reporter.writeFile).toHaveBeenCalledWith(reporter.savePath, "TEST-SiblingSuiteWithInvalidChars.xml", jasmine.any(String));
});
it("should remove invalid xml chars from the classname", function() {
expect(siblingSuite.output).toContain("SiblingSuite With Invalid Chars &amp; &amp;lt; &amp;gt; &amp;quot; &amp;apos; | : \\ /");
});
});
describe("consolidated is true and consolidatedAll is false", function(){
beforeEach(function(){
reporter.reportRunnerResults(runner);
});
it("should write one file per parent suite", function(){
expect(reporter.writeFile.callCount).toEqual(2);
});
it("should consolidate suite output", function(){
expect(reporter.getNestedOutput.callCount).toEqual(4);
});
it("should wrap output in <testsuites>", function(){
expect(reporter.writeFile.mostRecentCall.args[2]).toContain("<testsuites>");
});
it("should include xml header in every file", function(){
for (var i = 0; i < reporter.writeFile.callCount; i++) {
expect(reporter.writeFile.argsForCall[i][2]).toContain("<?xml");
}
});
});
describe("consolidated is false and consolidatedAll is false", function(){
beforeEach(function(){
reporter.consolidate = false;
reporter.reportRunnerResults(runner);
});
it("should write one file per suite", function(){
expect(reporter.writeFile.callCount).toEqual(4);
});
it("should not wrap results in <testsuites>", function(){
expect(reporter.writeFile.mostRecentCall.args[2]).not.toContain("<testsuites>");
});
it("should include xml header in every file", function(){
for (var i = 0; i < reporter.writeFile.callCount; i++) {
expect(reporter.writeFile.argsForCall[i][2]).toContain("<?xml");
}
});
});
describe("consolidatedAll is true", function(){
beforeEach(function(){
reporter.consolidateAll = true;
reporter.reportRunnerResults(runner);
});
it("should write one file for all test suites", function(){
expect(reporter.writeFile.callCount).toEqual(1);
});
it("should consolidate suites output", function(){
expect(reporter.getNestedOutput.callCount).toEqual(4);
});
it("should wrap output in <testsuites>", function(){
expect(reporter.writeFile.mostRecentCall.args[2]).toContain("<testsuites>");
});
it("should include xml header in the file", function(){
expect(reporter.writeFile.argsForCall[0][2]).toContain("<?xml");
});
});
describe("dot notation is true", function(){
beforeEach(function(){
reporter.reportRunnerResults(runner);
});
it("should separate descriptions with dot notation", function(){
expect(subSubSuite.output).toContain('classname="ParentSuite.SubSuite.SubSubSuite"');
});
});
describe("dot notation is false", function(){
beforeEach(function(){
reporter.useDotNotation = false;
triggerSuiteEvents([suite, subSuite, subSubSuite, siblingSuite]);
reporter.reportRunnerResults(runner);
});
it("should separate descriptions with whitespace", function(){
expect(subSubSuite.output).toContain('classname="ParentSuite SubSuite SubSubSuite"');
});
});
});
});
})();

View File

@@ -0,0 +1,164 @@
/* globals jasmine, describe, beforeEach, afterEach, it, expect, spyOn */
(function(){
var env, suite, subSuite, subSubSuite, siblingSuite, reporter, runner;
function fakeSpec(suite, name) {
var s = new jasmine.Spec(env, suite, name);
suite.add(s);
return s;
}
function fakeSuite(name, parentSuite) {
var s = new jasmine.Suite(env, name, null, parentSuite || null);
if (parentSuite) {
parentSuite.add(s);
}
runner.add(s);
return s;
}
// make sure reporter is set before calling this
function triggerSuiteEvents(suites) {
for (var i=0; i<suites.length; i++) {
var s = suites[i];
for (var j=0; j<s.specs().length; j++) {
reporter.reportSpecStarting(s.specs()[j]);
reporter.reportSpecResults(s.specs()[j]);
}
reporter.reportSuiteResults(s);
}
}
describe("NUnitXmlReporter", function(){
beforeEach(function(){
env = new jasmine.Env();
env.updateInterval = 0;
runner = new jasmine.Runner(env);
suite = fakeSuite("ParentSuite");
subSuite = fakeSuite("SubSuite", suite);
subSubSuite = fakeSuite("SubSubSuite", subSuite);
siblingSuite = fakeSuite("SiblingSuite With Invalid Chars & < > \" ' | : \\ /");
var spec = fakeSpec(suite, "should be a dummy with invalid characters: & < >");
var failedSpec = fakeSpec(suite, "should be failed");
failedSpec.fail(Error("I failed"));
var subSpec = fakeSpec(subSuite, "should be one level down");
var subSubSpec1 = fakeSpec(subSubSuite, "(1) should be two levels down");
var subSubSpec2 = fakeSpec(subSubSuite, "(2) should be two levels down");
var subSubSpec3 = fakeSpec(subSubSuite, "(3) should be two levels down");
var siblingSpec = fakeSpec(siblingSuite, "should be a sibling of Parent");
reporter = new jasmine.NUnitXmlReporter({reportName: "<Bad Character Report>"});
});
describe("constructor", function(){
it("should default path to an empty string", function(){
reporter = new jasmine.NUnitXmlReporter();
expect(reporter.savePath).toBe("");
});
it("should allow a custom path to be provided", function() {
reporter = new jasmine.NUnitXmlReporter({savePath:"/tmp"});
expect(reporter.savePath).toBe("/tmp");
});
it("should default filename to 'nunit-results.xml'", function(){
reporter = new jasmine.NUnitXmlReporter();
expect(reporter.filename).toBe("nunit-results.xml");
});
it("should allow a custom filename to be provided", function() {
reporter = new jasmine.NUnitXmlReporter({filename:"results.xml"});
expect(reporter.filename).toBe("results.xml");
});
it("should default reportName to 'Jasmine Results'", function(){
reporter = new jasmine.NUnitXmlReporter();
expect(reporter.reportName).toBe("Jasmine Results");
});
it("should allow a custom reportName to be provided", function() {
reporter = new jasmine.NUnitXmlReporter({reportName:"Test Results"});
expect(reporter.reportName).toBe("Test Results");
});
});
describe("reportRunnerResults", function(){
var output, xmldoc;
beforeEach(function(){
spyOn(reporter, "writeFile");
reporter.reportRunnerStarting(runner);
triggerSuiteEvents([suite, siblingSuite, subSuite, subSubSuite]);
reporter.reportRunnerResults(runner);
output = reporter.writeFile.mostRecentCall.args[0];
xmldoc = (new DOMParser()).parseFromString(output, "text/xml");
});
it("should escape invalid xml chars from report name", function() {
expect(output).toContain('name="&amp;lt;Bad Character Report&amp;gt;"');
});
it("should escape invalid xml chars from suite names", function() {
expect(output).toContain('name="SiblingSuite With Invalid Chars &amp; &amp;lt; &amp;gt; &amp;quot; &amp;apos; | : \\ /"');
});
it("should escape invalid xml chars from spec names", function() {
expect(output).toContain('name="should be a dummy with invalid characters: &amp; &amp;lt; &amp;gt;');
});
describe("xml structure", function() {
var rootNode, suites, specs;
beforeEach(function() {
rootNode = xmldoc.getElementsByTagName("test-results")[0];
suites = rootNode.getElementsByTagName("test-suite");
specs = rootNode.getElementsByTagName("test-case");
});
it("should report the date / time that the tests were run", function() {
function twoDigits(number) { return number >= 10 ? number : ("0" + number); }
var now = new Date();
var date = now.getFullYear() + "-" + twoDigits(now.getMonth()+1) + "-" + twoDigits(now.getDate());
var time = now.getHours() + ":" + twoDigits(now.getMinutes()) + ":" + twoDigits(now.getSeconds());
expect(rootNode.getAttribute("date")).toBe(date);
expect(rootNode.getAttribute("time")).toBe(time); // this could fail extremely rarely
});
it("should report the appropriate number of suites", function() {
expect(suites.length).toBe(4);
});
it("should order suites appropriately", function() {
expect(suites[0].getAttribute("name")).toContain("ParentSuite");
expect(suites[1].getAttribute("name")).toContain("SubSuite");
expect(suites[2].getAttribute("name")).toContain("SubSubSuite");
expect(suites[3].getAttribute("name")).toContain("SiblingSuite");
});
it("should nest suites appropriately", function() {
expect(suites[0].parentNode).toBe(rootNode);
expect(suites[1].parentNode).toBe(suites[0].getElementsByTagName("results")[0]);
expect(suites[2].parentNode).toBe(suites[1].getElementsByTagName("results")[0]);
expect(suites[3].parentNode).toBe(rootNode);
});
it("should report the execution time for test specs", function() {
var time;
for (var i = 0; i < specs.length; i++) {
time = specs[i].getAttribute("time");
expect(time.length).toBeGreaterThan(0);
expect(time).not.toContain(":"); // as partial seconds, not a timestamp
}
});
it("should include a test-case for each spec and report the total number of specs on the root node", function() {
expect(rootNode.getAttribute("total")).toBe(specs.length.toString());
});
describe("passed specs", function() {
it("should indicate that the test case was successful", function() {
expect(specs[0].getAttribute("success")).toBe("true");
});
});
describe("failed specs", function() {
var failedSpec;
beforeEach(function() {
failedSpec = rootNode.getElementsByTagName("message")[0].parentNode.parentNode;
});
it("should report the number of failed specs on the root node", function() {
expect(rootNode.getAttribute("failures")).toBe("1");
});
it("should indicate that the test case was not successful", function() {
expect(failedSpec.getAttribute("success")).toBe("false");
});
it("should include the error for failed specs", function() {
expect(failedSpec.getElementsByTagName("message")[0].textContent).toContain("I failed");
});
});
});
});
});
})();

View File

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Console Reporter Spec</title>
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" />
<script type="text/javascript" src="../ext/jasmine.js"></script>
<script type="text/javascript" src="../ext/jasmine-html.js"></script>
<script type="text/javascript" src="../src/jasmine.console_reporter.js"></script>
</head>
<body>
<script type="text/javascript">
describe("Basic Suite", function() {
it("Should pass a basic truthiness test.", function() {
expect(true).toEqual(true);
});
it("Should fail when it hits an inequal statement.", function() {
expect(1+1).toEqual(3);
});
});
describe("Another Suite", function() {
it("Should pass this test as well.", function() {
expect(0).toEqual(0);
});
});
jasmine.getEnv().addReporter(new jasmine.ConsoleReporter());
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

View File

@@ -0,0 +1,14 @@
load('../ext/env.rhino.1.2.js');
Envjs.scriptTypes['text/javascript'] = true;
var specFile;
for (i = 0; i < arguments.length; i++) {
specFile = arguments[i];
console.log("Loading: " + specFile);
window.location = specFile
}

View File

@@ -0,0 +1,7 @@
#!/bin/bash
# cleanup previous test runs
rm -f *.xml
# fire up the envjs environment
java -cp ../ext/js.jar:../ext/jline.jar org.mozilla.javascript.tools.shell.Main -opt -1 envjs.bootstrap.js $@

View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JUnit XML Reporter Spec</title>
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" />
<script type="text/javascript" src="../ext/jasmine.js"></script>
<script type="text/javascript" src="../ext/jasmine-html.js"></script>
<script type="text/javascript" src="../src/jasmine.junit_reporter.js"></script>
<!-- Include spec file -->
<script type="text/javascript" src="JUnitXmlReporterSpec.js"></script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JUnit XML Reporter Spec</title>
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" />
<script type="text/javascript" src="../ext/jasmine.js"></script>
<script type="text/javascript" src="../ext/jasmine-html.js"></script>
<script type="text/javascript" src="../src/jasmine.nunit_reporter.js"></script>
<script type="text/javascript" src="../src/jasmine.terminal_reporter.js"></script>
<!-- Include spec file -->
<script type="text/javascript" src="NUnitXmlReporterSpec.js"></script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().addReporter(new jasmine.NUnitXmlReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

View File

@@ -0,0 +1,223 @@
/* globals jasmine, phantom */
// Verify arguments
var system = require('system');
var args;
if(phantom.args) {
args = phantom.args;
} else {
args = system.args.slice(1);//use system args for phantom 2.0+
}
if (args.length === 0) {
console.log("Simple JasmineBDD test runner for phantom.js");
console.log("Usage: phantomjs-testrunner.js url_to_runner.html");
console.log("Accepts http:// and file:// urls");
console.log("");
console.log("NOTE: This script depends on jasmine.TrivialReporter being used\non the page, for the DOM elements it creates.\n");
phantom.exit(2);
}
else {
var fs = require("fs"),
pages = [],
page, address, resultsKey, i, l;
var setupPageFn = function(p, k) {
return function() {
overloadPageEvaluate(p);
setupWriteFileFunction(p, k, fs.separator);
};
};
for (i = 0, l = args.length; i < l; i++) {
address = args[i];
console.log("Loading " + address);
// if provided a url without a protocol, try to use file://
address = address.indexOf("://") === -1 ? "file://" + address : address;
// create a WebPage object to work with
page = require("webpage").create();
page.url = address;
// When initialized, inject the reporting functions before the page is loaded
// (and thus before it will try to utilize the functions)
resultsKey = "__jr" + Math.ceil(Math.random() * 1000000);
page.onInitialized = setupPageFn(page, resultsKey);
page.open(address, processPage(null, page, resultsKey));
pages.push(page);
page.onConsoleMessage = logAndWorkAroundDefaultLineBreaking;
}
// bail when all pages have been processed
setInterval(function(){
var exit_code = 0;
for (i = 0, l = pages.length; i < l; i++) {
page = pages[i];
if (page.__exit_code === null) {
// wait until later
return;
}
exit_code |= page.__exit_code;
}
phantom.exit(exit_code);
}, 100);
}
// Thanks to hoisting, these helpers are still available when needed above
/**
* Logs a message. Does not add a line-break for single characters '.' and 'F' or lines ending in ' ...'
*
* @param msg
*/
function logAndWorkAroundDefaultLineBreaking(msg) {
var interpretAsWithoutNewline = /(^(\033\[\d+m)*[\.F](\033\[\d+m)*$)|( \.\.\.$)/;
if (navigator.userAgent.indexOf("Windows") < 0 && interpretAsWithoutNewline.test(msg)) {
try {
system.stdout.write(msg);
} catch (e) {
var fs = require('fs');
fs.write('/dev/stdout', msg, 'w');
}
} else {
console.log(msg);
}
}
/**
* Stringifies the function, replacing any %placeholders% with mapped values.
*
* @param {function} fn The function to replace occurrences within.
* @param {object} replacements Key => Value object of string replacements.
*/
function replaceFunctionPlaceholders(fn, replacements) {
if (replacements && typeof replacements === "object") {
fn = fn.toString();
for (var p in replacements) {
if (replacements.hasOwnProperty(p)) {
var match = new RegExp("%" + p + "%", "g");
do {
fn = fn.replace(match, replacements[p]);
} while(fn.indexOf(match) !== -1);
}
}
}
return fn;
}
/**
* Replaces the "evaluate" method with one we can easily do substitution with.
*
* @param {phantomjs.WebPage} page The WebPage object to overload
*/
function overloadPageEvaluate(page) {
page._evaluate = page.evaluate;
page.evaluate = function(fn, replacements) { return page._evaluate(replaceFunctionPlaceholders(fn, replacements)); };
return page;
}
/** Stubs a fake writeFile function into the test runner.
*
* @param {phantomjs.WebPage} page The WebPage object to inject functions into.
* @param {string} key The name of the global object in which file data should
* be stored for later retrieval.
*/
// TODO: not bothering with error checking for now (closed environment)
function setupWriteFileFunction(page, key, path_separator) {
page.evaluate(function(){
window["%resultsObj%"] = {};
window.fs_path_separator = "%fs_path_separator%";
window.__phantom_writeFile = function(filename, text) {
window["%resultsObj%"][filename] = text;
};
}, {resultsObj: key, fs_path_separator: path_separator.replace("\\", "\\\\")});
}
/**
* Returns the loaded page's filename => output object.
*
* @param {phantomjs.WebPage} page The WebPage object to retrieve data from.
* @param {string} key The name of the global object to be returned. Should
* be the same key provided to setupWriteFileFunction.
*/
function getXmlResults(page, key) {
return page.evaluate(function(){
return window["%resultsObj%"] || {};
}, {resultsObj: key});
}
/**
* Processes a page.
*
* @param {string} status The status from opening the page via WebPage#open.
* @param {phantomjs.WebPage} page The WebPage to be processed.
*/
function processPage(status, page, resultsKey) {
if (status === null && page) {
page.__exit_code = null;
return function(stat){
processPage(stat, page, resultsKey);
};
}
if (status !== "success") {
console.error("Unable to load resource: " + address);
page.__exit_code = 2;
}
else {
var isFinished = function() {
return page.evaluate(function(){
// if there's a JUnitXmlReporter, return a boolean indicating if it is finished
if (jasmine && jasmine.JUnitXmlReporter && jasmine.JUnitXmlReporter.started_at !== null) {
return jasmine.JUnitXmlReporter.finished_at !== null;
}
// otherwise, see if there is anything in a "finished-at" element
return document.getElementsByClassName("finished-at").length &&
document.getElementsByClassName("finished-at")[0].innerHTML.length > 0;
});
};
var getResults = function() {
return page.evaluate(function(){
return document.getElementsByClassName("description").length &&
document.getElementsByClassName("description")[0].innerHTML.match(/(\d+) spec.* (\d+) failure.*/) ||
["Unable to determine success or failure."];
});
};
var timeout = 60000;
var loopInterval = 100;
var ival = setInterval(function(){
if (isFinished()) {
// get the results that need to be written to disk
var fs = require("fs"),
xml_results = getXmlResults(page, resultsKey),
output;
for (var filename in xml_results) {
if (xml_results.hasOwnProperty(filename) && (output = xml_results[filename]) && typeof(output) === "string") {
fs.write(filename, output, "w");
}
}
// print out a success / failure message of the results
var results = getResults();
var failures = Number(results[2]);
if (failures > 0) {
page.__exit_code = 1;
clearInterval(ival);
}
else {
page.__exit_code = 0;
clearInterval(ival);
}
}
else {
timeout -= loopInterval;
if (timeout <= 0) {
console.log('Page has timed out; aborting.');
page.__exit_code = 2;
clearInterval(ival);
}
}
}, loopInterval);
}
}

View File

@@ -0,0 +1,40 @@
#!/bin/bash
# sanity check to make sure phantomjs exists in the PATH
hash /usr/bin/env phantomjs &> /dev/null
if [ $? -eq 1 ]; then
echo "ERROR: phantomjs is not installed"
echo "Please visit http://www.phantomjs.org/"
exit 1
fi
# sanity check number of args
if [ $# -lt 1 ]
then
echo "Usage: `basename $0` path_to_runner.html"
echo
exit 1
fi
SCRIPTDIR=$(dirname `perl -e 'use Cwd "abs_path";print abs_path(shift)' $0`)
TESTFILE=""
while (( "$#" )); do
if [ ${1:0:7} == "http://" -o ${1:0:8} == "https://" ]; then
TESTFILE="$TESTFILE $1"
else
TESTFILE="$TESTFILE `perl -e 'use Cwd "abs_path";print abs_path(shift)' $1`"
fi
shift
done
# cleanup previous test runs
cd $SCRIPTDIR
rm -f *.xml
# make sure phantomjs submodule is initialized
cd ..
git submodule update --init
# fire up the phantomjs environment and run the test
cd $SCRIPTDIR
/usr/bin/env phantomjs $SCRIPTDIR/phantomjs-testrunner.js $TESTFILE

View File

@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Console Reporter Spec</title>
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" />
<script type="text/javascript" src="../ext/jasmine.js"></script>
<script type="text/javascript" src="../ext/jasmine-html.js"></script>
<script type="text/javascript" src="../src/jasmine.tap_reporter.js"></script>
</head>
<body>
<script type="text/javascript">
describe("Basic Suite", function() {
it("Should pass a basic truthiness test.", function() {
expect(true).toEqual(true);
expect(false).toEqual(false);
});
it("Should fail when it hits an inequal statement.", function() {
expect(1+1).toEqual(3);
});
});
describe("Another Suite", function() {
it("Should pass this test as well.", function() {
expect(0).toEqual(0);
});
});
jasmine.getEnv().addReporter(new jasmine.TapReporter());
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

View File

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Console Reporter Spec</title>
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" />
<script type="text/javascript" src="../ext/jasmine.js"></script>
<script type="text/javascript" src="../ext/jasmine-html.js"></script>
<script type="text/javascript" src="../src/jasmine.teamcity_reporter.js"></script>
</head>
<body>
<script type="text/javascript">
describe("Basic Suite", function() {
it("Should pass a basic truthiness test.", function() {
expect(true).toEqual(true);
});
it("Should fail when it hits an inequal statement.", function() {
expect(1+1).toEqual(3);
});
});
describe("Another Suite", function() {
it("Should pass this test as well.", function() {
expect(0).toEqual(0);
});
});
jasmine.getEnv().addReporter(new jasmine.TeamcityReporter());
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>

View File

@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Terminal Reporter Spec</title>
<link rel="stylesheet" href="../ext/jasmine.css" type="text/css" />
<script type="text/javascript" src="../ext/jasmine.js"></script>
<script type="text/javascript" src="../ext/jasmine-html.js"></script>
<script type="text/javascript" src="../src/jasmine.terminal_reporter.js"></script>
</head>
<body>
<script type="text/javascript">
describe("Basic Suite", function() {
it("Should pass a basic truthiness test.", function() {
expect(true).toEqual(true);
});
it("Should fail when it hits an inequal statement.", function() {
expect(1+1).toEqual(3);
});
});
describe("Another Suite", function() {
it("Should pass this test as well.", function() {
expect(0).toEqual(0);
});
});
jasmine.getEnv().addReporter(new jasmine.TerminalReporter({
verbosity: 3,
color: true
}));
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>