jasmine-coverage 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +19 -10
- data/lib/jasmine/coverage/version.rb +1 -1
- data/lib/tasks/coverage_output_generator.js +5 -1
- data/lib/tasks/jasmine_coverage.rake +23 -15
- metadata +19 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 742de221f16674814b07fcb8f50c49b82f178bbb
|
4
|
+
data.tar.gz: 3231a36eba66db48040d1c3efd158ebdf5482d2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ea74c9d27feb0b65ff1b198c7502f724da6eafde51c3056115b579ad2b25638362583a6b2c3b5ddb828d2d5dedd31801a64982456e1558413c7f83913929c87
|
7
|
+
data.tar.gz: 175e4726a4e0617ec6758df209323af1eb72737f5bc08488903f08e1ad6c3de6b6a1eb692eea9756d16ba623e639007b4fda4040ec16cc99ff5f5edc03b58e80
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
## Jasmine Coverage
|
2
2
|
|
3
3
|
A transcendent blend of useful JS unit testing and colourful coverage graphs.
|
4
4
|
|
@@ -8,7 +8,7 @@ failing it if it falls below a configurable level.
|
|
8
8
|
|
9
9
|
Coverage is provided by the [jscoverage](http://siliconforks.com/jscoverage/manual.html) project.
|
10
10
|
|
11
|
-
|
11
|
+
## Installation
|
12
12
|
|
13
13
|
First, ensure you have a binary of [jscoverage](http://siliconforks.com/jscoverage/manual.html)
|
14
14
|
available on your path. The installation steps are on the webpage.
|
@@ -24,13 +24,13 @@ Finally, add this to your Rakefile
|
|
24
24
|
|
25
25
|
require 'jasmine/coverage'
|
26
26
|
|
27
|
-
|
27
|
+
## Usage
|
28
28
|
|
29
29
|
To use jasmine-coverage, run the rake task.
|
30
30
|
|
31
31
|
bundle exec rake jasmine:coverage
|
32
32
|
|
33
|
-
|
33
|
+
## Output
|
34
34
|
|
35
35
|
You will see the tests execute, then a large blob of text, and finally a summary of the test coverage results.
|
36
36
|
An HTML file will also be saved that lets you view the results graphically, but only if served up from a server,
|
@@ -47,23 +47,23 @@ Files generated will be
|
|
47
47
|
target/jscoverage/jscoverage.json - The report data
|
48
48
|
target/jscoverage/jscoverage-test-rig.html - The actual page that the tests executed in
|
49
49
|
|
50
|
-
|
50
|
+
## Configuration
|
51
51
|
|
52
52
|
You can set a failure level percentage.
|
53
53
|
|
54
54
|
bundle exec rake jasmine:coverage JASMINE_COVERAGE_MINIMUM=75
|
55
55
|
|
56
56
|
In addition, as jasmine-coverage has to create a single folder environment for the Javascript sandbox to function correctly, it has to copy
|
57
|
-
files into the _target/jscoverage/test-rig_ folder. By default, this is
|
58
|
-
|
57
|
+
files into the _target/jscoverage/test-rig_ folder. By default, this is left for you if the tests pass. If you'd like it cleaned up,
|
58
|
+
you can specify that in an environment variable.
|
59
59
|
|
60
|
-
bundle exec rake jasmine:coverage JASMINE_COVERAGE_KEEP_TEST_RIG=
|
60
|
+
bundle exec rake jasmine:coverage JASMINE_COVERAGE_KEEP_TEST_RIG=false
|
61
61
|
|
62
62
|
You can also specify if you want missing coverage warnings
|
63
63
|
|
64
64
|
bundle exec rake jasmine:coverage JASMINE_COVERAGE_WARNINGS=true
|
65
65
|
|
66
|
-
|
66
|
+
## How it works
|
67
67
|
|
68
68
|
First Sprockets is interrogated to get a list of JS files concerned. This way, the right JS files
|
69
69
|
are required *in the same order that your app uses them*. JSCoverage then runs over them, and outputs the
|
@@ -74,4 +74,13 @@ The data we get from the coverage can only "leave" the JS sandbox one way: via t
|
|
74
74
|
a large block of Base64 encoded rubbish flying past as the build progresses. The console data is captured by Jasmine
|
75
75
|
Coverage, which decodes it and builds the results HTML page, and gives a short summary in the console.
|
76
76
|
|
77
|
-
You're done.
|
77
|
+
You're done.
|
78
|
+
|
79
|
+
## Mac Support
|
80
|
+
|
81
|
+
The tool uses the headless gem, which needs to create an X virtual frame buffer. Linux machines should work out the box,
|
82
|
+
but since Mac uses Quartz, you may get
|
83
|
+
|
84
|
+
Xvfb not found on your system
|
85
|
+
|
86
|
+
To solve that just install XQuartz and add /usr/X11/bin to your PATH (thanks @shell).
|
@@ -66,7 +66,11 @@ function coverageForAllFiles() {
|
|
66
66
|
}
|
67
67
|
|
68
68
|
var fraction = (simple_file_coverage['executed'] + "/" + simple_file_coverage['statements']).lpad(' ', 10);
|
69
|
-
|
69
|
+
var perc = simple_file_coverage['percentage'];
|
70
|
+
if (parseInt(simple_file_coverage['statements']) === 0){
|
71
|
+
perc = 100;
|
72
|
+
}
|
73
|
+
output += fraction + (" = " + perc + "").lpad(' ', 3) + "% for " + file_name + "\n";
|
70
74
|
}
|
71
75
|
|
72
76
|
var coverage = parseInt(100 * totals['executed'] / totals['statements']);
|
@@ -43,23 +43,35 @@ if env =~ /^(development|test)$/
|
|
43
43
|
Jasmine::Coverage.output_dir = output_dir
|
44
44
|
test_rig_folder = "#{Jasmine::Coverage.output_dir}/test-rig"
|
45
45
|
|
46
|
-
|
46
|
+
rr_file = "#{output_dir}/rawreport.txt"
|
47
|
+
puts "\nCoverage will now be run. Expect a large block of compiled coverage data. This will be processed for you into target/jscoverage (#{rr_file}).\n\n"
|
48
|
+
|
49
|
+
# Check we can write to the output file
|
50
|
+
begin
|
51
|
+
File.open(rr_file, 'w') { |f| f.write('test-write') }
|
52
|
+
File.delete(rr_file)
|
53
|
+
rescue
|
54
|
+
raise "There was an error writing to the report file #{rr_file}.\nDo you have permissions to do so?"
|
55
|
+
end
|
47
56
|
|
48
57
|
# Run Jasmine using the original config.
|
49
58
|
status_code = Jasmine::Headless::Runner.run(
|
50
59
|
# Any options from the options.rb file in jasmine-headless-webkit can be used here.
|
51
60
|
|
52
|
-
:reporters => [['File',
|
61
|
+
:reporters => [['Console'], ['File', rr_file]]
|
53
62
|
)
|
54
63
|
errStr = <<-EOS
|
64
|
+
**********************************************************************************************
|
65
|
+
|
55
66
|
JSCoverage exited with error code: #{status_code}
|
56
67
|
|
57
|
-
This implies one of
|
68
|
+
This implies one of six things:
|
58
69
|
0) Your JS files had exactly zero instructions. Are they all blank or just comments?
|
59
|
-
1)
|
60
|
-
2)
|
61
|
-
3)
|
62
|
-
4)
|
70
|
+
1) The Jasmine Headless gem failed. Run bundle exec rake jasmine:headless to see what it might be.
|
71
|
+
2) A test failed - you should be able to see the errors just above this text block (or run bundle exec rake jasmine:headless to see a simple error without coverage).
|
72
|
+
3) The sourcecode has a syntax error (which JSLint should find)
|
73
|
+
4) An error occurred in a deferred block, e.g. a setTimeout or underscore _.defer. This caused a window error which Jasmine will never see.
|
74
|
+
5) The source files are being loaded out of sequence (so global variables are not being declared in order)
|
63
75
|
To check this, run bundle exec jasmine-headless-webkit -l to see the ordering
|
64
76
|
|
65
77
|
In any case, try running the standard jasmine command to get better errors:
|
@@ -68,10 +80,6 @@ bundle exec rake jasmine:headless
|
|
68
80
|
|
69
81
|
Finally, try opening the test-rig in firefox to see the tests run in a browser and get a stacktrace. Chrome has strict security settings
|
70
82
|
that make this difficult since it accesses the local filesystem from Javascript (but you can switch the settings off at the command line).
|
71
|
-
|
72
|
-
|
73
|
-
**********************************************************************************************
|
74
|
-
|
75
83
|
The test rig file needs to load JS directly off disk, which Chrome prevents by default. Your best bet is to open the rig in Firefox.
|
76
84
|
|
77
85
|
The file can be found here: #{test_rig_folder}/jscoverage-test-rig.html
|
@@ -82,14 +90,14 @@ The file can be found here: #{test_rig_folder}/jscoverage-test-rig.html
|
|
82
90
|
|
83
91
|
fail errStr if status_code == 1
|
84
92
|
# Delete the test_rig folder if not required
|
85
|
-
if ENV['JASMINE_COVERAGE_KEEP_TEST_RIG']
|
86
|
-
p "A copy of the page and files that were used as the jasmine test environment can be found here: #{test_rig_folder}"
|
87
|
-
else
|
93
|
+
if ENV['JASMINE_COVERAGE_KEEP_TEST_RIG'] == 'false'
|
88
94
|
FileUtils.rm_rf test_rig_folder
|
95
|
+
else
|
96
|
+
p "A copy of the page and files that were used as the jasmine test environment can be found here: #{test_rig_folder}"
|
89
97
|
end
|
90
98
|
|
91
99
|
# Obtain the console log, which includes the coverage report encoded within it
|
92
|
-
contents = File.open(
|
100
|
+
contents = File.open(rr_file) { |f| f.read }
|
93
101
|
# Get our Base64.
|
94
102
|
json_report_enc = contents.split(/ENCODED-COVERAGE-EXPORT-STARTS:/m)[1]
|
95
103
|
# Provide warnings to use
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jasmine-coverage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Harry Lascelles
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
type: :runtime
|
16
14
|
name: jasmine-headless-webkit
|
17
|
-
prerelease: false
|
18
15
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
16
|
requirements:
|
21
|
-
- -
|
17
|
+
- - '>='
|
22
18
|
- !ruby/object:Gem::Version
|
23
19
|
version: 0.9.0.rc.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.9.0.rc.2
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
type: :runtime
|
32
28
|
name: coffee-script-source
|
33
|
-
prerelease: false
|
34
29
|
requirement: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
30
|
requirements:
|
37
|
-
- -
|
31
|
+
- - '>='
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
type: :runtime
|
48
42
|
name: headless
|
49
|
-
prerelease: false
|
50
43
|
requirement: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
44
|
requirements:
|
53
|
-
- -
|
45
|
+
- - '>='
|
54
46
|
- !ruby/object:Gem::Version
|
55
47
|
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description:
|
@@ -78,27 +71,26 @@ files:
|
|
78
71
|
- Rakefile
|
79
72
|
homepage: https://github.com/firstbanco/jasmine-coverage
|
80
73
|
licenses: []
|
74
|
+
metadata: {}
|
81
75
|
post_install_message:
|
82
76
|
rdoc_options: []
|
83
77
|
require_paths:
|
84
78
|
- lib
|
85
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
80
|
requirements:
|
88
|
-
- -
|
81
|
+
- - '>='
|
89
82
|
- !ruby/object:Gem::Version
|
90
83
|
version: '0'
|
91
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
85
|
requirements:
|
94
|
-
- -
|
86
|
+
- - '>='
|
95
87
|
- !ruby/object:Gem::Version
|
96
88
|
version: '0'
|
97
89
|
requirements: []
|
98
90
|
rubyforge_project:
|
99
|
-
rubygems_version:
|
91
|
+
rubygems_version: 2.0.3
|
100
92
|
signing_key:
|
101
|
-
specification_version:
|
93
|
+
specification_version: 4
|
102
94
|
summary: A blend of JS unit testing and coverage
|
103
95
|
test_files: []
|
104
96
|
has_rdoc:
|