jcov 1.0.1 → 1.1
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/bin/jcov +1 -0
- data/examples/jasmine/javascripts/mean.js +15 -0
- data/features/coverage.feature +8 -13
- data/features/html_report.feature +3 -3
- data/features/instrumentation.feature +310 -0
- data/features/javascript_interface.feature +36 -0
- data/features/run.feature +16 -4
- data/jcov.gemspec +1 -2
- data/lib/jcov.rb +5 -1
- data/lib/jcov/commands.rb +7 -7
- data/lib/jcov/configuration.rb +9 -3
- data/lib/jcov/context.rb +17 -0
- data/lib/jcov/context/instrumentation_context.rb +31 -0
- data/lib/jcov/context/run_context.rb +44 -0
- data/lib/jcov/coverage.rb +55 -130
- data/lib/jcov/errors.rb +6 -0
- data/lib/jcov/js/parser.js +44 -0
- data/lib/jcov/loader.rb +92 -0
- data/lib/jcov/reporter/console_reporter.rb +3 -7
- data/lib/jcov/reporter/html_reporter.rb +1 -1
- data/lib/jcov/runner.rb +22 -62
- data/lib/jcov/version.rb +1 -1
- data/vendor/acorn.js +1711 -0
- data/vendor/walk.js +305 -0
- metadata +13 -19
data/bin/jcov
CHANGED
@@ -13,6 +13,7 @@ global_option '--no-color', 'Disable color output'
|
|
13
13
|
global_option '--no-coverage', 'Disable coverage output'
|
14
14
|
global_option '--report', 'Report test coverage'
|
15
15
|
global_option '--test REGEX', 'Limit the tests to only the ones that match the regular expression'
|
16
|
+
global_option '--dump', 'Dump instrumented Javascript for debugging purposes'
|
16
17
|
global_option '-c', '--config FILE', 'Specify a configuration file to use'
|
17
18
|
|
18
19
|
default_command :run
|
data/features/coverage.feature
CHANGED
@@ -217,30 +217,25 @@ Feature: coverage
|
|
217
217
|
And the output should not contain "FAIL"
|
218
218
|
And the output should not contain "Total Coverage"
|
219
219
|
|
220
|
-
|
221
|
-
Scenario: functions should be reported as covered
|
220
|
+
Scenario: it handles syntax errors gracefully
|
222
221
|
Given a file named "public/javascripts/foo.js" with:
|
223
222
|
"""
|
224
|
-
|
225
|
-
|
226
|
-
}
|
223
|
+
// yep
|
224
|
+
var bar = \foo;
|
227
225
|
"""
|
228
226
|
When I run `jcov`
|
229
227
|
Then the output should contain:
|
230
228
|
"""
|
231
|
-
|
229
|
+
error: Expecting Unicode escape sequence \uXXXX (2:11) in public/javascripts/foo.js
|
232
230
|
"""
|
233
231
|
|
234
|
-
Scenario:
|
235
|
-
Given a file named "public/javascripts/
|
232
|
+
Scenario: uncovered files with a syntax error should not cause a problem when loaded (Issue #3)
|
233
|
+
Given a file named "public/javascripts/notrun.js" with:
|
236
234
|
"""
|
237
|
-
|
238
|
-
// two
|
239
|
-
var bar = 0;
|
240
|
-
// three
|
235
|
+
this will cause a syntax error because it's not actual javascript
|
241
236
|
"""
|
242
237
|
When I run `jcov`
|
243
238
|
Then the output should contain:
|
244
239
|
"""
|
245
|
-
|
240
|
+
error: Unexpected token (1:5) in public/javascripts/notrun.js
|
246
241
|
"""
|
@@ -17,9 +17,9 @@ Feature: HTML Report
|
|
17
17
|
}
|
18
18
|
};
|
19
19
|
|
20
|
-
|
20
|
+
function three() { // 6
|
21
21
|
two(); // 7
|
22
|
-
}
|
22
|
+
}
|
23
23
|
|
24
24
|
"""
|
25
25
|
|
@@ -103,7 +103,7 @@ Feature: HTML Report
|
|
103
103
|
| var one = "foo"; |
|
104
104
|
| var z = 0; |
|
105
105
|
| var two = function () { |
|
106
|
-
|
|
106
|
+
| function three() { |
|
107
107
|
|
108
108
|
Scenario: see uncovered lines
|
109
109
|
When I run `jcov --report`
|
@@ -0,0 +1,310 @@
|
|
1
|
+
Feature: instrumentation
|
2
|
+
In order to report coverage statistics
|
3
|
+
I need to instrument the running javascript
|
4
|
+
|
5
|
+
Background:
|
6
|
+
Given a file named "test/javascripts/runner.js" with:
|
7
|
+
"""
|
8
|
+
load("public/javascripts/foo.js");
|
9
|
+
error_count = 0;
|
10
|
+
"""
|
11
|
+
|
12
|
+
Scenario: it dumps instrumented file contents when a flag is set
|
13
|
+
Given a file named "public/javascripts/foo.js" with:
|
14
|
+
"""
|
15
|
+
var bar = 0;
|
16
|
+
"""
|
17
|
+
When I run `jcov --dump --trace`
|
18
|
+
Then the output should contain:
|
19
|
+
"""
|
20
|
+
_coverage_tick('public/javascripts/foo.js', 1);var bar = 0;
|
21
|
+
"""
|
22
|
+
|
23
|
+
Scenario: functions should be covered
|
24
|
+
Given a file named "public/javascripts/foo.js" with:
|
25
|
+
"""
|
26
|
+
function foo() {
|
27
|
+
var bar = 0;
|
28
|
+
}
|
29
|
+
"""
|
30
|
+
When I run `jcov --dump`
|
31
|
+
Then the output should contain:
|
32
|
+
"""
|
33
|
+
_coverage_tick('public/javascripts/foo.js', 1);function foo() {
|
34
|
+
_coverage_tick('public/javascripts/foo.js', 2);var bar = 0;
|
35
|
+
}
|
36
|
+
"""
|
37
|
+
|
38
|
+
Scenario: ignores comments
|
39
|
+
Given a file named "public/javascripts/foo.js" with:
|
40
|
+
"""
|
41
|
+
// one
|
42
|
+
// two
|
43
|
+
var bar = 0;
|
44
|
+
// three
|
45
|
+
"""
|
46
|
+
When I run `jcov --dump`
|
47
|
+
Then the output should contain:
|
48
|
+
"""
|
49
|
+
// one
|
50
|
+
// two
|
51
|
+
_coverage_tick('public/javascripts/foo.js', 3);var bar = 0;
|
52
|
+
// three
|
53
|
+
"""
|
54
|
+
|
55
|
+
Scenario: it handles object definitions with function values
|
56
|
+
Given a file named "public/javascripts/foo.js" with:
|
57
|
+
"""
|
58
|
+
var obj = {
|
59
|
+
foo: function () {
|
60
|
+
var test = 0;
|
61
|
+
}
|
62
|
+
};
|
63
|
+
|
64
|
+
obj.foo();
|
65
|
+
"""
|
66
|
+
When I run `jcov --dump`
|
67
|
+
Then the output should contain:
|
68
|
+
"""
|
69
|
+
_coverage_tick('public/javascripts/foo.js', 1);var obj = {
|
70
|
+
foo: function () {
|
71
|
+
_coverage_tick('public/javascripts/foo.js', 3);var test = 0;
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
_coverage_tick('public/javascripts/foo.js', 7);obj.foo();
|
76
|
+
"""
|
77
|
+
|
78
|
+
Scenario: it handles else if statements correctly
|
79
|
+
Given a file named "public/javascripts/foo.js" with:
|
80
|
+
"""
|
81
|
+
if (false) {
|
82
|
+
var one = 1;
|
83
|
+
}
|
84
|
+
else if (true) {
|
85
|
+
var two = 2;
|
86
|
+
}
|
87
|
+
"""
|
88
|
+
When I run `jcov --dump`
|
89
|
+
Then the output should contain:
|
90
|
+
"""
|
91
|
+
_coverage_tick('public/javascripts/foo.js', 1);if (false) {
|
92
|
+
_coverage_tick('public/javascripts/foo.js', 2);var one = 1;
|
93
|
+
}
|
94
|
+
else if (true) {
|
95
|
+
_coverage_tick('public/javascripts/foo.js', 5);var two = 2;
|
96
|
+
}
|
97
|
+
"""
|
98
|
+
|
99
|
+
Scenario: it handles broken up if statements
|
100
|
+
Given a file named "public/javascripts/foo.js" with:
|
101
|
+
"""
|
102
|
+
var foo = 3;
|
103
|
+
if (foo > 1 &&
|
104
|
+
foo < 8) {
|
105
|
+
var bar = 2;
|
106
|
+
}
|
107
|
+
"""
|
108
|
+
When I run `jcov --dump`
|
109
|
+
Then the output should contain:
|
110
|
+
"""
|
111
|
+
_coverage_tick('public/javascripts/foo.js', 1);var foo = 3;
|
112
|
+
_coverage_tick('public/javascripts/foo.js', 2);if (foo > 1 &&
|
113
|
+
foo < 8) {
|
114
|
+
_coverage_tick('public/javascripts/foo.js', 4);var bar = 2;
|
115
|
+
}
|
116
|
+
"""
|
117
|
+
|
118
|
+
Scenario: it handles weirdly formatted case statements
|
119
|
+
Given a file named "public/javascripts/foo.js" with:
|
120
|
+
"""
|
121
|
+
var foo = 'bar';
|
122
|
+
switch (foo) {
|
123
|
+
case 'bar': wibble = 1;
|
124
|
+
break;
|
125
|
+
case 'baz': wibble = 2;
|
126
|
+
break;
|
127
|
+
default:
|
128
|
+
wibble = 3;
|
129
|
+
}
|
130
|
+
"""
|
131
|
+
When I run `jcov --dump`
|
132
|
+
Then the output should contain:
|
133
|
+
"""
|
134
|
+
_coverage_tick('public/javascripts/foo.js', 1);var foo = 'bar';
|
135
|
+
_coverage_tick('public/javascripts/foo.js', 2);switch (foo) {
|
136
|
+
case 'bar': _coverage_tick('public/javascripts/foo.js', 3);wibble = 1;
|
137
|
+
_coverage_tick('public/javascripts/foo.js', 4);break;
|
138
|
+
case 'baz': _coverage_tick('public/javascripts/foo.js', 5);wibble = 2;
|
139
|
+
_coverage_tick('public/javascripts/foo.js', 6);break;
|
140
|
+
default:
|
141
|
+
_coverage_tick('public/javascripts/foo.js', 8);wibble = 3;
|
142
|
+
}
|
143
|
+
"""
|
144
|
+
|
145
|
+
Scenario: it handles stupid formatting with grace
|
146
|
+
Given a file named "public/javascripts/foo.js" with:
|
147
|
+
"""
|
148
|
+
var foo = 1
|
149
|
+
, bar = 2
|
150
|
+
, baz = function () { var wibble = 3; };
|
151
|
+
"""
|
152
|
+
When I run `jcov --dump`
|
153
|
+
Then the output should contain:
|
154
|
+
"""
|
155
|
+
_coverage_tick('public/javascripts/foo.js', 1);var foo = 1
|
156
|
+
, bar = 2
|
157
|
+
, baz = function () { _coverage_tick('public/javascripts/foo.js', 3);var wibble = 3; };
|
158
|
+
"""
|
159
|
+
|
160
|
+
Scenario: it still handles multiline functions within stupid formatting
|
161
|
+
Given a file named "public/javascripts/foo.js" with:
|
162
|
+
"""
|
163
|
+
var foo = 1
|
164
|
+
, bar = 2
|
165
|
+
, baz = function () {
|
166
|
+
var wibble = 3;
|
167
|
+
};
|
168
|
+
"""
|
169
|
+
When I run `jcov --dump`
|
170
|
+
Then the output should contain:
|
171
|
+
"""
|
172
|
+
_coverage_tick('public/javascripts/foo.js', 1);var foo = 1
|
173
|
+
, bar = 2
|
174
|
+
, baz = function () {
|
175
|
+
_coverage_tick('public/javascripts/foo.js', 4);var wibble = 3;
|
176
|
+
};
|
177
|
+
"""
|
178
|
+
|
179
|
+
Scenario: it handles if..else statements without parens gracefully
|
180
|
+
Given a file named "public/javascripts/foo.js" with:
|
181
|
+
"""
|
182
|
+
if (foo)
|
183
|
+
bar = 1;
|
184
|
+
else
|
185
|
+
baz = 3;
|
186
|
+
"""
|
187
|
+
When I run `jcov --dump`
|
188
|
+
Then the output should contain:
|
189
|
+
"""
|
190
|
+
_coverage_tick('public/javascripts/foo.js', 1);if (foo)
|
191
|
+
bar = 1;
|
192
|
+
else
|
193
|
+
baz = 3;
|
194
|
+
"""
|
195
|
+
|
196
|
+
Scenario: covers inline object definitions
|
197
|
+
Given a file named "public/javascripts/foo.js" with:
|
198
|
+
"""
|
199
|
+
var foo = {bar:'baz'};
|
200
|
+
"""
|
201
|
+
When I run `jcov --dump`
|
202
|
+
Then the output should contain:
|
203
|
+
"""
|
204
|
+
_coverage_tick('public/javascripts/foo.js', 1);var foo = {bar:'baz'};
|
205
|
+
"""
|
206
|
+
|
207
|
+
Scenario: covers single line if statements
|
208
|
+
Given a file named "public/javascripts/foo.js" with:
|
209
|
+
"""
|
210
|
+
if (foo) bar();
|
211
|
+
"""
|
212
|
+
When I run `jcov --dump`
|
213
|
+
Then the output should contain:
|
214
|
+
"""
|
215
|
+
_coverage_tick('public/javascripts/foo.js', 1);if (foo) bar();
|
216
|
+
"""
|
217
|
+
|
218
|
+
Scenario: handles catch statements
|
219
|
+
Given a file named "public/javascripts/foo.js" with:
|
220
|
+
"""
|
221
|
+
try {
|
222
|
+
foo();
|
223
|
+
}
|
224
|
+
catch(e) {
|
225
|
+
bar();
|
226
|
+
}
|
227
|
+
"""
|
228
|
+
When I run `jcov --dump`
|
229
|
+
Then the output should contain:
|
230
|
+
"""
|
231
|
+
_coverage_tick('public/javascripts/foo.js', 1);try {
|
232
|
+
_coverage_tick('public/javascripts/foo.js', 2);foo();
|
233
|
+
}
|
234
|
+
catch(e) {
|
235
|
+
_coverage_tick('public/javascripts/foo.js', 5);bar();
|
236
|
+
}
|
237
|
+
"""
|
238
|
+
|
239
|
+
Scenario: ignores empty catch statements
|
240
|
+
Given a file named "public/javascripts/foo.js" with:
|
241
|
+
"""
|
242
|
+
try {
|
243
|
+
foo();
|
244
|
+
}
|
245
|
+
catch(e) {}
|
246
|
+
"""
|
247
|
+
When I run `jcov --dump`
|
248
|
+
Then the output should contain:
|
249
|
+
"""
|
250
|
+
_coverage_tick('public/javascripts/foo.js', 1);try {
|
251
|
+
_coverage_tick('public/javascripts/foo.js', 2);foo();
|
252
|
+
}
|
253
|
+
catch(e) {}
|
254
|
+
"""
|
255
|
+
|
256
|
+
Scenario: ignores extra semicolons
|
257
|
+
Given a file named "public/javascripts/foo.js" with:
|
258
|
+
"""
|
259
|
+
try {
|
260
|
+
foo();
|
261
|
+
}
|
262
|
+
catch(e) {};
|
263
|
+
"""
|
264
|
+
When I run `jcov --dump`
|
265
|
+
Then the output should contain:
|
266
|
+
"""
|
267
|
+
_coverage_tick('public/javascripts/foo.js', 1);try {
|
268
|
+
_coverage_tick('public/javascripts/foo.js', 2);foo();
|
269
|
+
}
|
270
|
+
catch(e) {};
|
271
|
+
"""
|
272
|
+
|
273
|
+
Scenario: handles mixed inline and non-inline variable declarations
|
274
|
+
Given a file named "public/javascripts/foo.js" with:
|
275
|
+
"""
|
276
|
+
var foo, bar,
|
277
|
+
wibble = 'foo';
|
278
|
+
"""
|
279
|
+
When I run `jcov --dump`
|
280
|
+
Then the output should contain:
|
281
|
+
"""
|
282
|
+
_coverage_tick('public/javascripts/foo.js', 1);var foo, bar,
|
283
|
+
wibble = 'foo';
|
284
|
+
"""
|
285
|
+
|
286
|
+
Scenario: handles inline functions appropriately
|
287
|
+
Given a file named "public/javascripts/foo.js" with:
|
288
|
+
"""
|
289
|
+
var foo = function () { var bar = 0; };
|
290
|
+
"""
|
291
|
+
When I run `jcov --dump`
|
292
|
+
Then the output should contain:
|
293
|
+
"""
|
294
|
+
_coverage_tick('public/javascripts/foo.js', 1);var foo = function () { var bar = 0; };
|
295
|
+
"""
|
296
|
+
|
297
|
+
Scenario: it handles for..in statements appropriately
|
298
|
+
Given a file named "public/javascripts/foo.js" with:
|
299
|
+
"""
|
300
|
+
for (var i in foo) {
|
301
|
+
bar();
|
302
|
+
}
|
303
|
+
"""
|
304
|
+
When I run `jcov --dump`
|
305
|
+
Then the output should contain:
|
306
|
+
"""
|
307
|
+
_coverage_tick('public/javascripts/foo.js', 1);for (var i in foo) {
|
308
|
+
_coverage_tick('public/javascripts/foo.js', 2);bar();
|
309
|
+
}
|
310
|
+
"""
|
@@ -70,3 +70,39 @@ Feature: javascript interface
|
|
70
70
|
"""
|
71
71
|
here I am
|
72
72
|
"""
|
73
|
+
|
74
|
+
Scenario: I want to find where I made an error in my runner file
|
75
|
+
Given a file named "test/javascripts/runner.js" with:
|
76
|
+
"""
|
77
|
+
// this is a comment
|
78
|
+
// this is another comment
|
79
|
+
var foo = 1;
|
80
|
+
var bar = 2;
|
81
|
+
var baz = 3;
|
82
|
+
fail();
|
83
|
+
"""
|
84
|
+
When I run `jcov --trace`
|
85
|
+
Then the output should match:
|
86
|
+
"""
|
87
|
+
test/javascripts/runner.js:6:\d+: fail is not defined
|
88
|
+
"""
|
89
|
+
|
90
|
+
Scenario: I want to find where I made an error in tested Javascript
|
91
|
+
Given a file named "test/javascripts/runner.js" with:
|
92
|
+
"""
|
93
|
+
load("public/javascripts/foo.js");
|
94
|
+
"""
|
95
|
+
And a file named "public/javascripts/foo.js" with:
|
96
|
+
"""
|
97
|
+
// this is a comment
|
98
|
+
// this is another comment
|
99
|
+
var foo = 1;
|
100
|
+
var bar = 2;
|
101
|
+
var baz = 3;
|
102
|
+
fail();
|
103
|
+
"""
|
104
|
+
When I run `jcov --trace`
|
105
|
+
Then the output should match:
|
106
|
+
"""
|
107
|
+
public/javascripts/foo.js:6:\d+: fail is not defined
|
108
|
+
"""
|
data/features/run.feature
CHANGED
@@ -172,7 +172,7 @@ Feature: test runner
|
|
172
172
|
Given a file named "test/javascripts/runner.js" with:
|
173
173
|
"""
|
174
174
|
error_count = 0;
|
175
|
-
println(JCov.
|
175
|
+
println(JCov.config.verbose);
|
176
176
|
"""
|
177
177
|
When I run `jcov --verbose`
|
178
178
|
Then the output should contain:
|
@@ -184,7 +184,7 @@ Feature: test runner
|
|
184
184
|
Given a file named "test/javascripts/runner.js" with:
|
185
185
|
"""
|
186
186
|
error_count = 0;
|
187
|
-
println(JCov.
|
187
|
+
println(JCov.config.color);
|
188
188
|
"""
|
189
189
|
When I run `jcov --no-color`
|
190
190
|
Then the output should contain:
|
@@ -196,7 +196,7 @@ Feature: test runner
|
|
196
196
|
Given a file named "test/javascripts/runner.js" with:
|
197
197
|
"""
|
198
198
|
error_count = 0;
|
199
|
-
println(JCov.
|
199
|
+
println(JCov.config.color);
|
200
200
|
"""
|
201
201
|
When I run `jcov --color`
|
202
202
|
Then the output should contain:
|
@@ -208,10 +208,22 @@ Feature: test runner
|
|
208
208
|
Given a file named "test/javascripts/runner.js" with:
|
209
209
|
"""
|
210
210
|
error_count = 0;
|
211
|
-
println(JCov.
|
211
|
+
println(JCov.config.color);
|
212
212
|
"""
|
213
213
|
When I run `jcov`
|
214
214
|
Then the output should contain:
|
215
215
|
"""
|
216
216
|
false
|
217
217
|
"""
|
218
|
+
|
219
|
+
Scenario: user can also use the old options object
|
220
|
+
Given a file named "test/javascripts/runner.js" with:
|
221
|
+
"""
|
222
|
+
error_count = 0;
|
223
|
+
println(JCov.options.verbose);
|
224
|
+
"""
|
225
|
+
When I run `jcov --verbose`
|
226
|
+
Then the output should contain:
|
227
|
+
"""
|
228
|
+
true
|
229
|
+
"""
|