jasmine-headless-webkit 0.6.3 → 0.7.0

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 (78) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +3 -1
  3. data/Guardfile +7 -2
  4. data/Rakefile +1 -0
  5. data/bin/jasmine-headless-webkit +15 -2
  6. data/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp +140 -0
  7. data/ext/jasmine-webkit-specrunner/ConsoleOutput.h +38 -0
  8. data/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp +129 -0
  9. data/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h +32 -0
  10. data/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro +7 -0
  11. data/ext/jasmine-webkit-specrunner/Makefile.dummy +5 -0
  12. data/ext/jasmine-webkit-specrunner/{HeadlessSpecRunner/Page.cpp → Page.cpp} +3 -4
  13. data/ext/jasmine-webkit-specrunner/{HeadlessSpecRunner/Page.h → Page.h} +0 -2
  14. data/ext/jasmine-webkit-specrunner/Page_test.cpp +43 -0
  15. data/ext/jasmine-webkit-specrunner/Page_test.h +27 -0
  16. data/ext/jasmine-webkit-specrunner/Page_test.pro +6 -0
  17. data/ext/jasmine-webkit-specrunner/ReportFileOutput.cpp +54 -0
  18. data/ext/jasmine-webkit-specrunner/ReportFileOutput.h +37 -0
  19. data/ext/jasmine-webkit-specrunner/ReportFileOutput_test.cpp +88 -0
  20. data/ext/jasmine-webkit-specrunner/ReportFileOutput_test.h +26 -0
  21. data/ext/jasmine-webkit-specrunner/ReportFileOutput_test.pro +7 -0
  22. data/ext/jasmine-webkit-specrunner/Runner.cpp +211 -0
  23. data/ext/jasmine-webkit-specrunner/Runner.h +66 -0
  24. data/ext/jasmine-webkit-specrunner/common.pri +9 -0
  25. data/ext/jasmine-webkit-specrunner/extconf.rb +3 -1
  26. data/ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner.pro +19 -0
  27. data/ext/jasmine-webkit-specrunner/specrunner.cpp +5 -3
  28. data/ext/jasmine-webkit-specrunner/specrunner.pro +3 -7
  29. data/ext/jasmine-webkit-specrunner/test.pri +3 -0
  30. data/ext/jasmine-webkit-specrunner/test.rb +24 -0
  31. data/jasmine/jasmine.headless-reporter.coffee +47 -15
  32. data/jasmine/jasmine.headless-reporter.js +42 -17
  33. data/jasmine-headless-webkit.gemspec +2 -2
  34. data/js-lib/beautify-html.js +463 -0
  35. data/js-lib/jsDump.js +209 -0
  36. data/lib/jasmine/files_list.rb +35 -64
  37. data/lib/jasmine/headless/cacheable_action.rb +77 -0
  38. data/lib/jasmine/headless/coffee_script_cache.rb +20 -0
  39. data/lib/jasmine/headless/errors.rb +1 -0
  40. data/lib/jasmine/headless/options.rb +14 -2
  41. data/lib/jasmine/headless/railtie.rb +0 -2
  42. data/lib/jasmine/headless/report.rb +76 -0
  43. data/lib/jasmine/headless/report_message/console.rb +20 -0
  44. data/lib/jasmine/headless/report_message/error.rb +20 -0
  45. data/lib/jasmine/headless/report_message/fail.rb +5 -0
  46. data/lib/jasmine/headless/report_message/pass.rb +5 -0
  47. data/lib/jasmine/headless/report_message/spec.rb +30 -0
  48. data/lib/jasmine/headless/report_message/total.rb +31 -0
  49. data/lib/jasmine/headless/report_message.rb +11 -0
  50. data/lib/jasmine/headless/runner.rb +2 -6
  51. data/lib/jasmine/headless/spec_file_analyzer.rb +37 -0
  52. data/lib/jasmine/headless/task.rb +0 -2
  53. data/lib/jasmine/headless/version.rb +5 -0
  54. data/lib/jasmine/template_writer.rb +17 -2
  55. data/lib/jasmine-headless-webkit.rb +15 -2
  56. data/lib/qt/qmake.rb +61 -30
  57. data/script/gemfile +11 -0
  58. data/script/hooks/pre-commit +15 -0
  59. data/script/initialize-environment +35 -0
  60. data/script/install-git-hooks +6 -0
  61. data/spec/bin/jasmine-headless-webkit_spec.rb +10 -0
  62. data/spec/javascripts/jasmine.headless-reporter_spec.coffee +63 -5
  63. data/spec/lib/jasmine/files_list_spec.rb +37 -116
  64. data/spec/lib/jasmine/headless/cacheable_action_spec.rb +89 -0
  65. data/spec/lib/jasmine/headless/coffee_script_cache_spec.rb +21 -0
  66. data/spec/lib/jasmine/headless/options_spec.rb +3 -5
  67. data/spec/lib/jasmine/headless/report_message/spec_spec.rb +20 -0
  68. data/spec/lib/jasmine/headless/report_spec.rb +79 -0
  69. data/spec/lib/jasmine/headless/runner_spec.rb +5 -1
  70. data/spec/lib/jasmine/headless/spec_file_analyzer_spec.rb +57 -0
  71. data/spec/lib/qt/qmake_spec.rb +15 -2
  72. data/spec/spec_helper.rb +35 -22
  73. metadata +109 -19
  74. data/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/ConsoleOutput.cpp +0 -0
  75. data/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/ConsoleOutput.h +0 -0
  76. data/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp +0 -270
  77. data/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h +0 -61
  78. data/lib/jasmine-headless-webkit/version.rb +0 -7
