qunited 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -3
- data/lib/qunited/driver/phantomjs/support/tests_page.html.erb +1 -0
- data/lib/qunited/rake_task.rb +33 -10
- data/lib/qunited/runner.rb +6 -0
- data/lib/qunited/server/test_suite.html.erb +1 -0
- data/lib/qunited/server.rb +12 -2
- data/lib/qunited/version.rb +1 -1
- metadata +39 -21
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
<img src="http://i.imgur.com/NIoQy.png" width="150px" />
|
2
2
|
|
3
|
+
_Pronounced "queue united"_
|
4
|
+
|
3
5
|
QUnited is a tool to run headless JavaScript tests with QUnit.
|
4
6
|
|
5
7
|
Tests are run with PhantomJS if available, otherwise Rhino (Java) is used. Give it a try and let me know if you have any feedback.
|
@@ -36,11 +38,11 @@ require 'qunited/rake_task'
|
|
36
38
|
|
37
39
|
QUnited::RakeTask.new do |t|
|
38
40
|
t.source_files = ['lib/js/jquery.js', 'lib/js/my_app_1.js', 'lib/js/my_app_2.js']
|
39
|
-
t.
|
41
|
+
t.test_files = 'test/js/**/*.js'
|
40
42
|
end
|
41
43
|
```
|
42
44
|
|
43
|
-
Source and test files can be configured either as an array of file names or a glob pattern
|
45
|
+
Source and test files can be configured either as an array of file names or a glob pattern string. Using an array is usually desirable for source files since the order of their execution is often important. Note that all JavaScript dependencies (jQuery, underscore, etc.) will have to be loaded with source files, in the correct order, to match your production environment.
|
44
46
|
|
45
47
|
You can also use an array to configure the test files but a glob pattern might be more convenient since test files usually do not need to be loaded in a particular order.
|
46
48
|
|
@@ -51,7 +53,7 @@ QUnited uses various drivers to set up the environment the tests run in (see bel
|
|
51
53
|
```ruby
|
52
54
|
QUnited::RakeTask.new do |t|
|
53
55
|
t.source_files = ['lib/js/jquery.js', 'lib/js/my_app']
|
54
|
-
t.
|
56
|
+
t.test_files = 'test/js/**/*.js'
|
55
57
|
t.driver = :phantomjs # Always use PhantomJS to run tests. Fail if it's not available.
|
56
58
|
end
|
57
59
|
```
|
data/lib/qunited/rake_task.rb
CHANGED
@@ -15,8 +15,8 @@ module QUnited
|
|
15
15
|
@source_files = pattern
|
16
16
|
end
|
17
17
|
|
18
|
-
# Array of JavaScript source files (and any dependencies). These will be
|
19
|
-
#
|
18
|
+
# Array or glob pattern of JavaScript source files (and any dependencies). These will be
|
19
|
+
# loaded in order if specified as an array.
|
20
20
|
attr_accessor :source_files
|
21
21
|
|
22
22
|
# <b>DEPRECATED:</b> Please use <tt>test_files=</tt>, which now takes either an array of files
|
@@ -26,9 +26,14 @@ module QUnited
|
|
26
26
|
@test_files = pattern
|
27
27
|
end
|
28
28
|
|
29
|
-
# Array of QUnit test files.
|
29
|
+
# Array or glob pattern of QUnit test files. These will be loaded in order if specified as an array.
|
30
30
|
attr_accessor :test_files
|
31
31
|
|
32
|
+
# Array or glob pattern of test helper files. These include extra libraries for mocks or other
|
33
|
+
# test tools. These are loaded after source files and before test files. These will be loaded
|
34
|
+
# in order if specified as an array.
|
35
|
+
attr_accessor :helper_files
|
36
|
+
|
32
37
|
# The driver to use to run the QUnit tests.
|
33
38
|
attr_accessor :driver
|
34
39
|
|
@@ -63,11 +68,19 @@ module QUnited
|
|
63
68
|
task name do
|
64
69
|
RakeFileUtils.send(:verbose, verbose) do
|
65
70
|
if source_files_to_include.empty?
|
66
|
-
msg =
|
67
|
-
|
68
|
-
|
71
|
+
msg = if source_files.is_a? String
|
72
|
+
"No JavaScript source files match the pattern '#{source_files}'"
|
73
|
+
else
|
74
|
+
'No JavaScript source files specified'
|
75
|
+
end
|
76
|
+
fail msg
|
69
77
|
elsif test_files_to_run.empty?
|
70
|
-
|
78
|
+
msg = if test_files.is_a? String
|
79
|
+
"No QUnit test files match the pattern '#{test_files}'"
|
80
|
+
else
|
81
|
+
'No QUnit test files specified'
|
82
|
+
end
|
83
|
+
fail msg
|
71
84
|
else
|
72
85
|
command = test_command
|
73
86
|
puts command if verbose
|
@@ -91,8 +104,9 @@ module QUnited
|
|
91
104
|
task (name.to_s + ':server') do
|
92
105
|
require 'qunited/server'
|
93
106
|
server_options = {
|
94
|
-
:source_files =>
|
95
|
-
:test_files => test_files_to_run
|
107
|
+
:source_files => source_and_helper_files,
|
108
|
+
:test_files => test_files_to_run,
|
109
|
+
:verbose => verbose
|
96
110
|
}
|
97
111
|
server_options[:port] = @server_port if @server_port
|
98
112
|
::QUnited::Server.new(server_options).start
|
@@ -104,19 +118,28 @@ module QUnited
|
|
104
118
|
def test_command
|
105
119
|
cmd = 'qunited'
|
106
120
|
cmd << " --driver #{driver}" if driver
|
107
|
-
cmd << " #{
|
121
|
+
cmd << " #{source_and_helper_files.join(' ')} -- #{test_files_to_run.join(' ')}"
|
108
122
|
end
|
109
123
|
|
110
124
|
def source_files_to_include
|
111
125
|
files_array source_files
|
112
126
|
end
|
113
127
|
|
128
|
+
def helper_files_to_include
|
129
|
+
files_array helper_files
|
130
|
+
end
|
131
|
+
|
114
132
|
def test_files_to_run
|
115
133
|
files_array test_files
|
116
134
|
end
|
117
135
|
|
136
|
+
def source_and_helper_files
|
137
|
+
source_files_to_include + helper_files_to_include
|
138
|
+
end
|
139
|
+
|
118
140
|
# Force convert to array of files if glob pattern
|
119
141
|
def files_array(files)
|
142
|
+
return [] unless files
|
120
143
|
files.is_a?(Array) ? files : pattern_to_filelist(files.to_s)
|
121
144
|
end
|
122
145
|
|
data/lib/qunited/runner.rb
CHANGED
@@ -11,6 +11,8 @@ module QUnited
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def run
|
14
|
+
[js_source_files, js_test_files].each { |files| confirm_existence_of_files files }
|
15
|
+
|
14
16
|
driver_class, formatter_class = resolve_driver_class, resolve_formatter_class
|
15
17
|
driver = driver_class.new(js_source_files, js_test_files)
|
16
18
|
driver.formatter = formatter_class.new({:driver_name => driver.name})
|
@@ -69,5 +71,9 @@ module QUnited
|
|
69
71
|
def best_available_driver
|
70
72
|
DRIVERS_PRIORITY.map { |driver| get_driver(driver) }.find { |driver| driver.available? }
|
71
73
|
end
|
74
|
+
|
75
|
+
def confirm_existence_of_files(files_array)
|
76
|
+
files_array.each { |f| raise UsageError, "File not found: #{f}" unless File.exist? f }
|
77
|
+
end
|
72
78
|
end
|
73
79
|
end
|
data/lib/qunited/server.rb
CHANGED
@@ -17,11 +17,21 @@ module QUnited
|
|
17
17
|
|
18
18
|
def initialize(opts={})
|
19
19
|
@source_files, @test_files = opts[:source_files], opts[:test_files]
|
20
|
+
@port = opts[:port] || DEFAULT_PORT
|
20
21
|
|
21
22
|
server_options = {
|
22
|
-
:Port =>
|
23
|
+
:Port => @port
|
23
24
|
}
|
24
25
|
|
26
|
+
unless opts[:verbose]
|
27
|
+
server_options[:AccessLog] = []
|
28
|
+
|
29
|
+
dev_null = '/dev/null'
|
30
|
+
if File.exist?(dev_null) && File.writable?(dev_null)
|
31
|
+
server_options[:Logger] = WEBrick::Log.new(dev_null)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
25
35
|
@server = ::WEBrick::HTTPServer.new(server_options)
|
26
36
|
|
27
37
|
@server.mount_proc '/' do |request, response|
|
@@ -34,7 +44,6 @@ module QUnited
|
|
34
44
|
when /^\/#{QUNITED_ASSET_FILE_PREFIX}\/(.*)/
|
35
45
|
filename = $1
|
36
46
|
response['Content-Type'] = (filename =~ /\.js$/) ? 'application/javascript' : 'text/css'
|
37
|
-
puts "HUH? #{filename}"
|
38
47
|
response.body = IO.read(asset_path filename)
|
39
48
|
else
|
40
49
|
response['Content-Type'] = 'text/html'
|
@@ -49,6 +58,7 @@ module QUnited
|
|
49
58
|
end
|
50
59
|
|
51
60
|
def start
|
61
|
+
$stderr.puts "Serving QUnit test suite on port #{@port}\nCtrl-C to shutdown"
|
52
62
|
@server.start
|
53
63
|
end
|
54
64
|
|
data/lib/qunited/version.rb
CHANGED
metadata
CHANGED
@@ -1,24 +1,33 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: qunited
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Aaron Royer
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
17
|
+
|
18
|
+
date: 2013-03-23 00:00:00 Z
|
13
19
|
dependencies: []
|
20
|
+
|
14
21
|
description: QUnited runs headless QUnit tests as part of your normal build
|
15
|
-
email:
|
22
|
+
email:
|
16
23
|
- aaronroyer@gmail.com
|
17
|
-
executables:
|
24
|
+
executables:
|
18
25
|
- qunited
|
19
26
|
extensions: []
|
27
|
+
|
20
28
|
extra_rdoc_files: []
|
21
|
-
|
29
|
+
|
30
|
+
files:
|
22
31
|
- .gitignore
|
23
32
|
- Gemfile
|
24
33
|
- MIT-LICENSE
|
@@ -75,29 +84,38 @@ files:
|
|
75
84
|
- test/unit/test_runner.rb
|
76
85
|
homepage: https://github.com/aaronroyer/qunited
|
77
86
|
licenses: []
|
87
|
+
|
78
88
|
post_install_message:
|
79
89
|
rdoc_options: []
|
80
|
-
|
90
|
+
|
91
|
+
require_paths:
|
81
92
|
- lib
|
82
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
103
|
none: false
|
90
|
-
requirements:
|
91
|
-
- -
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
94
111
|
requirements: []
|
112
|
+
|
95
113
|
rubyforge_project: qunited
|
96
|
-
rubygems_version: 1.8.
|
114
|
+
rubygems_version: 1.8.15
|
97
115
|
signing_key:
|
98
116
|
specification_version: 3
|
99
117
|
summary: QUnit tests in your build
|
100
|
-
test_files:
|
118
|
+
test_files:
|
101
119
|
- test/fixtures/basic_project/app/assets/javascripts/application.js
|
102
120
|
- test/fixtures/basic_project/test/javascripts/test_basics.js
|
103
121
|
- test/fixtures/basic_project/test/javascripts/test_math.js
|