jasmine-headless-webkit 0.7.3.1 → 0.7.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/Guardfile +3 -2
  2. data/bin/jasmine-headless-webkit +1 -1
  3. data/ext/jasmine-webkit-specrunner/Page.cpp +8 -21
  4. data/ext/jasmine-webkit-specrunner/Page.h +11 -15
  5. data/ext/jasmine-webkit-specrunner/Runner.cpp +86 -110
  6. data/ext/jasmine-webkit-specrunner/Runner.h +23 -26
  7. data/ext/jasmine-webkit-specrunner/common.pri +2 -2
  8. data/ext/jasmine-webkit-specrunner/specrunner.cpp +0 -1
  9. data/ext/jasmine-webkit-specrunner/specrunner.pro +1 -0
  10. data/lib/jasmine/files_list.rb +24 -24
  11. data/lib/jasmine/headless.rb +1 -1
  12. data/lib/jasmine/headless/spec_file_analyzer.rb +1 -1
  13. data/lib/jasmine/headless/version.rb +1 -1
  14. data/lib/qt/qmake.rb +1 -5
  15. data/skel/template.html.erb +8 -45
  16. data/spec/files/UTF-8-test.txt +0 -0
  17. data/spec/javascripts/headless_reporter_result_spec.coffee +14 -0
  18. data/spec/javascripts/{jasmine.headless-reporter_spec.coffee → jasmine.HeadlessConsoleReporter_spec.coffee} +2 -2
  19. data/spec/javascripts/support/jasmine.yml +1 -1
  20. data/spec/lib/jasmine/files_list_spec.rb +6 -3
  21. data/spec/lib/jasmine/headless/spec_file_analyzer_spec.rb +41 -30
  22. data/spec/lib/qt/qmake_spec.rb +0 -6
  23. data/vendor/assets/coffeescripts/headless_reporter_result.coffee +46 -0
  24. data/vendor/assets/coffeescripts/intense.coffee +27 -0
  25. data/{jasmine/jasmine.headless-reporter.coffee → vendor/assets/coffeescripts/jasmine-extensions.coffee} +5 -90
  26. data/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee +86 -0
  27. data/vendor/assets/coffeescripts/prolog.coffee +73 -0
  28. data/{js-lib → vendor/assets/javascripts}/beautify-html.js +0 -0
  29. data/vendor/assets/javascripts/headless_reporter_result.js +72 -0
  30. data/vendor/assets/javascripts/intense.js +37 -0
  31. data/vendor/assets/javascripts/jasmine-extensions.js +101 -0
  32. data/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js +96 -0
  33. data/{js-lib → vendor/assets/javascripts}/jsDump.js +0 -0
  34. data/vendor/assets/javascripts/prolog.js +89 -0
  35. metadata +28 -33
  36. data/dev-bin/hooks/pre-commit +0 -5
  37. data/dev-bin/install-hooks +0 -6
  38. data/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp +0 -149
  39. data/ext/jasmine-webkit-specrunner/ConsoleOutput.h +0 -39
  40. data/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp +0 -129
  41. data/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h +0 -32
  42. data/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro +0 -7
  43. data/ext/jasmine-webkit-specrunner/Page_test.cpp +0 -43
  44. data/ext/jasmine-webkit-specrunner/Page_test.h +0 -27
  45. data/ext/jasmine-webkit-specrunner/Page_test.pro +0 -6
  46. data/ext/jasmine-webkit-specrunner/ReportFileOutput.cpp +0 -54
  47. data/ext/jasmine-webkit-specrunner/ReportFileOutput.h +0 -37
  48. data/ext/jasmine-webkit-specrunner/ReportFileOutput_test.cpp +0 -88
  49. data/ext/jasmine-webkit-specrunner/ReportFileOutput_test.h +0 -26
  50. data/ext/jasmine-webkit-specrunner/ReportFileOutput_test.pro +0 -7
  51. data/ext/jasmine-webkit-specrunner/test.pri +0 -3
  52. data/ext/jasmine-webkit-specrunner/test.rb +0 -31
  53. data/jasmine/jasmine.headless-reporter.js +0 -231
