jcov 1.0.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 (45) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +5 -0
  3. data/LICENSE +19 -0
  4. data/README.rdoc +109 -0
  5. data/Rakefile +2 -0
  6. data/bin/jcov +36 -0
  7. data/examples/jasmine/.gitignore +1 -0
  8. data/examples/jasmine/jasmine/ConsoleReporter.js +177 -0
  9. data/examples/jasmine/jasmine/MIT.LICENSE.txt +20 -0
  10. data/examples/jasmine/jasmine/jasmine.js +2476 -0
  11. data/examples/jasmine/jasmine/runner.js +28 -0
  12. data/examples/jasmine/javascripts/mean.js +11 -0
  13. data/examples/jasmine/jcov.yml +8 -0
  14. data/examples/jasmine/tests/mean_spec.js +15 -0
  15. data/examples/jspec/.gitignore +1 -0
  16. data/examples/jspec/javascripts/mean.js +11 -0
  17. data/examples/jspec/jcov.yml +8 -0
  18. data/examples/jspec/jspec/ext/slowness.js +43 -0
  19. data/examples/jspec/jspec/ext/trace.js +28 -0
  20. data/examples/jspec/jspec/lib/MIT.LICENSE.txt +7 -0
  21. data/examples/jspec/jspec/lib/jspec.js +1925 -0
  22. data/examples/jspec/jspec/runner.js +66 -0
  23. data/examples/jspec/tests/mean_spec.js +15 -0
  24. data/features/configuration.feature +134 -0
  25. data/features/coverage.feature +246 -0
  26. data/features/html_report.feature +130 -0
  27. data/features/javascript_interface.feature +72 -0
  28. data/features/reporting.feature +108 -0
  29. data/features/run.feature +217 -0
  30. data/features/step_definitions/report_steps.rb +54 -0
  31. data/features/support/env.rb +29 -0
  32. data/jcov.gemspec +29 -0
  33. data/lib/jcov.rb +11 -0
  34. data/lib/jcov/commands.rb +47 -0
  35. data/lib/jcov/configuration.rb +54 -0
  36. data/lib/jcov/coverage.rb +151 -0
  37. data/lib/jcov/reporter.rb +2 -0
  38. data/lib/jcov/reporter/console_reporter.rb +107 -0
  39. data/lib/jcov/reporter/file.html.erb +26 -0
  40. data/lib/jcov/reporter/html_reporter.rb +64 -0
  41. data/lib/jcov/reporter/report.css +53 -0
  42. data/lib/jcov/reporter/report.html.erb +45 -0
  43. data/lib/jcov/runner.rb +100 -0
  44. data/lib/jcov/version.rb +3 -0
  45. metadata +195 -0