data/.gitignore CHANGED
@@ -10,3 +10,6 @@ ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner
10
10
  moc_*.*
11
11
  .DS_Store
12
12
  hydra-runner.log
13
+ jhw-test
14
+ .jhw-cache/
15
+ _site/
data/Gemfile CHANGED
@@ -12,4 +12,6 @@ gem 'guard-coffeescript'
12
12
  gem 'growl'
13
13
  gem 'rake', '0.8.7'
14
14
  gem 'mocha', '0.9.12'
15
- gem 'guard-jasmine-headless-webkit'
15
+ gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-jasmine-headless-webkit.git'
16
+ gem 'facter'
17
+
data/Guardfile CHANGED
@@ -4,7 +4,11 @@
4
4
  #
5
5
 
6
6
  guard 'shell' do
7
- watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h)}) { compile }
7
+ watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h|pro|pri)}) { |m|
8
+ if !m[0]['moc_']
9
+ compile
10
+ end
11
+ }
8
12
  end
9
13
  # A sample Guardfile
10
14
  # More info at https://github.com/guard/guard#readme
@@ -22,7 +26,8 @@ guard 'jasmine-headless-webkit', :all_on_start => false do
22
26
  end
23
27
 
24
28
  def compile
25
- system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb}
29
+ #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}
26
31
  end
27
32
 
28
33
  compile
data/Rakefile CHANGED
@@ -9,6 +9,7 @@ RSpec::Core::RakeTask.new(:spec)
9
9
 
10
10
  $: << File.expand_path('../lib', __FILE__)
11
11
 
12
+ require 'jasmine-headless-webkit'
12
13
  require 'jasmine/headless/task'
13
14
 
14
15
  Jasmine::Headless::Task.new
@@ -8,13 +8,26 @@ def gem_dir
8
8
  end
9
9
 
10
10
  $:.unshift(File.join(gem_dir, 'lib'))
11
+ require 'jasmine-headless-webkit'
12
+
11
13
  require 'jasmine/headless/errors'
12
14
  require 'jasmine/headless/runner'
13
15
  require 'jasmine/headless/options'
14
16
 
15
17
  begin
16
- puts "Running Jasmine specs...".color(:white)
17
- exit Jasmine::Headless::Runner.run(Jasmine::Headless::Options.from_command_line)
18
+ options = Jasmine::Headless::Options.from_command_line
19
+ runner = Jasmine::Headless::Runner.new(options)
20
+
21
+ if options[:do_list]
22
+ files_list = Jasmine::FilesList.new(
23
+ :config => runner.jasmine_config
24
+ )
25
+
26
+ files_list.files.each { |file| puts file }
27
+ else
28
+ puts "Running Jasmine specs...".color(:white)
29
+ exit runner.run
30
+ end
18
31
  rescue CoffeeScript::CompilationError
