show javascript errors

This commit is contained in:
John Bintz 2011-04-12 07:10:03 -04:00
parent 4ac481c41d
commit 5229156bbd
2 changed files with 31 additions and 1 deletions

4
.gitignore vendored
View File

@ -2,3 +2,7 @@
.bundle .bundle
Gemfile.lock Gemfile.lock
pkg/* pkg/*
Makefile
specrunner.moc
specrunner.o
jasmine-webkit-specrunner

View File

@ -29,6 +29,20 @@
#error Use Qt 4.7 or later version #error Use Qt 4.7 or later version
#endif #endif
class HeadlessSpecRunnerPage: public QWebPage
{
Q_OBJECT
signals:
void consoleLog(const QString &msg, int lineNumber, const QString &sourceID);
protected:
void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
};
void HeadlessSpecRunnerPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID)
{
emit consoleLog(message, lineNumber, sourceID);
}
class HeadlessSpecRunner: public QObject class HeadlessSpecRunner: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -40,13 +54,15 @@ public slots:
void specLog(int indent, const QString &msg, const QString &clazz); void specLog(int indent, const QString &msg, const QString &clazz);
private slots: private slots:
void watch(bool ok); void watch(bool ok);
void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
protected: protected:
bool hasElement(const char *select); bool hasElement(const char *select);
void timerEvent(QTimerEvent *event); void timerEvent(QTimerEvent *event);
private: private:
QWebPage m_page; HeadlessSpecRunnerPage m_page;
QBasicTimer m_ticker; QBasicTimer m_ticker;
int m_runs; int m_runs;
bool hasErrors;
}; };
HeadlessSpecRunner::HeadlessSpecRunner() HeadlessSpecRunner::HeadlessSpecRunner()
@ -55,6 +71,8 @@ HeadlessSpecRunner::HeadlessSpecRunner()
{ {
m_page.settings()->enablePersistentStorage(); m_page.settings()->enablePersistentStorage();
connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString)));
hasErrors = false;
} }
void HeadlessSpecRunner::load(const QString &spec) void HeadlessSpecRunner::load(const QString &spec)
@ -81,6 +99,14 @@ bool HeadlessSpecRunner::hasElement(const char *select)
return !m_page.mainFrame()->findFirstElement(select).isNull(); return !m_page.mainFrame()->findFirstElement(select).isNull();
} }
void HeadlessSpecRunner::errorLog(const QString &msg, int lineNumber, const QString &sourceID)
{
std::cout << "\033[0;31m" << "[error] " << "\033[m;";
std::cout << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg);
std::cout << std::endl;
hasErrors = true;
}
void HeadlessSpecRunner::log(const QString &msg) void HeadlessSpecRunner::log(const QString &msg)
{ {
std::cout << "\033[0;32m" << "[console] " << "\033[m"; std::cout << "\033[0;32m" << "[console] " << "\033[m";