data/Guardfile CHANGED
@@ -3,6 +3,8 @@
3
3
  # watch('file/path') { `command(s)` }
4
4
  #
5
5
 
6
+ guard 'coffeescript', :input => 'vendor/assets/coffeescripts', :output => 'vendor/assets/javascripts'
7
+
6
8
  guard 'shell' do
7
9
  watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h|pro|pri)}) { |m|
8
10
  if !m[0]['moc_']
@@ -27,9 +29,8 @@ end
27
29
 
28
30
  def compile
29
31
  #system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb}
30
- system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb}
32
+ system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb}
31
33
  end
32
34
 
33
35
  compile
34
36
 
35
- guard 'coffeescript', :input => 'jasmine'
@@ -9,6 +9,7 @@ end
9
9
 
10
10
  $:.unshift(File.join(gem_dir, 'lib'))
11
11
  require 'jasmine-headless-webkit'
12
+ require 'coffee-script'
12
13
 
13
14
  begin
14
15
  options = Jasmine::Headless::Options.from_command_line
@@ -18,7 +19,6 @@ begin
18
19
  files_list = Jasmine::FilesList.new(:config => runner.jasmine_config)
19
20
  files_list.files.each { |file| puts file }
20
21
  else
21
- puts "Running Jasmine specs...".color(:white)
22
22
  exit runner.run
23
23
  end
24
24
  rescue CoffeeScript::CompilationError
@@ -4,26 +4,13 @@
4
4
 
5
5
  #include "Page.h"
6
6
 
7
- Page::Page() : QWebPage(), confirmResult(true) {}
7
+ Page::Page() : QWebPage() {}
8
8
 
9
- void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) {
10
- emit consoleLog(message, lineNumber, sourceID);
11
- }
9
+ void Page::javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID) {
10
+ emit handleError(message, lineNumber, sourceID);
11
+ }
12
12
 
13
- bool Page::javaScriptConfirm(QWebFrame*, const QString&) {
14
- if (confirmResult) {
15
- emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true.");
16
- return true;
17
- } else {
18
- confirmResult = true;
19
- return false;
20
- }
21
- }
22
-
23
- void Page::javaScriptAlert(QWebFrame*, const QString &msg) {
24
- emit internalLog("alert", msg);
25
- }
26
-
27
- void Page::oneFalseConfirm() {
28
- confirmResult = false;
29
- }
13
+ void Page::javaScriptAlert(QWebFrame *, const QString &) {}
14
+ bool Page::javaScriptConfirm(QWebFrame *, const QString &) {
15
+ return false;
16
+ }
@@ -4,20 +4,16 @@
4
4
  #include <QtGui>
5
5
  #include <QtWebKit>
6
6
 
7
- class Page: public QWebPage {
8
- Q_OBJECT
9
- public:
10
- Page();
11
- void oneFalseConfirm();
12
- signals:
13
- void consoleLog(const QString &msg, int lineNumber, const QString &sourceID);
14
- void internalLog(const QString &note, const QString &msg);
15
- protected:
16
- void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
17
- bool javaScriptConfirm(QWebFrame *frame, const QString &msg);
18
- void javaScriptAlert(QWebFrame *frame, const QString &msg);
19
- private:
20
- bool confirmResult;
21
- };
7
+ class Page: public QWebPage {
8
+ Q_OBJECT
9
+ public:
10
+ Page();
11
+ protected:
12
+ void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
13
+ void javaScriptAlert(QWebFrame *, const QString &);
14
+ bool javaScriptConfirm(QWebFrame *, const QString &);
15
+ signals:
16
+ void handleError(const QString & message, int lineNumber, const QString & sourceID);
17
+ };
22
18
 
23
19
  #endif
@@ -3,181 +3,157 @@
3
3
  #include <QFile>
4
4
  #include <QTextStream>
5
5
  #include <iostream>
6
+ #include <sstream>
6
7
  #include <QQueue>
7
8
 
8
9
  #include "Runner.h"
10
+ #include "Page.h"
9
11
 
10
12
  using namespace std;
11
13
 
12
14
  Runner::Runner() : QObject()
13
- , m_runs(0)
15
+ , runs(0)
14
16
  , hasErrors(false)
