Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit bd49cd7

Browse files
committed
Add basic non - regression test for the most frequent usecase
Changes highlights: package.json - Add devDependencies: mocha (test runner) and istanbul (to measure code coverage) - Add npm "test" lifecycle script: now "npm test" runs the mocha tests, wrapped with istanbul to measure coverage. Test coverage is not amazing so far, but that's a start :=) Statements : 46.21% ( 61/132 ) Branches : 49.3% ( 35/71 ) Functions : 53.57% ( 15/28 ) Lines : 49.18% ( 60/122 ) test/phantom-html2pdf.test.js: The test file for phantom-html2pdf.js (todo: add tests for other files) .gitignore: add the coverage files and the data directory of my favorite IDE
1 parent c9685ea commit bd49cd7

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
2-
node_modules
1+
node_modules/
2+
.idea/
3+
coverage/

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
"bin": {
3232
"phantom-html2pdf": "./bin/phantom-html2pdf"
3333
},
34-
"devDependencies": {},
34+
"devDependencies": {
35+
"istanbul": "^0.4.2",
36+
"mocha": "^2.4.5"
37+
},
3538
"optionalDependencies": {},
3639
"engines": {
3740
"node": "*"
@@ -49,5 +52,8 @@
4952
{
5053
"name": "dustin-H"
5154
}
52-
]
55+
],
56+
"scripts": {
57+
"test": "istanbul cover _mocha --include-all-sources -x \"**/test/**\" -- --recursive"
58+
}
5359
}

test/phantom-html2pdf.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
var assert = require('assert');
4+
5+
var pdf = require('../lib/phantom-html2pdf');
6+
7+
describe('phantom-html2pdf.js', function() {
8+
describe('Simple end to end test', function() {
9+
10+
it('Should generate a PDF file without crashing', function(done) {
11+
var pdfOptions = {
12+
'html': '<!DOCTYPE html><html lang="en"><body><h1>Hello</h1><p>World</p></body></html>',
13+
'papersize': {format: 'A4', orientation: 'portrait', border: '1cm'}
14+
};
15+
16+
pdf.convert(pdfOptions, function (result) {
17+
result.toBuffer(function (buffer) {
18+
assert(buffer, 'A buffer is returned');
19+
assert(buffer.length > 0, 'The generated buffer is not empty');
20+
done();
21+
});
22+
});
23+
});
24+
})
25+
});

0 commit comments

Comments
 (0)