@@ -0,0 +1,66 @@
1
+ // JSpec reporter uses print as println
2
+ print = println;
3
+
4
+ load('jspec/lib/jspec.js');
5
+
6
+ load('jspec/ext/slowness.js')
7
+
8
+ JSpec._globalScope = this;
9
+
10
+ JSpec._globals = {};
11
+ // capture the current globals
12
+ JSpec.captureGlobals = function () {
13
+ for (var i in JSpec._globalScope) {
14
+ JSpec._globals[i] = true;
15
+ }
16
+ };
17
+ // remove globals we haven't previously captured
18
+ JSpec.cullGlobals = function () {
19
+ for (var i in JSpec._globalScope) {
20
+ if (!JSpec._globals[i]) {
21
+ delete JSpec._globalScope[i];
22
+ }
23
+ }
24
+ };
25
+
26
+ if (JCov.options.verbose) {
27
+ load('jspec/ext/trace.js')
28
+ } else {
29
+ JSpec.include({
30
+ afterSpec: function (spec) {
31
+ putc((spec.requiresImplementation()) ? '*' : (spec.passed()) ? '.' : 'F');
32
+ }
33
+ });
34
+ }
35
+
36
+ JSpec.include({
37
+ afterSuite: function (suite) {
38
+ if (!suite.name) { // it's the top level suite
39
+ JSpec.cullGlobals();
40
+ }
41
+ }
42
+ });
43
+
44
+ // defining quit so jspec doesn't complain
45
+ quit = function () {
46
+ };
47
+
48
+ TESTS = JCov.tests;
49
+
50
+ if (TESTS.length == 1) {
51
+ print("Testing '"+TESTS[0]+"'");
52
+ }
53
+
54
+ thing = JSpec;
55
+ for (var i = 0; i < TESTS.length; i++) {
56
+ thing = thing.exec(TESTS[i]);
57
+ }
58
+
59
+ JSpec.captureGlobals();
60
+
61
+ thing
62
+ .run({reporter: JSpec.reporters.Terminal,
63
+ failuresOnly: true,
64
+ fixturePath: 'jspec/fixtures',
65
+ disableColors: !JCov.options.color})
66
+ .report();
@@ -0,0 +1,15 @@
1
+ describe("mean.js", function () {
2
+ before(function () {
3
+ load("javascripts/mean.js");
4
+ });
5
+
6
+ describe("Math.prototype.mean", function () {
7
+ it("returns the average for an array of numbers", function () {
8
+ Math.mean([1,2,3,4,5,10]).should.equal 4.166666666666667
9
+ });
10
+
11
+ it("returns 0 for empty arrays", function () {
12
+ Math.mean([]).should.equal 0
13
+ });
14
+ });
15
+ });
@@ -0,0 +1,134 @@
1
+ Feature: configuration
2
+ In order to use this tool effectively,
3
+ I want to configure it for my environment.
4
+
5
+ Background:
6
+ Given a file named "config/jcov.yml" with:
7
+ """
8
+ threshold: 76.8
9
+ threshold_must_match: true
10
+ """
11
+
12
+ Scenario: it can print out its loaded configuration
13
+ When I run `jcov check`
14
+ Then the output should contain:
15
+ """
16
+ threshold: 76.8
17
+ threshold_must_match: true
18
+ """
19
+
20
+ Scenario: it can have its configuration location overridden
21
+ Given a file named "foo/bar.yml" with:
22
+ """
23
+ threshold: 10
24
+ """
25
+ When I run `jcov check --config=foo/bar.yml`
26
+ Then the output should contain:
27
+ """
28
+ threshold: 10
29
+ """
30
+
31
+ Scenario: looks for its configuration in a set of logical places
32
+ Given a file named "jcov.yml" with:
33
+ """
34
+ threshold: 33
35
+ """
36
+ When I remove the file "config/jcov.yml"
37
+ When I run `jcov check`
38
+ Then the output should contain:
39
+ """
40
+ threshold: 33
41
+ """
42
+
43
+ Scenario: uses its default configuration if it can't find a configuration file
44
+ When I remove the file "config/jcov.yml"
45
+ When I run `jcov check`
46
+ Then the output should contain:
47
+ """
48
+ source_directory: public/javascripts
49
+ """
50
+
51
+ Scenario: it merges configuration with the defaults
52
+ When I run `jcov check`
53
+ Then the output should contain:
54
+ """
55
+ source_directory: public/javascripts
56
+ """
57
+ And the output should contain:
58
+ """
59
+ threshold: 76.8
60
+ """
61
+
62
+ Scenario: it complains if we provide a configuration file that doesn't exist
63
+ When I run `jcov check --config=not/a/file.yml`
64
+ Then the output should contain:
65
+ """
66
+ Cannot find file "not/a/file.yml"
67
+ """
68
+
69
+ Scenario: configures where to look for the test files
70
+ When I run `jcov check`
71
+ Then the output should contain:
72
+ """
73
+ test_directory:
74
+ """
75
+
76
+ Scenario: configures where to find the source files
77
+ When I run `jcov check`
78
+ Then the output should contain:
79
+ """
80
+ source_directory:
81
+ """
82
+
83
+ Scenario: configures which javascript file runs the tests
84
+ When I run `jcov check`
85
+ Then the output should contain:
86
+ """
87
+ test_runner:
88
+ """
89
+
90
+ Scenario: configures where to look for errors in javascript land
91
+ When I run `jcov check`
92
+ Then the output should contain:
93
+ """
94
+ error_field:
95
+ """
96
+
97
+ Scenario: has defaults for all the configuration values
98
+ When I remove the file "config/jcov.yml"
99
+ When I run `jcov check`
100
+ Then the output should contain:
101
+ """
102
+ test_directory: test/javascripts
103
+ """
104
+ And the output should contain:
105
+ """
106
+ source_directory: public/javascripts
107
+ """
108
+ And the output should contain:
109
+ """
110
+ test_runner: test/javascripts/runner.js
111
+ """
112
+ And the output should contain:
113
+ """
114
+ error_field: error_count
115
+ """
116
+ And the output should contain:
117
+ """
118
+ report_output_directory: jcov
119
+ """
120
+
121
+ Scenario: it prints out what file it is using
122
+ When I run `jcov check`
123
+ Then the output should contain:
124
+ """
125
+ Using configuration file: config/jcov.yml
126
+ """
127
+
128
+ Scenario: if it can't find a file it tells us that
129
+ When I remove the file "config/jcov.yml"
130
+ When I run `jcov check`
131
+ Then the output should contain:
132
+ """
133
+ No configuration file! Using defaults.
134
+ """
@@ -0,0 +1,246 @@
1
+ Feature: coverage
2
+ In order to make sure code is being executed
3
+ I want to report coverage statistics
4
+
5
+ Background:
6
+ Given a file named "public/javascripts/foo.js" with:
7
+ """
8
+ var one = "foo"; // 1
9
+ var z = 0; // 2
10
+
11
+ var two = function () { // 3
12
+ for (var i = 0; i < 10; i++) { // 4
13
+ z++; // 5
14
+ }
15
+ };
16
+
17
+ var three = function () { // 6
18
+ two(); // 7
19
+ };
20
+
21
+ """
22
+ And a file named "test/javascripts/runner.js" with:
23
+ """
24
+ load("public/javascripts/foo.js");
25
+ error_count = 0;
26
+ """
27
+
28
+ Scenario: it will report coverage
29
+ When I run `jcov`
30
+ Then the output should contain:
31
+ """
32
+ Total Coverage: (4/7) 57.1%
33
+ """
34
+
35
+ Scenario: it will not report coverage when disabled
36
+ When I run `jcov --no-coverage`
37
+ Then the output should not contain:
38
+ """
39
+ Total Coverage:
40
+ """
41
+
42
+ Scenario: it will report slightly more coverage
43
+ Given a file named "test/javascripts/runner.js" with:
44
+ """
45
+ load("public/javascripts/foo.js");
46
+ two();
47
+ error_count = 0;
48
+ """
49
+ When I run `jcov`
50
+ Then the output should contain:
51
+ """
52
+ Total Coverage: (6/7) 85.7%
53
+ """
54
+
55
+ Scenario: it will report full coverage
56
+ Given a file named "test/javascripts/runner.js" with:
57
+ """
58
+ load("public/javascripts/foo.js");
59
+ three();
60
+ error_count = 0;
61
+ """
62
+ When I run `jcov`
63
+ Then the output should contain:
64
+ """
65
+ Total Coverage: (7/7) 100.0%
66
+ """
67
+
68
+ Scenario: it reports correctly if we don't load any files
69
+ Given a file named "test/javascripts/runner.js" with:
70
+ """
71
+ error_count = 0;
72
+ """
73
+ When I run `jcov`
74
+ Then the output should contain:
75
+ """
76
+ Total Coverage: (0/7) 0.0%
77
+ """
78
+
79
+ Scenario: it will report coverage across all files even if they're not loaded
80
+ Given a file named "test/javascripts/runner.js" with:
81
+ """
82
+ load("public/javascripts/foo.js");
83
+ three();
84
+ error_count = 0;
85
+ """
86
+ And a file named "public/javascripts/bar.js" with:
87
+ """
88
+ var foo = 1;
89
+ var bar = 2;
90
+ var baz = 3;
91
+ """
92
+ When I run `jcov`
93
+ Then the output should contain:
94
+ """
95
+ Total Coverage: (7/10) 70.0%
96
+ """
97
+
98
+ Scenario: reports an error message if the coverage is below the threshold
99
+ Given a file named "jcov.yml" with:
100
+ """
101
+ threshold: 80
102
+ """
103
+ When I run `jcov`
104
+ Then the output should contain:
105
+ """
106
+ FAIL! Coverage is lower than threshold! 57.1% < 80% :(
107
+ """
108
+
109
+ Scenario: doesn't report an error message if the coverage is above the threshold
110
+ Given a file named "jcov.yml" with:
111
+ """
112
+ threshold: 40
113
+ """
114
+ When I run `jcov`
115
+ Then the output should not contain:
116
+ """
117
+ FAIL!
118
+ """
119
+
120
+ Scenario: reports an error message if the coverage is above the threshold and threshold_must_match == true
121
+ Given a file named "jcov.yml" with:
122
+ """
123
+ threshold: 40
124
+ threshold_must_match: true
125
+ """
126
+ When I run `jcov`
127
+ Then the output should contain:
128
+ """
129
+ Coverage does not match threshold! 57.1% != 40%
130
+ """
131
+
132
+ Scenario: tells you where to update threshold if it does not match
133
+ Given a file named "jcov.yml" with:
134
+ """
135
+ threshold: 40
136
+ threshold_must_match: true
137
+ """
138
+ When I run `jcov`
139
+ Then the output should contain:
140
+ """
141
+ Please raise the threshold in ./jcov.yml
142
+ """
143
+
144
+ Scenario: tells you where to update threshold if it does not match even if the file is not in a typical location
145
+ Given a file named "foo/bar/jcov.yml" with:
146
+ """
147
+ threshold: 40
148
+ threshold_must_match: true
149
+ """
150
+ When I run `jcov --config foo/bar/jcov.yml`
151
+ Then the output should contain:
152
+ """
153
+ Please raise the threshold in foo/bar/jcov.yml
154
+ """
155
+
156
+ Scenario: doesn't report a threshold error message if the threshold is not set
157
+ When I run `jcov`
158
+ Then the output should not contain:
159
+ """
160
+ FAIL!
161
+ """
162
+
163
+ Scenario: returns a zero exit status if coverage is above the threshold
164
+ Given a file named "jcov.yml" with:
165
+ """
166
+ threshold: 40
167
+ """
168
+ When I run `jcov`
169
+ And the exit status should be 0
170
+
171
+ Scenario: returns a non-zero exit status if coverage is below the threshold
172
+ Given a file named "jcov.yml" with:
173
+ """
174
+ threshold: 80
175
+ """
176
+ When I run `jcov`
177
+ And the exit status should not be 0
178
+
179
+ Scenario: returns a non-zero exit status if coverage is above the threshold and threshold_must_match == true
180
+ Given a file named "jcov.yml" with:
181
+ """
182
+ threshold: 40
183
+ threshold_must_match = true
184
+ """
185
+ When I run `jcov`
186
+ Then the exit status should not be 0
187
+
188
+ Scenario: gives a helpful message if no files were checked for coverage
189
+ Given a file named "jcov.yml" with:
190
+ """
191
+ ignore:
192
+ - foo
193
+ """
194
+ When I run `jcov`
195
+ Then the output should contain:
196
+ """
197
+ No files were checked for coverage. Maybe your ignore list in ./jcov.yml is too inclusive?
198
+ """
199
+
200
+ Scenario: don't check coverage if we're running focused tests
201
+ Given a file named "jcov.yml" with:
202
+ """
203
+ threshold: 80
204
+ """
205
+ When I run `jcov public/javascripts/foo.js`
206
+ Then the exit status should be 0
207
+ And the output should not contain "FAIL"
208
+ And the output should not contain "Total Coverage"
209
+
210
+ Scenario: don't check coverage if we're running regex focused tests
211
+ Given a file named "jcov.yml" with:
212
+ """
213
+ threshold: 80
214
+ """
215
+ When I run `jcov --test foo`
216
+ Then the exit status should be 0
217
+ And the output should not contain "FAIL"
218
+ And the output should not contain "Total Coverage"
219
+
220
+
221
+ Scenario: functions should be reported as covered
222
+ Given a file named "public/javascripts/foo.js" with:
223
+ """
224
+ function foo() {
225
+ var bar = 0;
226
+ }
227
+ """
228
+ When I run `jcov`
229
+ Then the output should contain:
230
+ """
231
+ Total Coverage: (1/2) 50.0%
232
+ """
233
+
234
+ Scenario: ignores comments
235
+ Given a file named "public/javascripts/foo.js" with:
236
+ """
237
+ // one
238
+ // two
239
+ var bar = 0;
240
+ // three
241
+ """
242
+ When I run `jcov`
243
+ Then the output should contain:
244
+ """
245
+ Total Coverage: (1/1) 100.0%
246
+ """