19
32
  exit 1
20
33
  rescue StandardError => e
@@ -0,0 +1,140 @@
1
+ #include "ConsoleOutput.h"
2
+
3
+ ConsoleOutput::ConsoleOutput() : QObject(),
4
+ showColors(false),
5
+ consoleLogUsed(false) {
6
+ outputIO = &std::cout;
7
+ }
8
+
9
+ void ConsoleOutput::passed(const QString &specDetail) {
10
+ green();
11
+ *outputIO << '.';
12
+ clear();
13
+ outputIO->flush();
14
+
15
+ consoleLogUsed = false;
16
+ successes.push(specDetail);
17
+ }
18
+
19
+ void ConsoleOutput::failed(const QString &specDetail) {
20
+ red();
21
+ *outputIO << 'F';
22
+ clear();
23
+ outputIO->flush();
24
+
25
+ consoleLogUsed = false;
26
+ failures.push(specDetail);
27
+ }
28
+
29
+ void ConsoleOutput::green() {
30
+ if (showColors) std::cout << "\033[0;32m";
31
+ }
32
+
33
+ void ConsoleOutput::clear() {
34
+ if (showColors) std::cout << "\033[m";
35
+ }
36
+
37
+ void ConsoleOutput::red() {
38
+ if (showColors) std::cout << "\033[0;31m";
39
+ }
40
+
41
+ void ConsoleOutput::yellow()
42
+ {
43
+ if (showColors) std::cout << "\033[0;33m";
44
+ }
45
+
46
+ void ConsoleOutput::errorLog(const QString &msg, int lineNumber, const QString &sourceID) {
47
+ red();
48
+ *outputIO << "[error] ";
49
+ clear();
50
+ *outputIO << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg);
51
+ *outputIO << std::endl;
52
+ }
53
+
54
+ void ConsoleOutput::internalLog(const QString &note, const QString &msg) {
55
+ red();
56
+ *outputIO << "[" << qPrintable(note) << "] ";
57
+ clear();
58
+ *outputIO << qPrintable(msg);
59
+ *outputIO << std::endl;
60
+ }
61
+
62
+ void ConsoleOutput::consoleLog(const QString &msg) {
63
+ if (!consoleLogUsed) {
64
+ *outputIO << std::endl;
65
+ consoleLogUsed = true;
66
+ }
67
+
68
+ green();
69
+ *outputIO << "[console] ";
70
+ if (msg.contains("\n"))
71
+ *outputIO << std::endl;
72
+ clear();
73
+ *outputIO << qPrintable(msg);
74
+ *outputIO << std::endl;
75
+ }
76
+
77
+ void ConsoleOutput::logSpecFilename(const QString &name) {
78
+ *outputIO << std::endl << std::endl;
79
+ red();
80
+ *outputIO << qPrintable(name) << std::endl;
81
+ clear();
82
+ }
83
+
84
+ void ConsoleOutput::logSpecResult(const QString &result) {
85
+ red();
86
+ *outputIO << " " << qPrintable(result) << std::endl;
87
+ clear();
88
+ }
89
+
90
+ void ConsoleOutput::reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration) {
91
+ red();
92
+ *outputIO << std::endl << "FAIL: ";
93
+ formatTestResults(totalTests, failedTests, duration);
94
+ *outputIO << std::endl;
95
+ clear();
96
+ }
97
+
98
+ void ConsoleOutput::reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration) {
99
+ green();
100
+ *outputIO << std::endl << "PASS: ";
101
+ formatTestResults(totalTests, failedTests, duration);
102
+ *outputIO << std::endl;
103
+ clear();
104
+ }
105
+
106
+ void ConsoleOutput::reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration) {
107
+ yellow();
108
+ *outputIO << std::endl << "PASS with JS errors: ";
109
+ formatTestResults(totalTests, failedTests, duration);
110
+ *outputIO << std::endl;
111
+ clear();
112
+ }
113
+
114
+ void ConsoleOutput::formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration) {
115
+ *outputIO << qPrintable(totalTests) << " ";
116
+ if (totalTests == "1") {
117
+ *outputIO << "test";
118
+ } else {
119
+ *outputIO << "tests";
120
+ }
121
+
122
+ *outputIO << ", ";
123
+
124
+ *outputIO << qPrintable(failedTests) << " ";
125
+ if (failedTests == "1") {
126
+ *outputIO << "failure";
127
+ } else {
128
+ *outputIO << "failures";
129
+ }
130
+
131
+ *outputIO << ", ";
132
+
133
+ *outputIO << qPrintable(duration) << " ";
134
+ if (duration == "1") {
135
+ *outputIO << "sec.";
136
+ } else {
137
+ *outputIO << "secs.";
138
+ }
139
+ }
140
+
@@ -0,0 +1,38 @@
1
+ #ifndef JHW_CONSOLE_OUTPUT
2
+ #define JHW_CONSOLE_OUTPUT
3
+
4
+ #include <QObject>
5
+ #include <iostream>
6
+ #include <QStack>
7
+
8
+ class ConsoleOutput : public QObject {
9
+ public:
10
+ ConsoleOutput();
11
+
12
+ void passed(const QString &specDetail);
13
+ void failed(const QString &specDetail);
14
+ void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
15
+ void internalLog(const QString &note, const QString &msg);
16
+ void consoleLog(const QString &msg);
17
+ void logSpecFilename(const QString &name);
18
+ void logSpecResult(const QString &result);
19
+
20
+ void reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration);
21
+ void reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration);
22
+ void reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration);
23
+
24
+ std::ostream *outputIO;
25
+ QStack<QString> successes;
26
+ QStack<QString> failures;
27
+
28
+ bool showColors;
29
+ bool consoleLogUsed;
30
+ private:
31
+ void green();
32
+ void clear();
33
+ void red();
34
+ void yellow();
35
+ void formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration);
36
+ };
37
+
38
+ #endif
@@ -0,0 +1,129 @@
1
+ #include <QtTest/QtTest>
2
+
3
+ #include "ConsoleOutput.h"
4
+ #include "ConsoleOutput_test.h"
5
+
6
+ using namespace std;
7
+
8
+ ConsoleOutputTest::ConsoleOutputTest() : QObject() {}
9
+
10
+ void ConsoleOutputTest::testPassed() {
11
+ stringstream buffer;
12
+ ConsoleOutput output;
13
+
14
+ output.consoleLogUsed = true;
15
+ output.outputIO = &buffer;
16
+ output.passed("test");
17
+ QVERIFY(buffer.str() == ".");
18
+ QVERIFY(output.successes.size() == 1);
19
+ QVERIFY(output.failures.size() == 0);
20
+ QVERIFY(output.consoleLogUsed == false);
21
+ }
22
+
23
+ void ConsoleOutputTest::testFailed() {
24
+ stringstream buffer;
25
+ ConsoleOutput output;
26
+
27
+ output.consoleLogUsed = true;
28
+ output.outputIO = &buffer;
29
+ output.failed("test");
30
+ QVERIFY(buffer.str() == "F");
31
+ QVERIFY(output.successes.size() == 0);
32
+ QVERIFY(output.failures.size() == 1);
33
+ QVERIFY(output.consoleLogUsed == false);
34
+ }
35
+
36
+ void ConsoleOutputTest::testErrorLog() {
37
+ stringstream buffer;
38
+ ConsoleOutput output;
39
+
40
+ output.outputIO = &buffer;
41
+ output.errorLog("message", 1, "source");
42
+ QVERIFY(buffer.str() == "[error] source:1 : message\n");
43
+ }
44
+
45
+ void ConsoleOutputTest::testInternalLog() {
46
+ stringstream buffer;
47
+ ConsoleOutput output;
48
+
49
+ output.outputIO = &buffer;
50
+ output.internalLog("note", "message");
51
+ QVERIFY(buffer.str() == "[note] message\n");
52
+ }
53
+
54
+ void ConsoleOutputTest::testConsoleLog() {
55
+ stringstream buffer;
56
+ ConsoleOutput output;
57
+
58
+ output.consoleLogUsed = false;
59
+ output.outputIO = &buffer;
60
+ output.consoleLog("log");
61
+ QVERIFY(buffer.str() == "\n[console] log\n");
62
+ }
63
+
64
+ void ConsoleOutputTest::testConsoleLogUsed() {
65
+ stringstream buffer;
66
+ ConsoleOutput output;
67
+
68
+ output.consoleLogUsed = true;
69
+ output.outputIO = &buffer;
70
+ output.consoleLog("log");
71
+ QVERIFY(buffer.str() == "[console] log\n");
72
+ }
73
+
74
+ void ConsoleOutputTest::testLogSpecFilename() {
75
+ stringstream buffer;
76
+ ConsoleOutput output;
77
+
78
+ output.outputIO = &buffer;
79
+ output.logSpecFilename("whatever");
80
+ QVERIFY(buffer.str() == "\n\nwhatever\n");
81
+ }
82
+
83
+ void ConsoleOutputTest::testLogSpecResult() {
84
+ stringstream buffer;
85
+ ConsoleOutput output;
86
+
87
+ output.outputIO = &buffer;
88
+ output.logSpecResult("whatever");
89
+ QVERIFY(buffer.str() == " whatever\n");
90
+ }
91
+
92
+ void ConsoleOutputTest::testReportResultsFailedSingular() {
93
+ stringstream buffer;
94
+ ConsoleOutput output;
95
+
96
+ output.outputIO = &buffer;
97
+ output.reportFailure("1", "1", "1");
98
+ QVERIFY(buffer.str() == "\nFAIL: 1 test, 1 failure, 1 sec.\n");
99
+ }
100
+
101
+ void ConsoleOutputTest::testReportResultsFailedPlural() {
102
+ stringstream buffer;
103
+ ConsoleOutput output;
104
+
105
+ output.outputIO = &buffer;
106
+ output.reportFailure("2", "2", "2");
107
+ QVERIFY(buffer.str() == "\nFAIL: 2 tests, 2 failures, 2 secs.\n");
108
+ }
109
+
110
+ void ConsoleOutputTest::testReportResultsSucceeded() {
111
+ stringstream buffer;
112
+ ConsoleOutput output;
113
+
114
+ output.outputIO = &buffer;
115
+ output.reportSuccess("2", "2", "2");
116
+ QVERIFY(buffer.str() == "\nPASS: 2 tests, 2 failures, 2 secs.\n");
117
+ }
118
+
119
+ void ConsoleOutputTest::testReportResultsSucceededWithJSErrors() {
120
+ stringstream buffer;
121
+ ConsoleOutput output;
122
+
123
+ output.outputIO = &buffer;
124
+ output.reportSuccessWithJSErrors("2", "2", "2");
125
+ QVERIFY(buffer.str() == "\nPASS with JS errors: 2 tests, 2 failures, 2 secs.\n");
126
+ }
127
+
128
+ QTEST_MAIN(ConsoleOutputTest);
129
+
@@ -0,0 +1,32 @@
1
+ #ifndef JHW_TEST_CONSOLE_OUTPUT
2
+ #define JHW_TEST_CONSOLE_OUTPUT
3
+
4
+ #include <QtTest/QtTest>
5
+ #include <iostream>
6
+ #include <sstream>
7
+ #include <string>
8
+
9
+ #include "ConsoleOutput.h"
10
+
11
+ class ConsoleOutputTest : public QObject {
12
+ Q_OBJECT
13
+ public:
14
+ ConsoleOutputTest();
15
+
16
+ private slots:
17
+ void testPassed();
18
+ void testFailed();
19
+ void testErrorLog();
20
+ void testInternalLog();
21
+ void testConsoleLog();
22
+ void testConsoleLogUsed();
23
+ void testLogSpecFilename();
24
+ void testLogSpecResult();
25
+
26
+ void testReportResultsFailedSingular();
27
+ void testReportResultsFailedPlural();
28
+ void testReportResultsSucceeded();
29
+ void testReportResultsSucceededWithJSErrors();
30
+ };
31
+
32
+ #endif
@@ -0,0 +1,7 @@
1
+ include(common.pri)
2
+ include(test.pri)
3
+
4
+ SOURCES += ConsoleOutput_test.cpp
5
+ HEADERS += ConsoleOutput_test.h
6
+
7
+
@@ -0,0 +1,5 @@
1
+ build:
2
+ true
3
+ install:
4
+ true
5
+
@@ -1,16 +1,16 @@
1
1
  #include <QtGui>
