qunit-cli-runner 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Peter Wagenet and contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ module QunitCliRunner
2
+ def self.path
3
+ File.expand_path("../../support/run-qunit.js", __FILE__)
4
+ end
5
+ end
6
+
7
+ require "qunit-cli-runner/task"
@@ -0,0 +1,47 @@
1
+ require 'colored'
2
+
3
+ module QunitCliRunner
4
+ class Task
5
+ def initialize(name_or_opts=nil, opts=nil)
6
+ if name_or_opts.is_a?(Hash)
7
+ opts = name_or_opts
8
+ else
9
+ name = name_or_opts
10
+ end
11
+
12
+ name ||= "test"
13
+ opts ||= {}
14
+ opts[:path] ||= File.join(Dir.pwd, "tests", "index.html")
15
+ opts[:test_args] ||= ['']
16
+
17
+ Rake::Task.define_task(name) do
18
+ success = true
19
+
20
+ puts "Running Tests..."
21
+
22
+ opts[:test_args].each do |args|
23
+ puts args
24
+ cmd = "phantomjs \"#{QunitCliRunner.path}\" \"file://localhost#{opts[:path]}?#{args}\""
25
+ system(cmd)
26
+
27
+ # A bit of a hack until we can figure this out on Travis
28
+ tries = 0
29
+ while tries < 3 && $?.exitstatus === 124
30
+ tries += 1
31
+ puts "\nTimed Out. Trying again...\n"
32
+ system(cmd)
33
+ end
34
+
35
+ success &&= $?.success?
36
+ end
37
+
38
+ if success
39
+ puts "\nTests Passed".green
40
+ else
41
+ puts "\nTests Failed".red
42
+ exit(1)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module QunitCliRunner
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/qunit-cli-runner/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Peter Wagenet"]
6
+ gem.email = ["peter.wagenet@gmail.com"]
7
+ gem.description = "CLI Runner for QUnit tests"
8
+ gem.summary = "Use PhantomJS to run your QUnit tests in the CLI"
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "qunit-cli-runner"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = QunitCliRunner::VERSION
17
+
18
+ gem.add_dependency "colored"
19
+ end
20
+
@@ -0,0 +1,122 @@
1
+ // PhantomJS QUnit Test Runner
2
+
3
+ /*globals QUnit phantom*/
4
+
5
+ var args = phantom.args;
6
+ if (args.length < 1 || args.length > 2) {
7
+ console.log("Usage: " + phantom.scriptName + " <URL> <timeout>");
8
+ phantom.exit(1);
9
+ }
10
+
11
+ var fs = require('fs');
12
+ function print(str) {
13
+ fs.write('/dev/stdout', str, 'w');
14
+ }
15
+
16
+ var page = require('webpage').create();
17
+
18
+ page.onConsoleMessage = function(msg) {
19
+ if (msg.slice(0,8) === 'WARNING:') { return; }
20
+ if (msg.slice(0,6) === 'DEBUG:') { return; }
21
+
22
+ // Hack to access the print method
23
+ // If there's a better way to do this, please change
24
+ if (msg.slice(0,6) === 'PRINT:') {
25
+ print(msg.slice(7));
26
+ return;
27
+ }
28
+
29
+ console.log(msg);
30
+ };
31
+
32
+ page.open(args[0], function(status) {
33
+ if (status !== 'success') {
34
+ console.error("Unable to access network");
35
+ phantom.exit(1);
36
+ } else {
37
+ page.evaluate(logQUnit);
38
+
39
+ var timeout = parseInt(args[1] || 60000, 10);
40
+ var start = Date.now();
41
+ var interval = setInterval(function() {
42
+ if (Date.now() > start + timeout) {
43
+ console.error("Tests timed out");
44
+ phantom.exit(124);
45
+ } else {
46
+ var qunitDone = page.evaluate(function() {
47
+ return window.qunitDone;
48
+ });
49
+
50
+ if (qunitDone) {
51
+ clearInterval(interval);
52
+ if (qunitDone.failed > 0) {
53
+ phantom.exit(1);
54
+ } else {
55
+ phantom.exit();
56
+ }
57
+ }
58
+ }
59
+ }, 500);
60
+ }
61
+ });
62
+
63
+ function logQUnit() {
64
+ var moduleErrors = [];
65
+ var testErrors = [];
66
+ var assertionErrors = [];
67
+
68
+ console.log("\nRunning: " + JSON.stringify(QUnit.urlParams) + "\n");
69
+
70
+ QUnit.moduleDone(function(context) {
71
+ if (context.failed) {
72
+ var msg = "Module Failed: " + context.name + "\n" + testErrors.join("\n");
73
+ moduleErrors.push(msg);
74
+ testErrors = [];
75
+ }
76
+ });
77
+
78
+ QUnit.testDone(function(context) {
79
+ if (context.failed) {
80
+ var msg = " Test Failed: " + context.name + assertionErrors.join(" ");
81
+ testErrors.push(msg);
82
+ assertionErrors = [];
83
+ console.log('PRINT: F');
84
+ } else {
85
+ console.log('PRINT: .');
86
+ }
87
+ });
88
+
89
+ QUnit.log(function(context) {
90
+ if (context.result) { return; }
91
+
92
+ var msg = "\n Assertion Failed:";
93
+ if (context.message) {
94
+ msg += " " + context.message;
95
+ }
96
+
97
+ if (context.expected) {
98
+ msg += "\n Expected: " + context.expected + ", Actual: " + context.actual;
99
+ }
100
+
101
+ assertionErrors.push(msg);
102
+ });
103
+
104
+ QUnit.done(function(context) {
105
+ console.log('\n');
106
+
107
+ if (moduleErrors.length > 0) {
108
+ for (var idx=0; idx<moduleErrors.length; idx++) {
109
+ console.error(moduleErrors[idx]+"\n");
110
+ }
111
+ }
112
+
113
+ var stats = [
114
+ "Time: " + context.runtime + "ms",
115
+ "Total: " + context.total,
116
+ "Passed: " + context.passed,
117
+ "Failed: " + context.failed
118
+ ];
119
+ console.log(stats.join(", "));
120
+ window.qunitDone = context;
121
+ });
122
+ }
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qunit-cli-runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Wagenet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colored
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: CLI Runner for QUnit tests
31
+ email:
32
+ - peter.wagenet@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - LICENSE
38
+ - lib/qunit-cli-runner.rb
39
+ - lib/qunit-cli-runner/task.rb
40
+ - lib/qunit-cli-runner/version.rb
41
+ - qunit-cli-runner.gemspec
42
+ - support/run-qunit.js
43
+ homepage: ''
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.24
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Use PhantomJS to run your QUnit tests in the CLI
67
+ test_files: []
68
+ has_rdoc: