js-test-driver-rails 0.3.4 → 0.4.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.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  jsTestDriver.conf
5
5
  pkg/*
6
6
  tags
7
+ .js_test_driver
data/README.markdown CHANGED
@@ -76,6 +76,21 @@ If you want to user Jasmine, simply add:
76
76
 
77
77
  in your config file, somewhere before including your test files and you are golden:)
78
78
 
79
+ Measuring code coverage
80
+ -----------------------
81
+
82
+ JsTestDriver has a pretty cool feature of being able to measure code coverage. To enable this in your config, you just need to add:
83
+
84
+ measure_coverage
85
+
86
+ in your config file.
87
+
88
+ You need to have lcov installed for the HTML report to be generated:
89
+
90
+ sudo apt-get install lcov
91
+
92
+ The HTML coverage report will be saved in the .js_test_driver/tests/coverage directory.
93
+
79
94
  Rake tasks
80
95
  ----------
81
96
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake/testtask'
2
2
 
3
3
  Rake::TestTask.new("test") do |test|
4
4
  test.libs << 'test'
5
- test.pattern = 'test/unit/**/*_test.rb'
5
+ test.pattern = 'test/**/*_test.rb'
6
6
  test.verbose = true
7
7
  end
8
8
 
@@ -59,12 +59,29 @@ module JsTestDriver
59
59
  #
60
60
  # There's no hacks or modifications here, so this method is just for the users convenience
61
61
  def enable_jasmine
62
- this_directory = File.dirname(__FILE__)
63
- vendor_directory = File.expand_path(File.join('..', '..', 'vendor'), this_directory)
64
62
  includes File.join(vendor_directory, "jasmine.js")
65
63
  includes File.join(vendor_directory, "JasmineAdapter.js")
66
64
  end
67
65
 
66
+ # Adds a JsTestDriver plugin for measuring coverage to the configuration
67
+ def measure_coverage
68
+ @measure_coverage = true
69
+ self.plugins << {
70
+ 'name' => 'coverage',
71
+ 'jar' => File.join(vendor_directory, 'coverage.jar'),
72
+ 'module' => 'com.google.jstestdriver.coverage.CoverageModule'
73
+ }
74
+ end
75
+
76
+ def measure_coverage?
77
+ !!@measure_coverage
78
+ end
79
+
80
+ # Plugins to include in the config
81
+ def plugins
82
+ @plugins ||= []
83
+ end
84
+
68
85
  # config variable which has a regular setter,
69
86
  # but also can be set by calling the "getter" with an argument
70
87
  # and if called without an argument the getter will return the passed block
@@ -125,6 +142,7 @@ module JsTestDriver
125
142
  hash = {'server' => server, 'basepath' => base_path}
126
143
  hash['load'] = loaded_files unless loaded_files.empty?
127
144
  hash['exclude'] = map_paths(excluded_files) unless excluded_files.empty?
145
+ hash['plugin'] = plugins unless plugins.empty?
128
146
  return hash.to_yaml
129
147
  end
130
148
 
@@ -153,6 +171,11 @@ module JsTestDriver
153
171
 
154
172
  private
155
173
 
174
+ def vendor_directory
175
+ this_directory = File.dirname(__FILE__)
176
+ return File.expand_path(File.join('..', '..', 'vendor'), this_directory)
177
+ end
178
+
156
179
  def expand_globs(paths)
157
180
  with_expanded_paths = paths.map{|path| File.expand_path(path)}
158
181
  return with_expanded_paths.map{|path| path.include?('*') ? Dir[path] : path}.flatten
@@ -83,7 +83,7 @@ module JsTestDriver
83
83
  command.run
84
84
  end
85
85
 
86
- def start_server_capture_and_run(tests, browsers, output_xml_path = nil, console = nil)
86
+ def start_server_capture_and_run(tests = nil, browsers = nil, output_xml_path = nil, console = nil)
87
87
  command = execute_jar
88
88
 
89
89
  add_start_server(command)
@@ -93,7 +93,13 @@ module JsTestDriver
93
93
  add_output_directory(command, output_xml_path) if output_xml_path
94
94
  add_capture_console(command) if console
95
95
 
96
- command.run
96
+ result = command.run
97
+
98
+ if config.measure_coverage? && output_xml_path
99
+ generate_html_coverage_report(output_xml_path)
100
+ end
101
+
102
+ return result
97
103
  end
98
104
 
99
105
  def add_start_server(command)
@@ -129,8 +135,28 @@ module JsTestDriver
129
135
  Command.new('java').option('-jar', jar_path)
130
136
  end
131
137
 
138
+ def generate_html_coverage_report(output_path)
139
+ unless genhtml_installed?
140
+ puts "Could not find genhtml. You must install lcov (sudo apt-get install lcov)"
141
+ return
142
+ end
143
+
144
+ output_path = File.expand_path(output_path)
145
+
146
+ config_file_name = File.basename(config_yml_path)
147
+ coverage_file_name = config_file_name + '-coverage.dat'
148
+ coverage_file_path = File.join(output_path, coverage_file_name)
149
+ coverage_out_dir = File.join(output_path, 'coverage')
150
+
151
+ system("genhtml -o #{coverage_out_dir} #{coverage_file_path}")
152
+ end
153
+
132
154
  protected
133
155
 
156
+ def genhtml_installed?
157
+ !%x[which genhtml].strip.empty?
158
+ end
159
+
134
160
  def parse_config
135
161
  source = ""
136
162
  if File.exist?(config_path)
@@ -1,3 +1,3 @@
1
1
  module JsTestDriver
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
2
+
3
+ module JsTestDriver
4
+ class SampleTest < Test::Unit::TestCase
5
+
6
+ def test_running_sample_specs
7
+ config = JsTestDriver::Runner.new(:config_path => File.expand_path('../../sample/config/js_test_driver.rb', __FILE__))
8
+
9
+ output_path = File.expand_path('../../../.js_test_driver/', __FILE__)
10
+
11
+ assert config.start_server_capture_and_run(nil, nil, output_path), 'running tests should return a success'
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ includes 'test/sample/lib/*.js'
2
+
3
+ ['google-chrome', 'firefox', 'chromium-browser'].select{|b| !%x[which #{b}].strip.empty? }.each do |b|
4
+ browser b
5
+ end
6
+
7
+ enable_jasmine
8
+ measure_coverage
9
+
10
+ includes 'test/sample/specs/spec_helper.js'
11
+ includes 'test/sample/specs/**/*_spec.js'
@@ -0,0 +1,15 @@
1
+ function Calculator(initialValue) {
2
+ this.value = initialValue;
3
+ }
4
+
5
+ Calculator.prototype = {
6
+ add: function(val) {
7
+ this.value += val;
8
+ },
9
+ multiply: function(val) {
10
+ this.value *= val;
11
+ },
12
+ sub: function(val) {
13
+ this.value -= val;
14
+ }
15
+ };
@@ -0,0 +1,19 @@
1
+ describe('Calculator', function () {
2
+ var calc;
3
+
4
+ beforeEach(function () {
5
+ calc = new Calculator(2);
6
+ });
7
+
8
+ it('adds values', function() {
9
+ calc.add(2);
10
+
11
+ expect(calc.value).toEqual(4);
12
+ });
13
+
14
+ it('multiplies values', function() {
15
+ calc.multiply(3);
16
+
17
+ expect(calc.value).toEqual(6);
18
+ });
19
+ });
@@ -0,0 +1,4 @@
1
+ // nothing to see here
2
+
3
+ function hello() {
4
+ }
@@ -253,5 +253,18 @@ module JsTestDriver
253
253
  assert Dir[config.included_files[1]].size > 0
254
254
  end
255
255
 
256
+ def test_with_coverage_measuring_enabled
257
+ # given
258
+ config = given_an_empty_config
259
+
260
+ # when
261
+ config.measure_coverage
262
+
263
+ # then
264
+ assert_config_includes config, 'plugin' => [{'name' => 'coverage',
265
+ 'jar' => File.expand_path('../../../vendor/coverage.jar', __FILE__),
266
+ 'module' => 'com.google.jstestdriver.coverage.CoverageModule'}]
267
+ end
268
+
256
269
  end
257
270
  end
@@ -92,5 +92,16 @@ module JsTestDriver
92
92
  runner.start_server_capture_and_run('TestCase', 'aaa,bbb', '.js_test_driver', true)
93
93
  end
94
94
 
95
+ def test_when_measuring_coverage
96
+ config = JsTestDriver::Config.new
97
+ config.measure_coverage
98
+ runner = given_a_runner(:config => config)
99
+
100
+ JsTestDriver::Runner::Command.any_instance.expects(:system)
101
+ runner.expects(:system).with("genhtml -o #{File.expand_path('.js_test_driver/coverage')} #{File.expand_path('.js_test_driver/jsTestDriver.conf-coverage.dat')}")
102
+
103
+ runner.start_server_capture_and_run(nil, 'aaa', '.js_test_driver')
104
+ end
105
+
95
106
  end
96
107
  end
Binary file
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
7
  - 4
9
- version: 0.3.4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Pohorecki
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-20 00:00:00 +02:00
17
+ date: 2011-04-27 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -87,12 +87,18 @@ files:
87
87
  - test/fixtures/foo/a.html
88
88
  - test/fixtures/foo/bar/a.html
89
89
  - test/fixtures/hello.txt
90
+ - test/integration/sample_test.rb
91
+ - test/sample/config/js_test_driver.rb
92
+ - test/sample/lib/calculator.js
93
+ - test/sample/specs/calculator_spec.js
94
+ - test/sample/specs/spec_helper.js
90
95
  - test/test_helper.rb
91
96
  - test/unit/config_test.rb
92
97
  - test/unit/html_fixture_test.rb
93
98
  - test/unit/runner_test.rb
94
99
  - vendor/JasmineAdapter.js
95
100
  - vendor/VERSIONS
101
+ - vendor/coverage.jar
96
102
  - vendor/jasmine.js
97
103
  - vendor/js_test_driver.jar
98
104
  has_rdoc: true