From 4adc4b645233f7d70be7a1b5448bfe4048ccf575 Mon Sep 17 00:00:00 2001 From: Kimmo Brunfeldt Date: Sun, 5 Aug 2018 13:34:32 +0300 Subject: [PATCH] Add test cases for larger images --- .eslintrc | 1 + docs/local-examples.md | 3 +++ test/resources/large-linked.html | 19 ++++++++++++++ test/resources/large.html | 22 ++++++++++++++++ test/test-all.js | 45 ++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 docs/local-examples.md create mode 100644 test/resources/large-linked.html create mode 100644 test/resources/large.html diff --git a/.eslintrc b/.eslintrc index d39bf19a..c4da745d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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", diff --git a/docs/local-examples.md b/docs/local-examples.md new file mode 100644 index 00000000..7559b163 --- /dev/null +++ b/docs/local-examples.md @@ -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 \ No newline at end of file diff --git a/test/resources/large-linked.html b/test/resources/large-linked.html new file mode 100644 index 00000000..981772bb --- /dev/null +++ b/test/resources/large-linked.html @@ -0,0 +1,19 @@ + + + + + + Test Page + + + +

Page

+ + + + + diff --git a/test/resources/large.html b/test/resources/large.html new file mode 100644 index 00000000..dccb023e --- /dev/null +++ b/test/resources/large.html @@ -0,0 +1,22 @@ + + + + + + Test Page + + + +

Page

+ + + + + + + + diff --git a/test/test-all.js b/test/test-all.js index f8666ed9..a8b7aeb5 100644 --- a/test/test-all.js +++ b/test/test-all.js @@ -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', () => { @@ -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); + }) + ); });