last set of changes
This commit is contained in:
parent
d9ade573c9
commit
298e8c2d3d
@ -9,3 +9,8 @@ Page::Page() : QWebPage() {}
|
||||
void Page::javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID) {
|
||||
emit handleError(message, lineNumber, sourceID);
|
||||
}
|
||||
|
||||
void Page::javaScriptAlert(QWebFrame *, const QString &) {}
|
||||
bool Page::javaScriptConfirm(QWebFrame *, const QString &) {
|
||||
return false;
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ class Page: public QWebPage {
|
||||
Page();
|
||||
protected:
|
||||
void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
|
||||
void javaScriptAlert(QWebFrame *, const QString &);
|
||||
bool javaScriptConfirm(QWebFrame *, const QString &);
|
||||
signals:
|
||||
void handleError(const QString & message, int lineNumber, const QString & sourceID);
|
||||
};
|
||||
|
@ -12,20 +12,19 @@
|
||||
using namespace std;
|
||||
|
||||
Runner::Runner() : QObject()
|
||||
, m_runs(0)
|
||||
, runs(0)
|
||||
, hasErrors(false)
|
||||
, usedConsole(false)
|
||||
, isFinished(false)
|
||||
, didFail(false)
|
||||
, useColors(false)
|
||||
{
|
||||
m_page.settings()->enablePersistentStorage();
|
||||
m_ticker.setInterval(TIMER_TICK);
|
||||
page.settings()->enablePersistentStorage();
|
||||
ticker.setInterval(TIMER_TICK);
|
||||
|
||||
connect(&m_ticker, SIGNAL(timeout()), this, SLOT(timerEvent()));
|
||||
connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
|
||||
connect(&m_page, SIGNAL(handleError(const QString &, int, const QString &)), this, SLOT(handleError(const QString &, int, const QString &)));
|
||||
connect(m_page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW()));
|
||||
connect(&ticker, SIGNAL(timeout()), this, SLOT(timerEvent()));
|
||||
connect(&page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
|
||||
connect(&page, SIGNAL(handleError(const QString &, int, const QString &)), this, SLOT(handleError(const QString &, int, const QString &)));
|
||||
connect(page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW()));
|
||||
}
|
||||
|
||||
void Runner::addFile(const QString &spec) {
|
||||
@ -33,14 +32,14 @@ void Runner::addFile(const QString &spec) {
|
||||
}
|
||||
|
||||
void Runner::go() {
|
||||
m_ticker.stop();
|
||||
m_page.setPreferredContentsSize(QSize(1024, 600));
|
||||
ticker.stop();
|
||||
page.setPreferredContentsSize(QSize(1024, 600));
|
||||
addJHW();
|
||||
|
||||
loadSpec();
|
||||
}
|
||||
void Runner::addJHW() {
|
||||
m_page.mainFrame()->addToJavaScriptWindowObject("JHW", this);
|
||||
page.mainFrame()->addToJavaScriptWindowObject("JHW", this);
|
||||
}
|
||||
|
||||
void Runner::handleError(const QString &message, int lineNumber, const QString &sourceID) {
|
||||
@ -55,7 +54,7 @@ void Runner::handleError(const QString &message, int lineNumber, const QString &
|
||||
|
||||
QString command("JHW._handleError(\"" + messageEscaped + "\", " + QString(ss.str().c_str()) + ", \"" + sourceIDEscaped + "\"); false;");
|
||||
|
||||
m_page.mainFrame()->evaluateJavaScript(command);
|
||||
page.mainFrame()->evaluateJavaScript(command);
|
||||
|
||||
hasErrors = true;
|
||||
}
|
||||
@ -72,20 +71,20 @@ void Runner::loadSpec()
|
||||
ts = new QTextStream(outputFile);
|
||||
}
|
||||
|
||||
m_page.mainFrame()->load(runnerFiles.dequeue());
|
||||
m_ticker.start();
|
||||
page.mainFrame()->load(runnerFiles.dequeue());
|
||||
ticker.start();
|
||||
}
|
||||
|
||||
void Runner::watch(bool ok) {
|
||||
if (!ok) {
|
||||
std::cerr << "Can't load " << qPrintable(m_page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl;
|
||||
std::cerr << "Can't load " << qPrintable(page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl;
|
||||
std::cerr << "Out of curiosity, did your tests try to submit a form and you haven't prevented that?" << std::endl;
|
||||
std::cerr << "Try running your tests in your browser with the Jasmine server and see what happens." << std::endl;
|
||||
QApplication::instance()->exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
m_page.mainFrame()->evaluateJavaScript(QString("JHW._setColors(") + (useColors ? QString("true") : QString("false")) + QString("); false;"));
|
||||
page.mainFrame()->evaluateJavaScript(QString("JHW._setColors(") + (useColors ? QString("true") : QString("false")) + QString("); false;"));
|
||||
}
|
||||
|
||||
void Runner::setColors(bool colors) {
|
||||
@ -96,16 +95,20 @@ void Runner::hasUsedConsole() {
|
||||
usedConsole = true;
|
||||
}
|
||||
|
||||
void Runner::hasError() {
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
void Runner::reportFile(const QString &file) {
|
||||
reportFileName = file;
|
||||
}
|
||||
|
||||
void Runner::timerPause() {
|
||||
m_ticker.stop();
|
||||
ticker.stop();
|
||||
}
|
||||
|
||||
void Runner::timerDone() {
|
||||
m_ticker.start();
|
||||
ticker.start();
|
||||
}
|
||||
|
||||
void Runner::print(const QString &fh, const QString &content) {
|
||||
@ -130,9 +133,9 @@ void Runner::finishSuite() {
|
||||
}
|
||||
|
||||
void Runner::timerEvent() {
|
||||
++m_runs;
|
||||
++runs;
|
||||
|
||||
if (hasErrors && m_runs > 2)
|
||||
if (hasErrors && runs > 2)
|
||||
QApplication::instance()->exit(1);
|
||||
|
||||
if (isFinished) {
|
||||
@ -141,7 +144,7 @@ void Runner::timerEvent() {
|
||||
}
|
||||
|
||||
int exitCode = 0;
|
||||
if (didFail || hasErrors) {
|
||||
if (hasErrors) {
|
||||
exitCode = 1;
|
||||
} else {
|
||||
if (usedConsole) {
|
||||
@ -167,8 +170,8 @@ void Runner::timerEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
if (m_runs > MAX_LOOPS) {
|
||||
std::cout << "WARNING: too many runs and the test is still not finished!" << std::endl;
|
||||
if (runs > MAX_LOOPS) {
|
||||
std::cerr << "WARNING: too many runs and the test is still not finished!" << std::endl;
|
||||
QApplication::instance()->exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -23,28 +23,28 @@ class Runner: public QObject {
|
||||
void reportFile(const QString &file);
|
||||
void addFile(const QString &spec);
|
||||
void go();
|
||||
|
||||
public slots:
|
||||
void timerPause();
|
||||
void timerDone();
|
||||
|
||||
void hasUsedConsole();
|
||||
|
||||
void hasError();
|
||||
void print(const QString &fh, const QString &content);
|
||||
|
||||
void finishSuite();
|
||||
|
||||
private slots:
|
||||
void watch(bool ok);
|
||||
void addJHW();
|
||||
void timerEvent();
|
||||
void handleError(const QString & message, int lineNumber, const QString & sourceID);
|
||||
|
||||
private:
|
||||
Page m_page;
|
||||
QTimer m_ticker;
|
||||
int m_runs;
|
||||
Page page;
|
||||
QTimer ticker;
|
||||
int runs;
|
||||
bool hasErrors;
|
||||
bool usedConsole;
|
||||
bool isFinished;
|
||||
bool didFail;
|
||||
bool useColors;
|
||||
|
||||
QQueue<QString> runnerFiles;
|
||||
|
@ -2,8 +2,10 @@
|
||||
class window.HeadlessReporterResult
|
||||
constructor: (@name, @splitName) ->
|
||||
@results = []
|
||||
|
||||
addResult: (message) ->
|
||||
@results.push(message)
|
||||
|
||||
print: ->
|
||||
output = @name.foreground('red')
|
||||
bestChoice = HeadlessReporterResult.findSpecLine(@splitName)
|
||||
@ -16,6 +18,7 @@ class window.HeadlessReporterResult
|
||||
output += " (line ~#{bestChoice.lineNumber + result.lineNumber})".foreground('red').bright()
|
||||
JHW.stdout.puts(" " + output)
|
||||
JHW.stdout.puts(" #{result.line}".foreground('yellow'))
|
||||
|
||||
@findSpecLine: (splitName) ->
|
||||
bestChoice = { accuracy: 0, file: null, lineNumber: null }
|
||||
|
||||
@ -37,5 +40,5 @@ class window.HeadlessReporterResult
|
||||
|
||||
if index > bestChoice.accuracy
|
||||
bestChoice = { accuracy: index, file: file, lineNumber: lineNumber }
|
||||
|
||||
|
||||
bestChoice
|
||||
|
@ -24,18 +24,22 @@ class jasmine.HeadlessReporter
|
||||
else
|
||||
JHW.stdout.puts("FAIL: #{resultLine}".foreground('red'))
|
||||
|
||||
output = "TOTAL||#{@length}||#{@failedCount}||#{runtime}||#{if JHW._hasErrors then "T" else "F"}"
|
||||
|
||||
JHW.report.puts(output)
|
||||
result.print() for result in @results
|
||||
|
||||
JHW.finishSuite()
|
||||
|
||||
reportRunnerStarting: (runner) ->
|
||||
@startTime = new Date()
|
||||
JHW.stdout.puts("Running Jasmine specs...")
|
||||
JHW.stdout.puts("\nRunning Jasmine specs...".bright())
|
||||
|
||||
reportSpecResults: (spec) ->
|
||||
return if this.hasError()
|
||||
|
||||
results = spec.results()
|
||||
|
||||
@length++
|
||||
if results.passed()
|
||||
JHW.stdout.print('.'.foreground('green'))
|
||||
@ -43,9 +47,12 @@ class jasmine.HeadlessReporter
|
||||
else
|
||||
JHW.stdout.print('F'.foreground('red'))
|
||||
JHW.report.puts("FAIL||" + spec.getJHWSpecInformation())
|
||||
JHW.hasError()
|
||||
|
||||
@failedCount++
|
||||
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName())
|
||||
testCount = 1
|
||||
|
||||
for result in results.getItems()
|
||||
if result.type == 'expect' and !result.passed_
|
||||
if foundLine = result.expectations[testCount - 1]
|
||||
|
@ -10,7 +10,7 @@
|
||||
this.length = 0;
|
||||
}
|
||||
HeadlessReporter.prototype.reportRunnerResults = function(runner) {
|
||||
var result, resultLine, runtime, _i, _len, _ref;
|
||||
var output, result, resultLine, runtime, _i, _len, _ref;
|
||||
if (this.hasError()) {
|
||||
return;
|
||||
}
|
||||
@ -25,6 +25,8 @@
|
||||
} else {
|
||||
JHW.stdout.puts(("FAIL: " + resultLine).foreground('red'));
|
||||
}
|
||||
output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + runtime + "||" + (JHW._hasErrors ? "T" : "F");
|
||||
JHW.report.puts(output);
|
||||
_ref = this.results;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
result = _ref[_i];
|
||||
@ -34,7 +36,7 @@
|
||||
};
|
||||
HeadlessReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
this.startTime = new Date();
|
||||
return JHW.stdout.puts("Running Jasmine specs...");
|
||||
return JHW.stdout.puts("\nRunning Jasmine specs...".bright());
|
||||
};
|
||||
HeadlessReporter.prototype.reportSpecResults = function(spec) {
|
||||
var failureResult, foundLine, result, results, testCount, _i, _len, _ref;
|
||||
@ -49,6 +51,7 @@
|
||||
} else {
|
||||
JHW.stdout.print('F'.foreground('red'));
|
||||
JHW.report.puts("FAIL||" + spec.getJHWSpecInformation());
|
||||
JHW.hasError();
|
||||
this.failedCount++;
|
||||
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName());
|
||||
testCount = 1;
|
||||
|
@ -25,21 +25,16 @@ if window.JHW
|
||||
data
|
||||
|
||||
window.onbeforeunload = (e) ->
|
||||
JHW.leavePageAttempt()
|
||||
|
||||
JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.')
|
||||
|
||||
if e = e || window.event
|
||||
e.returnValue = "leaving"
|
||||
|
||||
return "leaving"
|
||||
JHW.hasError()
|
||||
return false
|
||||
|
||||
window.confirm = (message) ->
|
||||
JHW.stderr.puts("jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.")
|
||||
JHW.stderr.puts("#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.")
|
||||
true
|
||||
|
||||
window.alert = (message) ->
|
||||
JHW.stderr.puts(message)
|
||||
JHW.stderr.puts("[alert] ".foreground('red') + message)
|
||||
|
||||
JHW._hasErrors = false
|
||||
|
||||
@ -48,8 +43,8 @@ if window.JHW
|
||||
JHW._hasErrors = true
|
||||
false
|
||||
|
||||
JHW._setColors = (what) ->
|
||||
Intense.useColors = what
|
||||
JHW._setColors = (useColors) ->
|
||||
Intense.useColors = useColors
|
||||
|
||||
createHandle = (handle) ->
|
||||
JHW[handle] =
|
||||
@ -58,7 +53,11 @@ if window.JHW
|
||||
|
||||
createHandle(handle) for handle in [ 'stdout', 'stderr', 'report' ]
|
||||
|
||||
JHW._usedConsole = false
|
||||
|
||||
JHW.log = (msg) ->
|
||||
JHW.usedConsole()
|
||||
JHW.hasUsedConsole()
|
||||
JHW.report.puts("CONSOLE||#{msg}")
|
||||
JHW._usedConsole = true
|
||||
JHW.stdout.puts(msg)
|
||||
|
||||
|
@ -37,19 +37,16 @@
|
||||
}
|
||||
};
|
||||
window.onbeforeunload = function(e) {
|
||||
JHW.leavePageAttempt();
|
||||
JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.');
|
||||
if (e = e || window.event) {
|
||||
e.returnValue = "leaving";
|
||||
}
|
||||
return "leaving";
|
||||
JHW.hasError();
|
||||
return false;
|
||||
};
|
||||
window.confirm = function(message) {
|
||||
JHW.stderr.puts("jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.");
|
||||
JHW.stderr.puts("" + ("[confirm]".foreground('red')) + " jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.");
|
||||
return true;
|
||||
};
|
||||
window.alert = function(message) {
|
||||
return JHW.stderr.puts(message);
|
||||
return JHW.stderr.puts("[alert] ".foreground('red') + message);
|
||||
};
|
||||
JHW._hasErrors = false;
|
||||
JHW._handleError = function(message, lineNumber, sourceURL) {
|
||||
@ -57,8 +54,8 @@
|
||||
JHW._hasErrors = true;
|
||||
return false;
|
||||
};
|
||||
JHW._setColors = function(what) {
|
||||
return Intense.useColors = what;
|
||||
JHW._setColors = function(useColors) {
|
||||
return Intense.useColors = useColors;
|
||||
};
|
||||
createHandle = function(handle) {
|
||||
return JHW[handle] = {
|
||||
@ -75,8 +72,11 @@
|
||||
handle = _ref[_i];
|
||||
createHandle(handle);
|
||||
}
|
||||
JHW._usedConsole = false;
|
||||
JHW.log = function(msg) {
|
||||
JHW.usedConsole();
|
||||
JHW.hasUsedConsole();
|
||||
JHW.report.puts("CONSOLE||" + msg);
|
||||
JHW._usedConsole = true;
|
||||
return JHW.stdout.puts(msg);
|
||||
};
|
||||
}
|
||||
|
14
spec/javascripts/headless_reporter_result_spec.coffee
Normal file
14
spec/javascripts/headless_reporter_result_spec.coffee
Normal file
@ -0,0 +1,14 @@
|
||||
describe 'HeadlessReporterResult', ->
|
||||
result = null
|
||||
name = "name"
|
||||
splitName = "splitName"
|
||||
message = 'message'
|
||||
|
||||
beforeEach ->
|
||||
result = new HeadlessReporterResult(name, splitName)
|
||||
|
||||
describe '#addResult', ->
|
||||
it 'should add a message', ->
|
||||
result.addResult(message)
|
||||
|
||||
expect(result.results).toEqual([ message ])
|
@ -14,6 +14,9 @@ describe Jasmine::FilesList do
|
||||
File.join(Jasmine::Core.path, "jasmine.js"),
|
||||
File.join(Jasmine::Core.path, "jasmine-html.js"),
|
||||
File.join(Jasmine::Core.path, "jasmine.css"),
|
||||
File.expand_path('jasmine/jasmine-extensions.js'),
|
||||
File.expand_path('jasmine/intense.js'),
|
||||
File.expand_path('jasmine/headless_reporter_result.js'),
|
||||
File.expand_path('jasmine/jasmine.headless-reporter.js'),
|
||||
File.expand_path('js-lib/jsDump.js'),
|
||||
File.expand_path('js-lib/beautify-html.js'),
|
||||
|
Loading…
Reference in New Issue
Block a user