Skip to content

Commit 89cc04f

Browse files
Upgrade puppeteer version. Fixes #115
1 parent 34cb1a1 commit 89cc04f

File tree

4 files changed

+101
-40
lines changed

4 files changed

+101
-40
lines changed

package-lock.json

Lines changed: 56 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"lodash": "^4.17.15",
3333
"morgan": "^1.9.1",
3434
"pdf-parse": "^1.1.1",
35-
"puppeteer": "^1.14.0",
35+
"puppeteer": "^2.0.0",
3636
"server-destroy": "^1.0.1",
3737
"winston": "^2.3.1"
3838
},

test/resources/special-chars.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4+
</head>
5+
<body>
6+
<p>
7+
special characters: ä ö ü
8+
</p>
9+
</body>
10+
</html>

test/test-all.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ function normalisePdfText(text) {
2323
return text.replace(/[\W_]+/g, '-');
2424
}
2525

26-
function getPdfTextContent(buffer) {
26+
function getPdfTextContent(buffer, opts = {}) {
2727
return pdf(buffer)
28-
.then(data => normalisePdfText(data.text));
28+
.then((data) => {
29+
if (opts.raw) {
30+
return data.text;
31+
}
32+
33+
return normalisePdfText(data.text);
34+
});
2935
}
3036

3137
describe('GET /api/render', () => {
@@ -177,4 +183,30 @@ describe('POST /api/render', () => {
177183
chai.expect(text).to.have.string('Cookie-named-url-to-pdf-test-2');
178184
})
179185
);
186+
187+
it('special characters should be rendered correctly', () =>
188+
request(app)
189+
.post('/api/render')
190+
.send({ html: getResource('special-chars.html') })
191+
.set('Connection', 'keep-alive')
192+
.set('content-type', 'application/json')
193+
.expect(200)
194+
.expect('content-type', 'application/pdf')
195+
.then((response) => {
196+
if (DEBUG) {
197+
console.log(response.headers);
198+
console.log(response.body);
199+
fs.writeFileSync('special-chars.pdf', response.body, { encoding: null });
200+
}
201+
202+
return getPdfTextContent(response.body, { raw: true });
203+
})
204+
.then((text) => {
205+
if (DEBUG) {
206+
fs.writeFileSync('./special-chars-content.txt', text);
207+
}
208+
209+
chai.expect(text).to.have.string('special characters: ä ö ü');
210+
})
211+
);
180212
});

0 commit comments

Comments
 (0)