Skip to content

Commit

Permalink
Upgrade puppeteer version. Fixes alvarcarto#115
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmobrunfeldt committed Nov 5, 2019
1 parent 34cb1a1 commit 89cc04f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 40 deletions.
93 changes: 56 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"lodash": "^4.17.15",
"morgan": "^1.9.1",
"pdf-parse": "^1.1.1",
"puppeteer": "^1.14.0",
"puppeteer": "^2.0.0",
"server-destroy": "^1.0.1",
"winston": "^2.3.1"
},
Expand Down
10 changes: 10 additions & 0 deletions test/resources/special-chars.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>
special characters: ä ö ü
</p>
</body>
</html>
36 changes: 34 additions & 2 deletions test/test-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ function normalisePdfText(text) {
return text.replace(/[\W_]+/g, '-');
}

function getPdfTextContent(buffer) {
function getPdfTextContent(buffer, opts = {}) {
return pdf(buffer)
.then(data => normalisePdfText(data.text));
.then((data) => {
if (opts.raw) {
return data.text;
}

return normalisePdfText(data.text);
});
}

describe('GET /api/render', () => {
Expand Down Expand Up @@ -177,4 +183,30 @@ describe('POST /api/render', () => {
chai.expect(text).to.have.string('Cookie-named-url-to-pdf-test-2');
})
);

it('special characters should be rendered correctly', () =>
request(app)
.post('/api/render')
.send({ html: getResource('special-chars.html') })
.set('Connection', 'keep-alive')
.set('content-type', 'application/json')
.expect(200)
.expect('content-type', 'application/pdf')
.then((response) => {
if (DEBUG) {
console.log(response.headers);
console.log(response.body);
fs.writeFileSync('special-chars.pdf', response.body, { encoding: null });
}

return getPdfTextContent(response.body, { raw: true });
})
.then((text) => {
if (DEBUG) {
fs.writeFileSync('./special-chars-content.txt', text);
}

chai.expect(text).to.have.string('special characters: ä ö ü');
})
);
});

0 comments on commit 89cc04f

Please sign in to comment.