2
2
  #include <QtWebKit>
3
+ #include <iostream>
3
4
 
4
5
  #include "Page.h"
5
6
 
6
- namespace HeadlessSpecRunner {
7
7
  Page::Page() : QWebPage(), confirmResult(true) {}
8
8
 
9
9
  void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) {
10
10
  emit consoleLog(message, lineNumber, sourceID);
11
11
  }
12
12
 
13
- bool Page::javaScriptConfirm(QWebFrame *frame, const QString &msg) {
13
+ bool Page::javaScriptConfirm(QWebFrame*, const QString&) {
14
14
  if (confirmResult) {
15
15
  emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true.");
16
16
  return true;
@@ -20,11 +20,10 @@ namespace HeadlessSpecRunner {
20
20
  }
21
21
  }
22
22
 
23
- void Page::javaScriptAlert(QWebFrame *frame, const QString &msg) {
23
+ void Page::javaScriptAlert(QWebFrame*, const QString &msg) {
24
24
  emit internalLog("alert", msg);
25
25
  }
26
26
 
27
27
  void Page::oneFalseConfirm() {
28
28
  confirmResult = false;
29
29
  }
30
- }
@@ -4,7 +4,6 @@
4
4
  #include <QtGui>
5
5
  #include <QtWebKit>
6
6
 
7
- namespace HeadlessSpecRunner {
8
7
  class Page: public QWebPage {
9
8
  Q_OBJECT
10
9
  public:
@@ -20,6 +19,5 @@ namespace HeadlessSpecRunner {
20
19
  private:
21
20
  bool confirmResult;
22
21
  };
23
- }
24
22
 
25
23
  #endif
@@ -0,0 +1,43 @@
1
+ #include <QtTest/QtTest>
2
+
3
+ #include "Page.h"
4
+ #include "Page_test.h"
5
+
6
+ PageTest::PageTest() : QObject(), internalLogCalled(false) {
7
+ }
8
+
9
+ void PageTest::internalLog(const QString &, const QString &) {
10
+ internalLogCalled = true;
11
+ }
12
+
13
+ void PageTest::consoleLog(const QString &, int, const QString &) {
14
+ consoleLogCalled = true;
15
+ }
16
+
17
+ void PageTest::testJavaScriptConfirmWithLog() {
18
+ connect(&page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString)));
19
+ internalLogCalled = false;
20
+
21
+ page.mainFrame()->setHtml("<script>confirm('test')</script>");
22
+ QVERIFY(internalLogCalled);
23
+ }
24
+
25
+ void PageTest::testJavaScriptConfirmWithoutLog() {
26
+ connect(&page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString)));
27
+ internalLogCalled = false;
28
+
29
+ page.oneFalseConfirm();
30
+ page.mainFrame()->setHtml("<script>confirm('test')</script>");
31
+ QVERIFY(!internalLogCalled);
32
+ }
33
+
34
+ void PageTest::testJavaScriptConsoleMessage() {
35
+ connect(&page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(consoleLog(QString, int, QString)));
36
+ consoleLogCalled = false;
37
+
38
+ page.mainFrame()->setHtml("<script>cats();</script>");
39
+ QVERIFY(consoleLogCalled);
40
+ }
41
+
42
+ QTEST_MAIN(PageTest);
43
+
@@ -0,0 +1,27 @@
1
+ #ifndef JHW_TEST_PAGE
2
+ #define JHW_TEST_PAGE
3
+
4
+ #include <QtTest/QtTest>
5
+
6
+ #include "Page.h"
7
+
8
+ class PageTest : public QObject {
9
+ Q_OBJECT
10
+ public:
11
+ PageTest();
12
+
13
+ private:
14
+ bool internalLogCalled;
15
+ bool consoleLogCalled;
16
+ Page page;
17
+
18
+ private slots:
19
+ void internalLog(const QString &note, const QString &msg);
20
+ void consoleLog(const QString &message, int lineNumber, const QString &source);
21
+ void testJavaScriptConfirmWithLog();
22
+ void testJavaScriptConfirmWithoutLog();
23
+ void testJavaScriptConsoleMessage();
24
+ };
25
+
26
+ #endif
27
+
@@ -0,0 +1,6 @@
1
+ include(common.pri)
2
+ include(test.pri)
3
+
4
+ SOURCES += Page_test.cpp
5
+ HEADERS += Page_test.h
6
+
@@ -0,0 +1,54 @@
1
+ #include "ReportFileOutput.h"
2
+
3
+ using namespace std;
4
+
5
+ ReportFileOutput::ReportFileOutput() : QObject() {
6
+ reset();
7
+ }
8
+
9
+ void ReportFileOutput::reset() {
10
+ buffer = new stringstream();
11
+
12
+ outputIO = buffer;
13
+ }
14
+
15
+ void ReportFileOutput::passed(const QString &specDetail) {
16
+ *outputIO << "PASS||" << qPrintable(specDetail) << std::endl;
17
+ successes.push(specDetail);
18
+ }
19
+
20
+ void ReportFileOutput::failed(const QString &specDetail) {
21
+ *outputIO << "FAIL||" << qPrintable(specDetail) << std::endl;
22
+ failures.push(specDetail);
23
+ }
24
+
25
+ void ReportFileOutput::errorLog(const QString &msg, int lineNumber, const QString &sourceID) {
26
+ *outputIO << "ERROR||" << qPrintable(msg) << "||" << qPrintable(sourceID) << ":" << lineNumber << std::endl;
27
+ }
28
+
29
+ void ReportFileOutput::consoleLog(const QString &msg) {
30
+ *outputIO << "CONSOLE||" << qPrintable(msg) << std::endl;
31
+ }
32
+
33
+ void ReportFileOutput::internalLog(const QString &, const QString &) {}
34
+ void ReportFileOutput::logSpecFilename(const QString &) {}
35
+ void ReportFileOutput::logSpecResult(const QString &) {}
36
+
37
+ void ReportFileOutput::reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration) {
38
+ reportTotals(totalTests, failedTests, duration, false);
39
+ }
40
+
41
+ void ReportFileOutput::reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration) {
42
+ reportTotals(totalTests, failedTests, duration, false);
43
+ }
44
+
45
+ void ReportFileOutput::reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration) {
46
+ reportTotals(totalTests, failedTests, duration, true);
47
+ }
48
+
49
+ void ReportFileOutput::reportTotals(const QString &totalTests, const QString &failedTests, const QString &duration, bool hasJavaScriptError) {
50
+ *outputIO << "TOTAL||" << qPrintable(totalTests) << "||" << qPrintable(failedTests) << "||" << qPrintable(duration) << "||";
51
+ *outputIO << (hasJavaScriptError ? "T" : "F");
52
+ *outputIO << std::endl;
53
+ }
54
+
@@ -0,0 +1,37 @@
1
+ #ifndef JHW_REPORT_FILE_OUTPUT
2
+ #define JHW_REPORT_FILE_OUTPUT
3
+
4
+ #include <QObject>
5
+ #include <iostream>
6
+ #include <QStack>
7
+ #include <sstream>
8
+
9
+ using namespace std;
10
+
11
+ class ReportFileOutput : public QObject {
12
+ public:
13
+ ReportFileOutput();
14
+
15
+ void passed(const QString &specDetail);
16
+ void failed(const QString &specDetail);
17
+ void errorLog(const QString &msg, int lineNumber, const QString &sourceID);
18
+ void internalLog(const QString &note, const QString &msg);
19
+ void consoleLog(const QString &msg);
20
+ void logSpecFilename(const QString &name);
21
+ void logSpecResult(const QString &result);
22
+
23
+ void reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration);
24
+ void reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration);
25
+ void reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration);
26
+
27
+ void reset();
28
+
29
+ stringstream *buffer;
30
+ stringstream *outputIO;
31
+ QStack<QString> successes;
32
+ QStack<QString> failures;
33
+ private:
34
+ void reportTotals(const QString &totalTests, const QString &failedTests, const QString &duration, bool hasJavaScriptError);
35
+ };
36
+
37
+ #endif