qunited 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/README.md +7 -0
- data/lib/qunited/application.rb +5 -0
- data/lib/qunited/driver/base.rb +72 -5
- data/lib/qunited/driver/phantomjs/phantomjs.rb +3 -63
- data/lib/qunited/driver/rhino/rhino.rb +5 -34
- data/lib/qunited/driver/rhino/support/env.rhino.js +1 -1
- data/lib/qunited/driver/rhino/support/runner.js +25 -122
- data/lib/qunited/driver/support/qunit.js +7 -7
- data/lib/qunited/driver/support/tests_page.html.erb +37 -0
- data/lib/qunited/qunit_test_result.rb +12 -5
- data/lib/qunited/rake_task.rb +10 -0
- data/lib/qunited/runner.rb +6 -2
- data/lib/qunited/server/test_suite.html.erb +13 -9
- data/lib/qunited/server.rb +8 -2
- data/lib/qunited/version.rb +1 -1
- data/test/unit/test_rhino_driver.rb +0 -10
- metadata +3 -5
- data/lib/qunited/driver/phantomjs/support/tests_page.html.erb +0 -31
- data/test/fixtures/errors_project/test/javascripts/this_test_has_no_tests.js +0 -4
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,12 +18,15 @@ If you are using Bundler you can add QUnited to your Gemfile. With Rails add QUn
|
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
# In Gemfile
|
21
|
+
|
22
|
+
gem 'coffee-script' # Optional, only needed if using CoffeeScript
|
21
23
|
gem 'qunited'
|
22
24
|
```
|
23
25
|
|
24
26
|
```ruby
|
25
27
|
# With Rails
|
26
28
|
group :test, :development do
|
29
|
+
gem 'coffee-script' # Optional
|
27
30
|
gem 'qunited'
|
28
31
|
end
|
29
32
|
```
|
@@ -58,6 +61,10 @@ end
|
|
58
61
|
```
|
59
62
|
These will be loaded after source files and before running tests. Separating helpers this way is merely for convenience and has the same effect as just including them last with your source files.
|
60
63
|
|
64
|
+
### CoffeeScript
|
65
|
+
|
66
|
+
CoffeeScript is also supported. If any included source or test files have the `.coffee` extension they will automatically be compiled and tests will be run with the resulting JavaScript. Compilation is done with the [coffee-script](https://github.com/josh/ruby-coffee-script) gem.
|
67
|
+
|
61
68
|
### Specifying a driver
|
62
69
|
|
63
70
|
QUnited uses various drivers to set up the environment the tests run in (see below for more details). By default it tries to Just Work and find an available driver to use. You may want to lock down the driver (recommended) so your tests are consistent. To do this add a bit more configuration to the Rake task.
|
data/lib/qunited/application.rb
CHANGED
@@ -54,6 +54,11 @@ Options:
|
|
54
54
|
raise UsageError, "Invalid driver specified: #{name}\n#{valid_drivers_string}" unless driver
|
55
55
|
options[:driver] = driver
|
56
56
|
end
|
57
|
+
|
58
|
+
opts.on('--fixtures [FILES]', 'Specify some files to include as html before running the tests') do |files|
|
59
|
+
options[:fixture_files] = files.split(',')
|
60
|
+
end
|
61
|
+
|
57
62
|
opts.on_tail('-h', '--help', 'Show this message') do
|
58
63
|
puts opts
|
59
64
|
exit
|
data/lib/qunited/driver/base.rb
CHANGED
@@ -13,7 +13,7 @@ module QUnited
|
|
13
13
|
COFFEESCRIPT_EXTENSIONS = ['coffee', 'cs']
|
14
14
|
|
15
15
|
attr_reader :results, :source_files, :test_files
|
16
|
-
attr_accessor :formatter
|
16
|
+
attr_accessor :formatter, :fixture_files
|
17
17
|
|
18
18
|
# Finds an executable on the PATH. Returns the absolute path of the
|
19
19
|
# executable if found, otherwise nil.
|
@@ -28,15 +28,58 @@ module QUnited
|
|
28
28
|
return nil
|
29
29
|
end
|
30
30
|
|
31
|
+
# Overridden in subclasses to return true if the underlying library is installed
|
32
|
+
def self.available?
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
31
36
|
# Initialize the driver with source and test files. The files can be described either with
|
32
37
|
# glob patterns or arrays of file names.
|
33
38
|
def initialize(source_files, test_files)
|
34
39
|
@source_files = normalize_files source_files
|
35
40
|
@test_files = normalize_files test_files
|
41
|
+
@fixture_files = []
|
42
|
+
end
|
43
|
+
|
44
|
+
def command
|
45
|
+
raise 'not implemented'
|
36
46
|
end
|
37
47
|
|
38
48
|
def run
|
39
|
-
|
49
|
+
@tests_file = Tempfile.new(['tests_page', '.html'])
|
50
|
+
@tests_file.write(tests_page_content)
|
51
|
+
@tests_file.close
|
52
|
+
puts @tests_file.path
|
53
|
+
|
54
|
+
send_to_formatter(:start)
|
55
|
+
|
56
|
+
@results = []
|
57
|
+
|
58
|
+
Open3.popen3(command) do |stdin, stdout, stderr|
|
59
|
+
results_collector = ResultsCollector.new(stdout)
|
60
|
+
|
61
|
+
results_collector.on_test_result do |result|
|
62
|
+
@results << result
|
63
|
+
method = result.passed? ? :test_passed : :test_failed
|
64
|
+
send_to_formatter(method, result)
|
65
|
+
end
|
66
|
+
|
67
|
+
results_collector.on_non_test_result_line do |line|
|
68
|
+
# Drivers sometimes print error messages to stdout. If we are not reading
|
69
|
+
# a test result then redirect any output to stderr
|
70
|
+
$stderr.puts(line)
|
71
|
+
end
|
72
|
+
|
73
|
+
results_collector.collect_results
|
74
|
+
|
75
|
+
err = stderr.read
|
76
|
+
$stderr.puts(err) if err && !err.empty?
|
77
|
+
end
|
78
|
+
|
79
|
+
send_to_formatter(:stop)
|
80
|
+
send_to_formatter(:summarize)
|
81
|
+
|
82
|
+
@results
|
40
83
|
end
|
41
84
|
|
42
85
|
def support_file_path(filename)
|
@@ -51,7 +94,7 @@ module QUnited
|
|
51
94
|
self.class.name.split('::')[-1]
|
52
95
|
end
|
53
96
|
|
54
|
-
|
97
|
+
private
|
55
98
|
|
56
99
|
def send_to_formatter(method, *args)
|
57
100
|
formatter.send(method, *args) if formatter
|
@@ -64,8 +107,6 @@ module QUnited
|
|
64
107
|
@compiled_coffeescript_files ||= {}
|
65
108
|
end
|
66
109
|
|
67
|
-
private
|
68
|
-
|
69
110
|
# Produces an array of JavaScript filenames from either a glob pattern or an array of
|
70
111
|
# JavaScript or CoffeeScript filenames. Files with CoffeeScript extensions will be
|
71
112
|
# compiled and replaced in the produced array with temp files of compiled JavaScript.
|
@@ -102,6 +143,32 @@ Run the following command (with sudo if necessary): gem install coffee-script
|
|
102
143
|
|
103
144
|
compiled_js_file.path
|
104
145
|
end
|
146
|
+
|
147
|
+
def tests_page_content
|
148
|
+
ERB.new(IO.read(support_file_path('tests_page.html.erb'))).result(binding)
|
149
|
+
end
|
150
|
+
|
151
|
+
def read_file(file)
|
152
|
+
IO.read(file)
|
153
|
+
end
|
154
|
+
|
155
|
+
def script_tag(file)
|
156
|
+
js_file_path, tests_file_path = Pathname.new(file).realpath, Pathname.new(@tests_file.path)
|
157
|
+
begin
|
158
|
+
rel_path = js_file_path.relative_path_from(tests_file_path)
|
159
|
+
# Attempt to convert paths to relative URLs if Windows... should really test this
|
160
|
+
return %{<script type="text/javascript" src="#{rel_path.to_s.gsub(/\\/, '/')}"></script>}
|
161
|
+
rescue ArgumentError
|
162
|
+
# If we cannot get a relative path to the js file then just put the contents
|
163
|
+
# of the file inline. This can happen for a few reasons, like if the drive
|
164
|
+
# letter is different on Windows.
|
165
|
+
return <<-SCRIPT_ELEMENT
|
166
|
+
<script type="text/javascript">
|
167
|
+
#{IO.read(file)}
|
168
|
+
</script>
|
169
|
+
SCRIPT_ELEMENT
|
170
|
+
end
|
171
|
+
end
|
105
172
|
end
|
106
173
|
end
|
107
174
|
end
|
@@ -7,7 +7,7 @@ require 'open3'
|
|
7
7
|
module QUnited
|
8
8
|
module Driver
|
9
9
|
class PhantomJs < Base
|
10
|
-
|
10
|
+
RUNNER_JS = File.expand_path('../support/runner.js', __FILE__)
|
11
11
|
|
12
12
|
# Determines whether this driver available to use.
|
13
13
|
# Checks whether phantomjs is on the PATH.
|
@@ -19,68 +19,8 @@ module QUnited
|
|
19
19
|
'PhantomJS'
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
tests_file.write(tests_page_content)
|
25
|
-
tests_file.close
|
26
|
-
|
27
|
-
send_to_formatter(:start)
|
28
|
-
|
29
|
-
cmd = %|phantomjs "#{File.join(SUPPORT_DIR, 'runner.js')}" "#{tests_file.path}"|
|
30
|
-
|
31
|
-
@results = []
|
32
|
-
|
33
|
-
Open3.popen3(cmd) do |stdin, stdout, stderr|
|
34
|
-
results_collector = ResultsCollector.new(stdout)
|
35
|
-
|
36
|
-
results_collector.on_test_result do |result|
|
37
|
-
@results << result
|
38
|
-
method = result.passed? ? :test_passed : :test_failed
|
39
|
-
send_to_formatter(method, result)
|
40
|
-
end
|
41
|
-
|
42
|
-
results_collector.on_non_test_result_line do |line|
|
43
|
-
# PhantomJS sometimes puts error messages to stdout. If we are not reading
|
44
|
-
# a test result then redirect any output to stderr
|
45
|
-
$stderr.puts(line)
|
46
|
-
end
|
47
|
-
|
48
|
-
results_collector.collect_results
|
49
|
-
|
50
|
-
err = stderr.read
|
51
|
-
unless err.nil? || err.strip.empty? then $stderr.puts(err) end
|
52
|
-
end
|
53
|
-
|
54
|
-
send_to_formatter(:stop)
|
55
|
-
send_to_formatter(:summarize)
|
56
|
-
|
57
|
-
@results
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
attr_accessor :tests_file
|
63
|
-
|
64
|
-
def tests_page_content
|
65
|
-
ERB.new(IO.read(File.join(SUPPORT_DIR, 'tests_page.html.erb'))).result(binding)
|
66
|
-
end
|
67
|
-
|
68
|
-
def script_tag(file)
|
69
|
-
js_file_path, tests_file_path = Pathname.new(file).realpath, Pathname.new(tests_file.path)
|
70
|
-
begin
|
71
|
-
rel_path = js_file_path.relative_path_from(tests_file_path)
|
72
|
-
# Attempt to convert paths to relative URLs if Windows... should really test this
|
73
|
-
return %{<script type="text/javascript" src="#{rel_path.to_s.gsub(/\\/, '/')}"></script>}
|
74
|
-
rescue ArgumentError
|
75
|
-
# If we cannot get a relative path to the js file then just put the contents
|
76
|
-
# of the file inline. This can happen for a few reasons, like if the drive
|
77
|
-
# letter is different on Windows.
|
78
|
-
return <<-SCRIPT_ELEMENT
|
79
|
-
<script type="text/javascript">
|
80
|
-
#{IO.read(file)}
|
81
|
-
</script>
|
82
|
-
SCRIPT_ELEMENT
|
83
|
-
end
|
22
|
+
def command
|
23
|
+
%|phantomjs "#{RUNNER_JS}" "#{@tests_file.path}"|
|
84
24
|
end
|
85
25
|
end
|
86
26
|
end
|
@@ -5,7 +5,9 @@ require 'open3'
|
|
5
5
|
module QUnited
|
6
6
|
module Driver
|
7
7
|
class Rhino < Base
|
8
|
-
|
8
|
+
JS_JAR = File.expand_path('../support/js.jar', __FILE__)
|
9
|
+
ENV_JS = File.expand_path('../support/env.rhino.js', __FILE__)
|
10
|
+
RUNNER_JS = File.expand_path('../support/runner.js', __FILE__)
|
9
11
|
|
10
12
|
# Determines whether this driver available to use. Checks whether java
|
11
13
|
# is on the PATH and whether Java is version 1.1 or greater.
|
@@ -22,39 +24,8 @@ module QUnited
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
source_files_args = @source_files.map { |sf| %{"#{sf}"} }.join(' ')
|
29
|
-
test_files_args = @test_files.map { |tf| %{"#{tf}"} }.join(' ')
|
30
|
-
|
31
|
-
send_to_formatter(:start)
|
32
|
-
|
33
|
-
cmd = %{java -jar "#{js_jar}" -opt -1 "#{runner}" }
|
34
|
-
cmd << %{"#{QUnited::Driver::Base::SUPPORT_DIR}" "#{SUPPORT_DIR}"}
|
35
|
-
cmd << " #{source_files_args} -- #{test_files_args}"
|
36
|
-
|
37
|
-
@results = []
|
38
|
-
|
39
|
-
Open3.popen3(cmd) do |stdin, stdout, stderr|
|
40
|
-
results_collector = ResultsCollector.new(stdout)
|
41
|
-
results_collector.on_test_result do |result|
|
42
|
-
@results << result
|
43
|
-
method = result.passed? ? :test_passed : :test_failed
|
44
|
-
send_to_formatter(method, result)
|
45
|
-
end
|
46
|
-
|
47
|
-
results_collector.collect_results
|
48
|
-
|
49
|
-
# Allow stderr to get blasted out to console - if there are uncaught exceptions or
|
50
|
-
# anything else that goes wrong with Rhino the user will probably want to know.
|
51
|
-
unless (err = stderr.read).strip.empty? then $stderr.puts(err) end
|
52
|
-
end
|
53
|
-
|
54
|
-
send_to_formatter(:stop)
|
55
|
-
send_to_formatter(:summarize)
|
56
|
-
|
57
|
-
@results
|
27
|
+
def command
|
28
|
+
%|java -jar "#{JS_JAR}" -opt -1 #{RUNNER_JS} #{ENV_JS} #{@tests_file.path}|
|
58
29
|
end
|
59
30
|
end
|
60
31
|
end
|
@@ -13975,7 +13975,7 @@ Window = function(scope, parent, opener){
|
|
13975
13975
|
//finally pre-supply the window with the window-like environment
|
13976
13976
|
//console.log('Default Window');
|
13977
13977
|
new Window(__this__, __this__);
|
13978
|
-
console.log('[ %s ]',window.navigator.userAgent);
|
13978
|
+
// console.log('[ %s ]',window.navigator.userAgent);
|
13979
13979
|
/**
|
13980
13980
|
*
|
13981
13981
|
* @param {Object} event
|
@@ -1,124 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
* rest of the arguments are QUnit test files.
|
11
|
-
*
|
12
|
-
* Example:
|
13
|
-
* java -jar js.jar -opt -1 runner.js commonlibdir libdir source.js -- test1.js test2.js
|
14
|
-
* ^ our args start here
|
15
|
-
*/
|
16
|
-
|
17
|
-
var QUnited = { sourceFiles: [], testFiles: [] };
|
18
|
-
|
19
|
-
// Process command line arguments
|
20
|
-
(function(args) {
|
21
|
-
var commonLibDir = args.shift(),
|
22
|
-
libDir = args.shift();
|
23
|
-
|
24
|
-
load(libDir + '/env.rhino.js');
|
25
|
-
|
26
|
-
['qunit.js', 'qunited.js'].forEach(function(lib) {
|
27
|
-
load(commonLibDir + '/' + lib);
|
28
|
-
});
|
29
|
-
|
30
|
-
var readingSource = true;
|
31
|
-
args.forEach(function(arg) {
|
32
|
-
if (arg === '--') {
|
33
|
-
readingSource = false; // Now reading tests
|
34
|
-
} else {
|
35
|
-
(readingSource ? QUnited.sourceFiles : QUnited.testFiles).push(arg);
|
36
|
-
}
|
37
|
-
});
|
38
|
-
|
39
|
-
// QUnit config
|
40
|
-
QUnit.init();
|
41
|
-
QUnit.config.blocking = false;
|
42
|
-
QUnit.config.autorun = true;
|
43
|
-
QUnit.config.updateRate = 0;
|
44
|
-
|
45
|
-
QUnited.startCollectingTestResults();
|
46
|
-
|
47
|
-
})(Array.prototype.slice.call(arguments, 0));
|
48
|
-
|
49
|
-
// Load source files under test
|
50
|
-
QUnited.sourceFiles.forEach(function(file) {
|
51
|
-
load(file);
|
1
|
+
// Load EnvJs
|
2
|
+
load(arguments[0]);
|
3
|
+
|
4
|
+
// Allow script tags in test document to be eval'd
|
5
|
+
Envjs({
|
6
|
+
scriptTypes: {
|
7
|
+
'': true,
|
8
|
+
'text/javascript': true
|
9
|
+
}
|
52
10
|
});
|
53
11
|
|
54
|
-
// Load test
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
// that I've come up with is to make sure at least one test is run after a file is loaded. A
|
71
|
-
// failure when no tests have been written is not unreasonable and it will have the desirable side
|
72
|
-
// effect that the build is failed if loading fails and tests are not run.
|
73
|
-
load(file);
|
74
|
-
|
75
|
-
// Check that the file had at least one test in it. See above.
|
76
|
-
var foundOne = false;
|
77
|
-
Object.keys(QUnited.modulesMap).forEach(function(key) {
|
78
|
-
var tests = QUnited.modulesMap[key].tests, i, test;
|
79
|
-
for (i = 0; test = tests[i++];) {
|
80
|
-
if (test.file === file) {
|
81
|
-
foundOne = true;
|
82
|
-
break;
|
83
|
-
}
|
84
|
-
};
|
85
|
-
});
|
86
|
-
|
87
|
-
if (!foundOne) {
|
88
|
-
// Create our own test failure in the default module
|
89
|
-
var defaultModuleName = "(no module)",
|
90
|
-
module = QUnited.modulesMap[defaultModuleName];
|
91
|
-
if (!module) {
|
92
|
-
module = {name: defaultModuleName, tests: []};
|
93
|
-
QUnited.modulesMap[defaultModuleName] = module;
|
94
|
-
}
|
95
|
-
|
96
|
-
// Put our failed test data into the default module
|
97
|
-
var failingTest = {
|
98
|
-
name: "Nonexistent tests",
|
99
|
-
assertion_data: [{
|
100
|
-
result: false, message: "Test file did not contain any tests (or there was an error loading it)"
|
101
|
-
}],
|
102
|
-
start: new Date(), duration: 0,
|
103
|
-
assertions: 1, failed: 1, total: 1,
|
104
|
-
file: file
|
105
|
-
}
|
106
|
-
|
107
|
-
module.tests.push(failingTest);
|
108
|
-
QUnited.testResultsPendingOutput.push(failingTest);
|
109
|
-
}
|
110
|
-
|
111
|
-
var results = [];
|
112
|
-
while (QUnited.testResultsPendingOutput.length > 0) {
|
113
|
-
results.push(QUnited.testResultsPendingOutput.shift());
|
114
|
-
}
|
115
|
-
|
116
|
-
var i, output;
|
117
|
-
for (i = 0; i < results.length; i++) {
|
118
|
-
// Beginning and end tokens should match the constants in QUnited::Driver::ResultsCollector
|
119
|
-
output = 'QUNITED_TEST_RESULT_START_TOKEN\n';
|
120
|
-
output += JSON.stringify(results[i], null, 1);
|
121
|
-
output += '\nQUNITED_TEST_RESULT_END_TOKEN';
|
122
|
-
java.lang.System.out.println(output);
|
123
|
-
}
|
124
|
-
});
|
12
|
+
// Load up the test document
|
13
|
+
window.location = arguments[1];
|
14
|
+
|
15
|
+
// Print the collected test results to stdout
|
16
|
+
(function(results) {
|
17
|
+
var tests, output, i, j;
|
18
|
+
for (i = 0; i < results.length; i++) {
|
19
|
+
tests = results[i].tests;
|
20
|
+
for (j = 0; j < tests.length; j++) {
|
21
|
+
output = 'QUNITED_TEST_RESULT_START_TOKEN';
|
22
|
+
output += QUnited.util.jsonStringify(tests[j]);
|
23
|
+
output += 'QUNITED_TEST_RESULT_END_TOKEN';
|
24
|
+
console.log(output);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
})(QUnited.collectedTestResults());
|
@@ -421,7 +421,7 @@ QUnit.assert = {
|
|
421
421
|
source = sourceFromStacktrace( 2 );
|
422
422
|
if ( source ) {
|
423
423
|
details.source = source;
|
424
|
-
msg += "<table><tr class='test-source'><th>Source: </th><td><
|
424
|
+
msg += "<table><tr class='test-source'><th>Source: </th><td><code>" + escapeInnerText( source ) + "</code></td></tr></table>";
|
425
425
|
}
|
426
426
|
}
|
427
427
|
runLoggingCallbacks( "log", QUnit, details );
|
@@ -742,18 +742,18 @@ extend( QUnit, {
|
|
742
742
|
if ( !result ) {
|
743
743
|
expected = escapeInnerText( QUnit.jsDump.parse(expected) );
|
744
744
|
actual = escapeInnerText( QUnit.jsDump.parse(actual) );
|
745
|
-
output += "<table><tr class='test-expected'><th>Expected: </th><td><
|
745
|
+
output += "<table><tr class='test-expected'><th>Expected: </th><td><code>" + expected + "</code></td></tr>";
|
746
746
|
|
747
747
|
if ( actual != expected ) {
|
748
|
-
output += "<tr class='test-actual'><th>Result: </th><td><
|
749
|
-
output += "<tr class='test-diff'><th>Diff: </th><td><
|
748
|
+
output += "<tr class='test-actual'><th>Result: </th><td><code>" + actual + "</code></td></tr>";
|
749
|
+
output += "<tr class='test-diff'><th>Diff: </th><td><code>" + QUnit.diff( expected, actual ) + "</code></td></tr>";
|
750
750
|
}
|
751
751
|
|
752
752
|
source = sourceFromStacktrace();
|
753
753
|
|
754
754
|
if ( source ) {
|
755
755
|
details.source = source;
|
756
|
-
output += "<tr class='test-source'><th>Source: </th><td><
|
756
|
+
output += "<tr class='test-source'><th>Source: </th><td><code>" + escapeInnerText( source ) + "</code></td></tr>";
|
757
757
|
}
|
758
758
|
|
759
759
|
output += "</table>";
|
@@ -780,7 +780,7 @@ extend( QUnit, {
|
|
780
780
|
|
781
781
|
if ( source ) {
|
782
782
|
details.source = source;
|
783
|
-
output += "<table><tr class='test-source'><th>Source: </th><td><
|
783
|
+
output += "<table><tr class='test-source'><th>Source: </th><td><code>" + escapeInnerText( source ) + "</code></td></tr></table>";
|
784
784
|
}
|
785
785
|
|
786
786
|
runLoggingCallbacks( "log", QUnit, details );
|
@@ -1835,4 +1835,4 @@ if ( typeof exports !== "undefined" ) {
|
|
1835
1835
|
}
|
1836
1836
|
|
1837
1837
|
// get at whatever the global object is, like window in browsers
|
1838
|
-
}( (function() {return this;}.call()) ));
|
1838
|
+
}( (function() {return this;}.call()) ));
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>QUnit Test Suite</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<h1 id="qunit-header">QUnit Test Suite</h1>
|
8
|
+
<h2 id="qunit-banner"></h2>
|
9
|
+
<div id="qunit-testrunner-toolbar"></div>
|
10
|
+
<h2 id="qunit-userAgent"></h2>
|
11
|
+
<ol id="qunit-tests"></ol>
|
12
|
+
<div id="qunit-fixture">
|
13
|
+
<% fixture_files.each do |fixture_file| %>
|
14
|
+
<%= read_file fixture_file %>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
<%= script_tag support_file_path('qunit.js') %>
|
19
|
+
<%= script_tag support_file_path('qunited.js') %>
|
20
|
+
|
21
|
+
<script type="text/javascript" charset="utf-8">
|
22
|
+
QUnited.startCollectingTestResults();
|
23
|
+
</script>
|
24
|
+
|
25
|
+
<% source_files.each do |source_file| %>
|
26
|
+
<%= script_tag source_file %>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<% test_files.each do |test_file| %>
|
30
|
+
<script>
|
31
|
+
QUnited.currentTestFile = "<%= test_file %>";
|
32
|
+
</script>
|
33
|
+
|
34
|
+
<%= script_tag test_file %>
|
35
|
+
<% end %>
|
36
|
+
</body>
|
37
|
+
</html>
|
@@ -74,14 +74,21 @@ module QUnited
|
|
74
74
|
def self.clean_up_result(test_result)
|
75
75
|
test_result = symbolize_keys(test_result)
|
76
76
|
test_result[:start] = DateTime.parse(test_result[:start])
|
77
|
-
test_result[:assertion_data].map! { |data| symbolize_keys data }
|
78
77
|
test_result
|
79
78
|
end
|
80
79
|
|
81
|
-
def self.symbolize_keys(
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
def self.symbolize_keys(obj)
|
81
|
+
case obj
|
82
|
+
when Hash
|
83
|
+
obj.inject({}) do |new_hash, (key, value)|
|
84
|
+
new_hash[key.to_sym] = symbolize_keys(value)
|
85
|
+
new_hash
|
86
|
+
end
|
87
|
+
when Array
|
88
|
+
obj.map { |x| symbolize_keys(x) }
|
89
|
+
else
|
90
|
+
obj
|
91
|
+
end
|
85
92
|
end
|
86
93
|
end
|
87
94
|
end
|
data/lib/qunited/rake_task.rb
CHANGED
@@ -34,6 +34,10 @@ module QUnited
|
|
34
34
|
# in order if specified as an array.
|
35
35
|
attr_accessor :helper_files
|
36
36
|
|
37
|
+
# Array or glob pattern of fixture files. These are included under the #qunit-fixture element
|
38
|
+
# on the test page. These will be included in order if specified as an array.
|
39
|
+
attr_accessor :fixture_files
|
40
|
+
|
37
41
|
# The driver to use to run the QUnit tests.
|
38
42
|
attr_accessor :driver
|
39
43
|
|
@@ -106,6 +110,7 @@ module QUnited
|
|
106
110
|
server_options = {
|
107
111
|
:source_files => source_and_helper_files,
|
108
112
|
:test_files => test_files_to_run,
|
113
|
+
:fixture_files => fixture_files_to_include,
|
109
114
|
:verbose => verbose
|
110
115
|
}
|
111
116
|
server_options[:port] = @server_port if @server_port
|
@@ -118,6 +123,7 @@ module QUnited
|
|
118
123
|
def test_command
|
119
124
|
cmd = 'qunited'
|
120
125
|
cmd << " --driver #{driver}" if driver
|
126
|
+
cmd << " --fixtures #{fixture_files_to_include.join(',')}" if fixture_files
|
121
127
|
cmd << " #{source_and_helper_files.join(' ')} -- #{test_files_to_run.join(' ')}"
|
122
128
|
end
|
123
129
|
|
@@ -129,6 +135,10 @@ module QUnited
|
|
129
135
|
files_array helper_files
|
130
136
|
end
|
131
137
|
|
138
|
+
def fixture_files_to_include
|
139
|
+
files_array fixture_files
|
140
|
+
end
|
141
|
+
|
132
142
|
def test_files_to_run
|
133
143
|
files_array test_files
|
134
144
|
end
|
data/lib/qunited/runner.rb
CHANGED
@@ -17,6 +17,10 @@ module QUnited
|
|
17
17
|
driver = driver_class.new(js_source_files, js_test_files)
|
18
18
|
driver.formatter = formatter_class.new({:driver_name => driver.name})
|
19
19
|
|
20
|
+
if options[:fixture_files]
|
21
|
+
driver.fixture_files = options[:fixture_files]
|
22
|
+
end
|
23
|
+
|
20
24
|
results = driver.run
|
21
25
|
|
22
26
|
results.all? { |r| r.passed? }
|
@@ -57,13 +61,13 @@ module QUnited
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def get_driver(klass)
|
60
|
-
if known_driver_classes.include?(klass)
|
64
|
+
if known_driver_classes.include?(klass.to_sym)
|
61
65
|
::QUnited::Driver.const_get(klass.to_s)
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
69
|
def get_formatter(klass)
|
66
|
-
if known_formatter_classes.include?(klass)
|
70
|
+
if known_formatter_classes.include?(klass.to_sym)
|
67
71
|
::QUnited::Formatter.const_get(klass.to_s)
|
68
72
|
end
|
69
73
|
end
|
@@ -10,16 +10,20 @@
|
|
10
10
|
<div id="qunit-testrunner-toolbar"></div>
|
11
11
|
<h2 id="qunit-userAgent"></h2>
|
12
12
|
<ol id="qunit-tests"></ol>
|
13
|
-
<div id="qunit-fixture"
|
14
|
-
|
15
|
-
<%=
|
13
|
+
<div id="qunit-fixture">
|
14
|
+
<% fixture_files.each do |file| %>
|
15
|
+
<%= include_fixture_file(file) %>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
16
18
|
|
17
|
-
|
18
|
-
<%= source_script_tag file %>
|
19
|
-
<% end %>
|
19
|
+
<%= qunited_asset_script_tag 'qunit.js' %>
|
20
20
|
|
21
|
-
<%
|
22
|
-
|
23
|
-
<% end %>
|
21
|
+
<% source_files.each do |file| %>
|
22
|
+
<%= source_script_tag file %>
|
23
|
+
<% end %>
|
24
24
|
|
25
|
+
<% test_files.each do |file| %>
|
26
|
+
<%= test_script_tag file %>
|
27
|
+
<% end %>
|
28
|
+
</body>
|
25
29
|
</html>
|
data/lib/qunited/server.rb
CHANGED
@@ -16,10 +16,12 @@ module QUnited
|
|
16
16
|
|
17
17
|
COFFEESCRIPT_EXTENSIONS = ['coffee', 'cs']
|
18
18
|
|
19
|
-
attr_accessor :source_files, :test_files
|
19
|
+
attr_accessor :source_files, :test_files, :fixture_files
|
20
20
|
|
21
21
|
def initialize(opts={})
|
22
|
-
@source_files
|
22
|
+
@source_files = opts[:source_files]
|
23
|
+
@test_files = opts[:test_files]
|
24
|
+
@fixture_files = opts[:fixture_files]
|
23
25
|
@port = opts[:port] || DEFAULT_PORT
|
24
26
|
|
25
27
|
server_options = {
|
@@ -81,6 +83,10 @@ module QUnited
|
|
81
83
|
script_tag "#{TEST_FILE_PREFIX}/#{file_path}"
|
82
84
|
end
|
83
85
|
|
86
|
+
def include_fixture_file(file_path)
|
87
|
+
IO.read(file_path)
|
88
|
+
end
|
89
|
+
|
84
90
|
def qunited_asset_script_tag(filename)
|
85
91
|
script_tag "#{QUNITED_ASSET_FILE_PREFIX}/#{filename}"
|
86
92
|
end
|
data/lib/qunited/version.rb
CHANGED
@@ -51,16 +51,6 @@ class TestRhinoDriver < MiniTest::Unit::TestCase
|
|
51
51
|
assert_equal 1, total_error_tests, 'Correct number of errors given'
|
52
52
|
end
|
53
53
|
|
54
|
-
def test_no_tests_in_test_file_means_failure
|
55
|
-
driver = QUnited::Driver::Rhino.new(
|
56
|
-
[File.join(FIXTURES_DIR, 'errors_project/app/assets/javascripts/no_error.js')],
|
57
|
-
[File.join(FIXTURES_DIR, 'errors_project/test/javascripts/this_test_has_no_tests.js')])
|
58
|
-
driver.run
|
59
|
-
|
60
|
-
@results = driver.results
|
61
|
-
assert @results.find { |r| r.failed? }, 'No tests in a file means failure'
|
62
|
-
end
|
63
|
-
|
64
54
|
private
|
65
55
|
|
66
56
|
def driver_class
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qunited
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: QUnited runs headless QUnit tests as part of your normal build
|
15
15
|
email:
|
@@ -31,7 +31,6 @@ files:
|
|
31
31
|
- lib/qunited/driver/base.rb
|
32
32
|
- lib/qunited/driver/phantomjs/phantomjs.rb
|
33
33
|
- lib/qunited/driver/phantomjs/support/runner.js
|
34
|
-
- lib/qunited/driver/phantomjs/support/tests_page.html.erb
|
35
34
|
- lib/qunited/driver/results_collector.rb
|
36
35
|
- lib/qunited/driver/rhino/rhino.rb
|
37
36
|
- lib/qunited/driver/rhino/support/env.rhino.js
|
@@ -39,6 +38,7 @@ files:
|
|
39
38
|
- lib/qunited/driver/rhino/support/runner.js
|
40
39
|
- lib/qunited/driver/support/qunit.js
|
41
40
|
- lib/qunited/driver/support/qunited.js
|
41
|
+
- lib/qunited/driver/support/tests_page.html.erb
|
42
42
|
- lib/qunited/formatter.rb
|
43
43
|
- lib/qunited/formatter/base.rb
|
44
44
|
- lib/qunited/formatter/dots.rb
|
@@ -66,7 +66,6 @@ files:
|
|
66
66
|
- test/fixtures/errors_project/app/assets/javascripts/syntax_error.js
|
67
67
|
- test/fixtures/errors_project/app/assets/javascripts/undefined_error.js
|
68
68
|
- test/fixtures/errors_project/test/javascripts/this_test_has_no_errors_in_it.js
|
69
|
-
- test/fixtures/errors_project/test/javascripts/this_test_has_no_tests.js
|
70
69
|
- test/fixtures/errors_project/test/javascripts/this_test_has_syntax_error.js
|
71
70
|
- test/fixtures/errors_project/test/javascripts/this_test_has_undefined_error.js
|
72
71
|
- test/fixtures/failures_project/app/assets/javascripts/application.js
|
@@ -119,7 +118,6 @@ test_files:
|
|
119
118
|
- test/fixtures/errors_project/app/assets/javascripts/syntax_error.js
|
120
119
|
- test/fixtures/errors_project/app/assets/javascripts/undefined_error.js
|
121
120
|
- test/fixtures/errors_project/test/javascripts/this_test_has_no_errors_in_it.js
|
122
|
-
- test/fixtures/errors_project/test/javascripts/this_test_has_no_tests.js
|
123
121
|
- test/fixtures/errors_project/test/javascripts/this_test_has_syntax_error.js
|
124
122
|
- test/fixtures/errors_project/test/javascripts/this_test_has_undefined_error.js
|
125
123
|
- test/fixtures/failures_project/app/assets/javascripts/application.js
|
@@ -1,31 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>QUnit Test Suite</title>
|
5
|
-
</head>
|
6
|
-
<body>
|
7
|
-
<h1 id="qunit-header">QUnit Test Suite</h1>
|
8
|
-
<h2 id="qunit-banner"></h2>
|
9
|
-
<div id="qunit-testrunner-toolbar"></div>
|
10
|
-
<h2 id="qunit-userAgent"></h2>
|
11
|
-
<ol id="qunit-tests"></ol>
|
12
|
-
<div id="qunit-fixture"></div>
|
13
|
-
</body>
|
14
|
-
<%= script_tag support_file_path('qunit.js') %>
|
15
|
-
<%= script_tag support_file_path('qunited.js') %>
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
QUnited.startCollectingTestResults();
|
19
|
-
</script>
|
20
|
-
|
21
|
-
<% source_files.each do |source_file| %>
|
22
|
-
<%= script_tag source_file %>
|
23
|
-
<% end %>
|
24
|
-
<% test_files.each do |test_file| %>
|
25
|
-
<script>
|
26
|
-
QUnited.currentTestFile = "<%= test_file %>";
|
27
|
-
</script>
|
28
|
-
<%= script_tag test_file %>
|
29
|
-
<% end %>
|
30
|
-
|
31
|
-
</html>
|