17
+ , _hasSpecFailure(false)
15
18
  , usedConsole(false)
16
19
  , isFinished(false)
17
- , didFail(false)
20
+ , useColors(false)
18
21
  {
19
- m_page.settings()->enablePersistentStorage();
20
- m_ticker.setInterval(TIMER_TICK);
22
+ page.settings()->enablePersistentStorage();
23
+ ticker.setInterval(TIMER_TICK);
21
24
 
22
- connect(&m_ticker, SIGNAL(timeout()), this, SLOT(timerEvent()));
23
- connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
24
- connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString)));
25
- connect(&m_page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString)));
26
- connect(m_page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW()));
25
+ connect(&ticker, SIGNAL(timeout()), this, SLOT(timerEvent()));
26
+ connect(&page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool)));
27
+ connect(&page, SIGNAL(handleError(const QString &, int, const QString &)), this, SLOT(handleError(const QString &, int, const QString &)));
28
+ connect(page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW()));
27
29
  }
28
30
 
29
31
  void Runner::addFile(const QString &spec) {
30
32
  runnerFiles.enqueue(spec);
31
33
  }
32
34
 
33
- void Runner::go()
34
- {
35
- m_ticker.stop();
36
- m_page.setPreferredContentsSize(QSize(1024, 600));
35
+ void Runner::go() {
36
+ ticker.stop();
37
+ page.setPreferredContentsSize(QSize(1024, 600));
37
38
  addJHW();
38
- loadSpec();
39
39
 
40
- m_ticker.start();
40
+ loadSpec();
41
41
  }
42
- void Runner::addJHW()
43
- {
44
- m_page.mainFrame()->addToJavaScriptWindowObject("JHW", this);
42
+ void Runner::addJHW() {
43
+ page.mainFrame()->addToJavaScriptWindowObject("JHW", this);
44
+ }
45
+
46
+ void Runner::handleError(const QString &message, int lineNumber, const QString &sourceID) {
47
+ QString messageEscaped = QString(message);
48
+ QString sourceIDEscaped = QString(sourceID);
49
+
50
+ messageEscaped.replace(QString("\""), QString("\\\""));
51
+ sourceIDEscaped.replace(QString("\""), QString("\\\""));
52
+
53
+ std::stringstream ss;
54
+ ss << lineNumber;
55
+
56
+ QString command("JHW._handleError(\"" + messageEscaped + "\", " + QString(ss.str().c_str()) + ", \"" + sourceIDEscaped + "\"); false;");
57
+
58
+ page.mainFrame()->evaluateJavaScript(command);
59
+
60
+ hasErrors = true;
45
61
  }
46
62
 
47
63
  void Runner::loadSpec()
48
64
  {
49
- m_page.mainFrame()->load(runnerFiles.dequeue());
50
- m_ticker.start();
65
+ if (reportFileName.isEmpty()) {
66
+ outputFile = 0;
67
+ ts = 0;
68
+ } else {
69
+ outputFile = new QFile(reportFileName);
70
+ outputFile->open(QIODevice::WriteOnly);
71
+
72
+ ts = new QTextStream(outputFile);
73
+ }
74
+
75
+ page.mainFrame()->load(runnerFiles.dequeue());
76
+ ticker.start();
51
77
  }
52
78
 
53
- void Runner::watch(bool ok)
54
- {
79
+ void Runner::watch(bool ok) {
55
80
  if (!ok) {
56
- std::cerr << "Can't load " << qPrintable(m_page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl;
81
+ std::cerr << "Can't load " << qPrintable(page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl;
57
82
  std::cerr << "Out of curiosity, did your tests try to submit a form and you haven't prevented that?" << std::endl;
58
83
  std::cerr << "Try running your tests in your browser with the Jasmine server and see what happens." << std::endl;
59
84
  QApplication::instance()->exit(1);
60
85
  return;
61
86
  }
62
87
 
63
- }
64
-
65
- bool Runner::hasElement(const char *select)
66
- {
67
- return !m_page.mainFrame()->findFirstElement(select).isNull();
88
+ page.mainFrame()->evaluateJavaScript(QString("JHW._setColors(") + (useColors ? QString("true") : QString("false")) + QString("); false;"));
68
89
  }
69
90
 
70
91
  void Runner::setColors(bool colors) {
71
- consoleOutput.showColors = colors;
92
+ useColors = colors;
72
93
  }
73
94
 
74
- void Runner::reportFile(const QString &file) {
75
- reportFileName = file;
76
- }
77
-
78
- bool Runner::hasError() {
79
- return hasErrors;
80
- }
81
-
82
- void Runner::timerPause() {
83
- m_ticker.stop();
84
- }
85
-
86
- void Runner::timerDone() {
87
- m_ticker.start();
88
- }
89
-
90
- void Runner::specPassed(const QString &specDetail) {
91
- consoleOutput.passed(specDetail);
92
- reportFileOutput.passed(specDetail);
93
- }
94
-
95
- void Runner::specFailed(const QString &specDetail) {
96
- consoleOutput.failed(specDetail);
97
- reportFileOutput.failed(specDetail);
98
-
99
- didFail = true;
100
- failedSpecs.push(specDetail);
95
+ void Runner::hasUsedConsole() {
96
+ usedConsole = true;
101
97
  }
102
98
 
103
- void Runner::errorLog(const QString &msg, int lineNumber, const QString &sourceID)
104
- {
105
- consoleOutput.errorLog(msg, lineNumber, sourceID);
106
- reportFileOutput.errorLog(msg, lineNumber, sourceID);
107
-
99
+ void Runner::hasError() {
108
100
  hasErrors = true;
109
- m_runs = 0;
110
- m_ticker.start();
111
101
  }
112
102
 
113
- void Runner::internalLog(const QString &note, const QString &msg) {
114
- consoleOutput.internalLog(note, msg);
115
- reportFileOutput.internalLog(note, msg);
103
+ void Runner::hasSpecFailure() {
104
+ _hasSpecFailure = true;
116
105
  }
117
106
 
118
- void Runner::log(const QString &msg)
119
- {
120
- usedConsole = true;
121
- consoleOutput.consoleLog(msg);
122
- reportFileOutput.consoleLog(msg);
107
+ void Runner::reportFile(const QString &file) {
108
+ reportFileName = file;
123
109
  }
124
110
 
125
- void Runner::leavePageAttempt(const QString &msg)
126
- {
127
- consoleOutput.internalLog("error", msg);
128
- m_page.oneFalseConfirm();
129
- hasErrors = true;
111
+ void Runner::timerPause() {
112
+ ticker.stop();
130
113
  }
131
114
 
132
- void Runner::printName(const QString &name)
133
- {
134
- consoleOutput.logSpecFilename(name);
115
+ void Runner::timerDone() {
116
+ ticker.start();
135
117
  }
136
118
 
137
- void Runner::printResult(const QString &result)
138
- {
139
- consoleOutput.logSpecResult(result);
119
+ void Runner::ping() {
120
+ runs = 0;
140
121
  }
141
122
 
142
- void Runner::finishSuite(const QString &duration, const QString &total, const QString& failed)
143
- {
144
- if (didFail) {
145
- consoleOutput.reportFailure(total, failed, duration);
146
- reportFileOutput.reportFailure(total, failed, duration);
147
- } else {
148
- if (hasErrors) {
149
- consoleOutput.reportSuccessWithJSErrors(total, failed, duration);
150
- reportFileOutput.reportSuccessWithJSErrors(total, failed, duration);
151
- } else {
152
- consoleOutput.reportSuccess(total, failed, duration);
153
- reportFileOutput.reportSuccess(total, failed, duration);
154
- }
123
+ void Runner::print(const QString &fh, const QString &content) {
124
+ if (fh == "stdout") {
125
+ std::cout << qPrintable(content);
126
+ std::cout.flush();
155
127
  }
156
128
 
157
- if (!reportFileName.isEmpty()) {
158
- QFile outputFile(reportFileName);
159
- outputFile.open(QIODevice::WriteOnly);
160
-
161
- QTextStream ts(&outputFile);
162
-
163
- ts << reportFileOutput.outputIO->str().c_str();
129
+ if (fh == "stderr") {
130
+ std::cerr << qPrintable(content);
131
+ std::cerr.flush();
132
+ }
164
133
 
165
- outputFile.close();
134
+ if (fh == "report" && outputFile) {
135
+ *ts << qPrintable(content);
136
+ ts->flush();
166
137
  }
138
+ }
167
139
 
140
+ void Runner::finishSuite() {
168
141
  isFinished = true;
169
142
  }
170
143
 
171
- void Runner::timerEvent()
172
- {
173
- ++m_runs;
144
+ void Runner::timerEvent() {
145
+ ++runs;
174
146
 
175
- if (hasErrors && m_runs > 2)
147
+ if (hasErrors && runs > 2)
176
148
  QApplication::instance()->exit(1);
177
149
 
178
150
  if (isFinished) {
151
+ if (outputFile) {
152
+ outputFile->close();
153
+ }
154
+
179
155
  int exitCode = 0;
180
- if (didFail || hasErrors) {
156
+ if (_hasSpecFailure || hasErrors) {
181
157
  exitCode = 1;
182
158
  } else {
183
159
  if (usedConsole) {
@@ -203,8 +179,8 @@ void Runner::timerEvent()
203
179
  }
204
180
  }
205
181
 
206
- if (m_runs > MAX_LOOPS) {
207
- std::cout << "WARNING: too many runs and the test is still not finished!" << std::endl;
182
+ if (runs > MAX_LOOPS) {
183
+ std::cerr << "WARNING: too many runs and the test is still not finished!" << std::endl;
208
184
  QApplication::instance()->exit(1);
209
185
  }
210
186
  }
@@ -10,57 +10,54 @@
10
10
  #include <QQueue>
11
11
 
12
12
  #include "Page.h"
13
- #include "ConsoleOutput.h"
14
- #include "ReportFileOutput.h"
15
13
 
16
14
  using namespace std;
17
15
 
18
16
  class Runner: public QObject {
19
17
  Q_OBJECT
20
18
  public:
21
- enum { TIMER_TICK = 200, MAX_LOOPS = 25 };
19
+ enum { TIMER_TICK = 200, MAX_LOOPS = 50 };
22
20
 
23
21
  Runner();
24
22
  void setColors(bool colors);
25
23
  void reportFile(const QString &file);
26
24
  void addFile(const QString &spec);
27
25
  void go();
28
- public slots:
29
- void log(const QString &msg);
30
- bool hasError();
31
- void leavePageAttempt(const QString &msg);
26
+
27
+ public slots:
32
28
  void timerPause();
33
29
  void timerDone();
34
- void specPassed(const QString &specDetail);
35
- void specFailed(const QString &specDetail);
36
- void printName(const QString &name);
37
- void printResult(const QString &result);
38
- void finishSuite(const QString &duration, const QString &total, const QString& failed);
39
- private slots:
40
- void watch(bool ok);
41
- void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
42
- void internalLog(const QString &note, const QString &msg);
30
+ void hasUsedConsole();
31
+ void hasError();
32
+ void hasSpecFailure();
33
+ void print(const QString &fh, const QString &content);
34
+ void finishSuite();
35
+ void ping();
36
+
37
+ private slots:
38
+ void watch(bool ok);
43
39
  void addJHW();
44
40
  void timerEvent();
45
- protected:
46
- bool hasElement(const char *select);
41
+ void handleError(const QString & message, int lineNumber, const QString & sourceID);
42
+
47
43
  private:
48
- Page m_page;
49
- QTimer m_ticker;
50
- int m_runs;
44
+ Page page;
45
+ QTimer ticker;
46
+ int runs;
51
47
  bool hasErrors;
48
+ bool _hasSpecFailure;
52
49
  bool usedConsole;
53
50
  bool isFinished;
54
- bool didFail;
55
- QQueue<QString> runnerFiles;
56
- QStack<QString> failedSpecs;
51
+ bool useColors;
57
52
 
58
- ConsoleOutput consoleOutput;
59
- ReportFileOutput reportFileOutput;
53
+ QQueue<QString> runnerFiles;
60
54
 
61
55
  QString reportFileName;
62
56
 
63
57
  void loadSpec();
58
+
59
+ QFile *outputFile;
60
+ QTextStream *ts;
64
61
  };
65
62
 
66
63
  #endif