Skip to content

Commit 47ebab6

Browse files
authored
Add code coverage (parallax#880)
* Add code coverage, convert tests to es6 then babel-ify for IE and old browsers * Fix indentation on the annotations file
1 parent 44a6403 commit 47ebab6

9 files changed

Lines changed: 96 additions & 51 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
.DS_Store
33
node_modules/
4+
coverage/

karma.conf.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ module.exports = (config) => {
3131

3232
// preprocess matching files before serving them to the browser
3333
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
34-
preprocessors: {},
34+
preprocessors: {
35+
'jspdf.js': 'coverage',
36+
'plugins/*.js': 'coverage',
37+
'specs/!(acroform)*/*.js': 'babel'
38+
},
3539

3640
// test results reporter to use
3741
// possible values: 'dots', 'progress'
3842
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
39-
reporters: ['progress'],
43+
reporters: ['progress', 'coverage'],
4044

4145
// web server port
4246
port: 9876,
@@ -61,6 +65,25 @@ module.exports = (config) => {
6165

6266
// Concurrency level
6367
// how many browser should be started simultaneous
64-
concurrency: Infinity
68+
concurrency: Infinity,
69+
70+
coverageReporter: {
71+
reporters: [
72+
{
73+
type: 'html',
74+
dir: 'coverage/'
75+
},
76+
{
77+
type: 'text'
78+
}
79+
]
80+
},
81+
babelPreprocessor: {
82+
options: {
83+
presets: ['es2015'],
84+
sourceMap: 'inline'
85+
}
86+
}
87+
6588
})
6689
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@
2424
"requirejs": "2.3.2"
2525
},
2626
"devDependencies": {
27+
"babel-preset-es2015": "^6.16.0",
2728
"babel-preset-es2015-rollup": "1.1.1",
2829
"diff": "3.0.0",
2930
"docdash": "0.4.0",
3031
"jasmine": "2.5.2",
3132
"js-yaml": "3.6.1",
3233
"jsdoc": "3.4.1",
3334
"karma": "1.3.0",
35+
"karma-babel-preprocessor": "^6.0.1",
3436
"karma-chrome-launcher": "2.0.0",
37+
"karma-coverage": "^1.1.1",
3538
"karma-firefox-launcher": "1.0.0",
3639
"karma-jasmine": "1.0.2",
3740
"karma-requirejs": "1.1.0",

saucelabs.karma.conf.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ module.exports = (config) => {
7272

7373
// preprocess matching files before serving them to the browser
7474
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
75-
preprocessors: {},
76-
75+
preprocessors: {
76+
'jspdf.js': 'coverage',
77+
'plugins/*.js': 'coverage',
78+
'specs/!(acroform)*/*.js': 'babel'
79+
},
7780
// test results reporter to use
7881
// possible values: 'dots', 'progress'
7982
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
@@ -98,10 +101,28 @@ module.exports = (config) => {
98101

99102
// Concurrency level
100103
// how many browser should be started simultaneous
101-
concurrency: Infinity,
104+
concurrency: 1,
102105

103-
reporters: ['saucelabs', 'progress'], // 2
106+
reporters: ['saucelabs', 'progress', 'coverage'], // 2
104107
browsers: Object.keys(browsers), // 3
105-
customLaunchers: browsers // 4
108+
customLaunchers: browsers, // 4
109+
110+
coverageReporter: {
111+
reporters: [
112+
{
113+
type: 'html',
114+
dir: 'coverage/'
115+
},
116+
{
117+
type: 'text'
118+
}
119+
]
120+
},
121+
babelPreprocessor: {
122+
options: {
123+
presets: ['es2015'],
124+
sourceMap: 'inline'
125+
}
126+
}
106127
})
107128
}

specs/acroform/standard.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* @TODO Enable 'use strict', remove all these globals */
2-
/* global describe, it, jsPDF, comparePdf, ComboBox, ListBox, PushButton, CheckBox, TextField, PasswordField, RadioButton, AcroForm */
2+
/* global describe, xit, it, jsPDF, comparePdf, ComboBox, ListBox, PushButton, CheckBox, TextField, PasswordField, RadioButton, AcroForm */
33
/**
44
* Acroform testing
55
*/

specs/annotations/standard.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* We compare the exact output.
88
*/
99

