Skip to content

Commit

Permalink
Add test cases for larger images
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmobrunfeldt committed Aug 5, 2018
1 parent 5c64237 commit 4adc4b6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
"no-use-before-define": ["error", { "functions": false }],
"no-underscore-dangle": "off",
"no-console": "off",
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
Expand Down
3 changes: 3 additions & 0 deletions docs/local-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Local examples

curl -o html.pdf -XPOST -d@test/resources/large-linked.html -H"content-type: text/html" https://url-to-pdf-api.herokuapp.com/api/render
19 changes: 19 additions & 0 deletions test/resources/large-linked.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Test Page</title>
<style>
img {
width: 100%;
}
</style>
</head>
<body>
<h1>Page</h1>
<img src="https://images.unsplash.com/photo-1440658172029-9d9e5cdc127c?auto=format&fit=crop&w=2026&q=60&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D">
<img src="https://images.unsplash.com/photo-1440658172029-9d9e5cdc127c?auto=format&fit=crop&w=2026&q=60&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D">
<img src="https://images.unsplash.com/photo-1440658172029-9d9e5cdc127c?auto=format&fit=crop&w=2026&q=60&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D">
</body>
</html>
22 changes: 22 additions & 0 deletions test/resources/large.html

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions test/test-all.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
/* eslint-env mocha */

const chai = require('chai');
const fs = require('fs');
const request = require('supertest');
const BPromise = require('bluebird');
const { getResource } = require('./util');
const createApp = require('../src/app');

const DEBUG = false;

BPromise.config({
longStackTraces: true,
});

const app = createApp();

describe('GET /api/render', () => {
Expand Down Expand Up @@ -84,4 +92,41 @@ describe('POST /api/render', () => {
chai.expect(length).to.be.above(1024 * 40);
})
);

/*
Disabled until we get the setContent API working with waitFor parameters
it('rendering large html should succeed', () =>
request(app)
.post('/api/render')
.send(getResource('large.html'))
.set('content-type', 'text/html')
.expect(200)
.expect('content-type', 'application/pdf')
.then((response) => {
const length = Number(response.headers['content-length']);
chai.expect(length).to.be.above(1024 * 1024 * 1);
})
);
*/

it('rendering html with large linked images should succeed', () =>
request(app)
.post('/api/render')
.send(getResource('large-linked.html'))
.set('content-type', 'text/html')
.expect(200)
.expect('content-type', 'application/pdf')
.then((response) => {
if (DEBUG) {
console.log(response.headers);
console.log(response.body);
fs.writeFileSync('out.pdf', response.body, { encoding: null });
}

const length = Number(response.headers['content-length']);
chai.expect(length).to.be.above(30 * 1024 * 1);
})
);
});

0 comments on commit 4adc4b6

Please sign in to comment.