Skip to content

Commit 56d4327

Browse files
authored
Merge pull request #886 from blikblum/improve-tests
Improve tests structure Load src files directly allowing to test without build step and test isolated classes Separate tests into two categories: unit and integration Allow to use ES modules in tests Ensure test output is the same across different runs / systems
2 parents c09cd64 + a1156fb commit 56d4327

40 files changed

Lines changed: 68 additions & 36 deletions

.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [["env", {"modules": false, "targets": {"node": "6.10"}}]],
3+
"env": {
4+
"test": {
5+
"presets": [["env", {"targets": {"node": "6.10"}}]]
6+
}
7+
}
8+
}

lib/font/standard.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import fs from 'fs';
44

55
// This insanity is so bundlers can inline the font files
66
const STANDARD_FONTS = {
7-
"Courier"() { return fs.readFileSync(__dirname + "/font/data/Courier.afm", 'utf8'); },
8-
"Courier-Bold"() { return fs.readFileSync(__dirname + "/font/data/Courier-Bold.afm", 'utf8'); },
9-
"Courier-Oblique"() { return fs.readFileSync(__dirname + "/font/data/Courier-Oblique.afm", 'utf8'); },
10-
"Courier-BoldOblique"() { return fs.readFileSync(__dirname + "/font/data/Courier-BoldOblique.afm", 'utf8'); },
11-
"Helvetica"() { return fs.readFileSync(__dirname + "/font/data/Helvetica.afm", 'utf8'); },
12-
"Helvetica-Bold"() { return fs.readFileSync(__dirname + "/font/data/Helvetica-Bold.afm", 'utf8'); },
13-
"Helvetica-Oblique"() { return fs.readFileSync(__dirname + "/font/data/Helvetica-Oblique.afm", 'utf8'); },
14-
"Helvetica-BoldOblique"() { return fs.readFileSync(__dirname + "/font/data/Helvetica-BoldOblique.afm", 'utf8'); },
15-
"Times-Roman"() { return fs.readFileSync(__dirname + "/font/data/Times-Roman.afm", 'utf8'); },
16-
"Times-Bold"() { return fs.readFileSync(__dirname + "/font/data/Times-Bold.afm", 'utf8'); },
17-
"Times-Italic"() { return fs.readFileSync(__dirname + "/font/data/Times-Italic.afm", 'utf8'); },
18-
"Times-BoldItalic"() { return fs.readFileSync(__dirname + "/font/data/Times-BoldItalic.afm", 'utf8'); },
19-
"Symbol"() { return fs.readFileSync(__dirname + "/font/data/Symbol.afm", 'utf8'); },
20-
"ZapfDingbats"() { return fs.readFileSync(__dirname + "/font/data/ZapfDingbats.afm", 'utf8'); }
7+
"Courier"() { return fs.readFileSync(__dirname + "/data/Courier.afm", 'utf8'); },
8+
"Courier-Bold"() { return fs.readFileSync(__dirname + "/data/Courier-Bold.afm", 'utf8'); },
9+
"Courier-Oblique"() { return fs.readFileSync(__dirname + "/data/Courier-Oblique.afm", 'utf8'); },
10+
"Courier-BoldOblique"() { return fs.readFileSync(__dirname + "/data/Courier-BoldOblique.afm", 'utf8'); },
11+
"Helvetica"() { return fs.readFileSync(__dirname + "/data/Helvetica.afm", 'utf8'); },
12+
"Helvetica-Bold"() { return fs.readFileSync(__dirname + "/data/Helvetica-Bold.afm", 'utf8'); },
13+
"Helvetica-Oblique"() { return fs.readFileSync(__dirname + "/data/Helvetica-Oblique.afm", 'utf8'); },
14+
"Helvetica-BoldOblique"() { return fs.readFileSync(__dirname + "/data/Helvetica-BoldOblique.afm", 'utf8'); },
15+
"Times-Roman"() { return fs.readFileSync(__dirname + "/data/Times-Roman.afm", 'utf8'); },
16+
"Times-Bold"() { return fs.readFileSync(__dirname + "/data/Times-Bold.afm", 'utf8'); },
17+
"Times-Italic"() { return fs.readFileSync(__dirname + "/data/Times-Italic.afm", 'utf8'); },
18+
"Times-BoldItalic"() { return fs.readFileSync(__dirname + "/data/Times-BoldItalic.afm", 'utf8'); },
19+
"Symbol"() { return fs.readFileSync(__dirname + "/data/Symbol.afm", 'utf8'); },
20+
"ZapfDingbats"() { return fs.readFileSync(__dirname + "/data/ZapfDingbats.afm", 'utf8'); }
2121
};
2222

2323
class StandardFont extends PDFFont {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"bugs": "http://github.com/devongovett/pdfkit/issues",
2424
"devDependencies": {
2525
"babel-core": "^6.26.3",
26+
"babel-jest": "^23.6.0",
2627
"babel-plugin-external-helpers": "^6.22.0",
2728
"babel-preset-env": "^1.7.0",
2829
"blob-stream": "^0.1.2",
@@ -54,6 +55,7 @@
5455
"website": "node docs/generate_website.js",
5556
"docs": "npm run pdf-guide && npm run website && npm run browser-demo",
5657
"test": "jest -i",
58+
"test:integration": "jest integration/ -i",
5759
"test:unit": "jest unit/ -i"
5860
},
5961
"main": "js/pdfkit.js",

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default [
4141
}),
4242
copy({
4343
files: ['lib/font/data/*.afm'],
44-
dest: 'js/font/data'
44+
dest: 'js/data'
4545
}),
4646
stripFSInterop()
4747
]
107 KB
Binary file not shown.
10.2 KB
Binary file not shown.
6.15 KB
Binary file not shown.
62.2 KB
Binary file not shown.
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
var PDFDocument = require('../');
1+
var PDFDocument = require('../../lib/document').default;
2+
var PDFSecurity = require('../../lib/security').default;
3+
var CryptoJS = require('crypto-js');
24
var path = require('path');
35
var fs = require('fs');
46

7+
// manual mock for PDFSecurity to ensure stored id will be the same accross different systems
8+
PDFSecurity.generateFileID = () => {
9+
return new Buffer('mocked-pdf-id');
10+
}
11+
12+
PDFSecurity.generateRandomWordArray = (bytes) => {
13+
const words = [];
14+
for (let i = 0; i < bytes; i++) {
15+
words.push(0x00010203);
16+
}
17+
return new CryptoJS.lib.WordArray.init(words, bytes);
18+
}
19+
520
function updatePdf (pdfData, testState, snapshotChanges) {
621
const pdfDir = path.join(path.dirname(testState.testPath), '__pdfs__');
722
if (!fs.existsSync(pdfDir)) {

0 commit comments

Comments
 (0)