10-
describe('Drawing functions', function () {
11-
it('should draw a closed annotation', function () {
12-
var doc = jsPDF()
10+
describe('Drawing functions', () => {
11+
it('should draw a closed annotation', () => {
12+
const doc = jsPDF()
1313
doc.createAnnotation({
1414
type: 'text',
1515
title: 'note',
@@ -24,8 +24,8 @@ describe('Drawing functions', function () {
2424
})
2525
comparePdf(doc.output(), 'closed.pdf', 'annotations')
2626
})
27-
it('should draw an open annotation', function () {
28-
var doc = jsPDF()
27+
it('should draw an open annotation', () => {
28+
const doc = jsPDF()
2929
doc.createAnnotation({
3030
type: 'text',
3131
title: 'note',
@@ -40,8 +40,8 @@ describe('Drawing functions', function () {
4040
})
4141
comparePdf(doc.output(), 'open.pdf', 'annotations')
4242
})
43-
it('should draw a free text annotation', function () {
44-
var doc = jsPDF()
43+
it('should draw a free text annotation', () => {
44+
const doc = jsPDF()
4545
doc.createAnnotation({
4646
type: 'freetext',
4747
bounds: {

specs/shapes/standard.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* We compare the exact output.
88
*/
99

10-
describe('Drawing functions', function () {
11-
it('should draw circles', function () {
12-
var doc = jsPDF()
10+
describe('Drawing functions', () => {
11+
it('should draw circles', () => {
12+
const doc = jsPDF()
1313

1414
doc.ellipse(40, 20, 10, 5)
1515

@@ -23,8 +23,8 @@ describe('Drawing functions', function () {
2323
comparePdf(doc.output(), 'circles.pdf', 'shapes')
2424
})
2525

26-
it('should draw rectangles', function () {
27-
var doc = jsPDF()
26+
it('should draw rectangles', () => {
27+
const doc = jsPDF()
2828

2929
// Empty square
3030
doc.rect(20, 20, 10, 10)
@@ -58,16 +58,16 @@ describe('Drawing functions', function () {
5858
comparePdf(doc.output(), 'rectangles.pdf', 'shapes')
5959
})
6060

61-
it('should draw a line', function () {
62-
var doc = jsPDF()
61+
it('should draw a line', () => {
62+
const doc = jsPDF()
6363

6464
// horizontal line
6565
doc.line(20, 20, 60, 20)
6666
comparePdf(doc.output(), 'line.pdf', 'shapes')
6767
})
6868

69-
it('should draw lines', function () {
70-
var doc = jsPDF()
69+
it('should draw lines', () => {
70+
const doc = jsPDF()
7171

7272
// horizontal line
7373
doc.line(20, 20, 60, 20)

specs/text/standard.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
* We compare the exact output.
88
*/
99

10-
describe('Standard Text', function () {
11-
it('should load', function () {
10+
describe('Standard Text', () => {
11+
it('should load', () => {
1212
// assertions here]
1313
expect(typeof jsPDF).toBe('function')
1414
})
15-
it('should generate blank page', function () {
16-
var doc = jsPDF()
15+
it('should generate blank page', () => {
16+
const doc = jsPDF()
1717
comparePdf(doc.output(), 'blank.pdf', 'text')
1818
})
19-
it('should allow text insertion', function () {
20-
var doc = jsPDF()
19+
it('should allow text insertion', () => {
20+
const doc = jsPDF()
2121
doc.text(10, 10, 'This is a test!')
2222
comparePdf(doc.output(), 'standard.pdf', 'text')
2323
})
24-
it('should allow text insertion at an angle', function () {
25-
var doc = jsPDF()
24+
it('should allow text insertion at an angle', () => {
25+
const doc = jsPDF()
2626
doc.text(20, 20, 'This is a test!', null, 20)
2727
comparePdf(doc.output(), 'angle.pdf', 'text')
2828
})
29-
it('should render different font faces', function () {
30-
var doc = jsPDF()
29+
it('should render different font faces', () => {
30+
const doc = jsPDF()
3131

3232
doc.text(20, 20, 'This is the default font.')
3333

@@ -49,16 +49,16 @@ describe('Standard Text', function () {
4949

5050
comparePdf(doc.output(), 'font-faces.pdf', 'text')
5151
})
52-
it('should support multiple pages', function () {
53-
var doc = jsPDF()
52+
it('should support multiple pages', () => {
53+
const doc = jsPDF()
5454
doc.text(20, 20, 'Hello world!')
5555
doc.text(20, 30, 'This is client-side JavaScript, pumping out a PDF.')
5656
doc.addPage()
5757
doc.text(20, 20, 'Do you like that?')
5858
comparePdf(doc.output(), 'two-page.pdf', 'text')
5959
})
60-
it('should support different size fonts', function () {
61-
var doc = jsPDF()
60+
it('should support different size fonts', () => {
61+
const doc = jsPDF()
6262
doc.setFontSize(22)
6363
doc.text(20, 20, 'This is a title')
6464

specs/utils/compare.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
'use strict'
21
/* global XMLHttpRequest, expect */
32

43
function loadBinaryResource (url) {
5-
var req = new XMLHttpRequest()
4+
const req = new XMLHttpRequest()
65
req.open('GET', url, false)
76
// XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
87
req.overrideMimeType('text\/plain; charset=x-user-defined')
@@ -14,29 +13,27 @@ function loadBinaryResource (url) {
1413
}
1514

1615
function sendReference (filename, data) {
17-
var req = new XMLHttpRequest()
18-
req.open('POST', 'http://localhost:9090/' + filename, true)
19-
req.onload = function (e) {
16+
const req = new XMLHttpRequest()
17+
req.open('POST', `http://localhost:9090/${filename}`, true)
18+
req.onload = e => {
2019
console.log(e)
2120
}
2221
req.send(data)
2322
}
2423

25-
var resetCreationDate = function (input) {
26-
return input.replace(/\/CreationDate \(D:(.*?)\)/, '/CreationDate (D:19871210000000+00\'00\'\)')
27-
}
24+
const resetCreationDate = input => input.replace(/\/CreationDate \(D:(.*?)\)/, '/CreationDate (D:19871210000000+00\'00\'\)')
2825

2926
/**
3027
* Find a better way to set this
3128
* @type {Boolean}
3229
*/
33-
var training = false
30+
const training = false
3431

35-
window.comparePdf = function (actual, expectedFile, suite) {
32+
window.comparePdf = (actual, expectedFile, suite) => {
3633
if (training === true) {
37-
sendReference('/specs/' + suite + '/reference/' + expectedFile, resetCreationDate(actual))
34+
sendReference(`/specs/${suite}/reference/${expectedFile}`, resetCreationDate(actual))
3835
} else {
39-
var expected = resetCreationDate(loadBinaryResource('/base/specs/' + suite + '/reference/' + expectedFile).trim())
36+
const expected = resetCreationDate(loadBinaryResource(`/base/specs/${suite}/reference/${expectedFile}`).trim())
4037
actual = resetCreationDate(actual.trim())
4138

4239
expect(actual).toEqual(expected)

0 commit comments

Comments
 (0)