Skip to content
This repository was archived by the owner on Apr 7, 2020. It is now read-only.

Commit 3a5a53b

Browse files
committed
xReformat test
1 parent c32efd2 commit 3a5a53b

File tree

2 files changed

+70
-71
lines changed

2 files changed

+70
-71
lines changed

test/integration.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,31 +84,31 @@ describe('integration', () => {
8484
});
8585
});
8686

87-
describe('POST /pdf', () => {
88-
it('should render valid pdf from POSTED html in fixtures/example.html', function renderPdf(done) {
89-
this.slow(10000);
90-
const exampleHtmlPath = path.join(fixturePath, 'example.html');
91-
92-
request.post('/pdf')
93-
.parse(parseBuffer) // Superagent does not detect PDF
94-
.type('form')
95-
.query({ accessKey: process.env.RENDERER_ACCESS_KEY })
96-
.send(fs.readFileSync(exampleHtmlPath, 'utf-8'))
97-
.expect((res) => {
98-
if (res.statusCode !== 200) {
99-
throw new Error(`Invalid response code: ${res.statusCode}\n${res.body}`);
100-
}
101-
102-
const examplePdfPath = path.join(fixturePath, 'example.pdf');
103-
const fixture = fs.readFileSync(examplePdfPath);
104-
105-
if (res.body.slice(150).compare(fixture.slice(150)) === 0) return; // Slice out ModDate
106-
107-
fs.writeFileSync('./example_failed.pdf', res.body);
108-
execSync('curl --upload-file ./example_failed.pdf https://transfer.sh/example_failed.pdf', { stdio: 'inherit' });
109-
throw new Error(`${examplePdfPath} does not match rendered pdf`);
110-
})
111-
.end(done);
112-
});
87+
describe('POST /pdf', () => {
88+
it('should render valid pdf from POSTED html in fixtures/example.html', function renderPdf(done) {
89+
this.slow(10000);
90+
const exampleHtmlPath = path.join(fixturePath, 'example.html');
91+
92+
request.post('/pdf')
93+
.parse(parseBuffer) // Superagent does not detect PDF
94+
.type('form')
95+
.query({ accessKey: process.env.RENDERER_ACCESS_KEY })
96+
.send(fs.readFileSync(exampleHtmlPath, 'utf-8'))
97+
.expect((res) => {
98+
if (res.statusCode !== 200) {
99+
throw new Error(`Invalid response code: ${res.statusCode}\n${res.body}`);
100+
}
101+
102+
const examplePdfPath = path.join(fixturePath, 'example.pdf');
103+
const fixture = fs.readFileSync(examplePdfPath);
104+
105+
if (res.body.slice(150).compare(fixture.slice(150)) === 0) return; // Slice out ModDate
106+
107+
fs.writeFileSync('./example_failed.pdf', res.body);
108+
execSync('curl --upload-file ./example_failed.pdf https://transfer.sh/example_failed.pdf', { stdio: 'inherit' });
109+
throw new Error(`${examplePdfPath} does not match rendered pdf`);
110+
})
111+
.end(done);
113112
});
113+
});
114114
});

test/stability.js

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,54 @@ const fs = require('fs');
44
const path = require('path');
55
const async = require('async');
66
const { execSync } = require('child_process');
7+
78
const bigTableHtml = fs.readFileSync(path.resolve(__dirname, 'fixtures/bigTable.html'), 'utf-8');
89

910
const parseBuffer = (res, fn) => { // Superagent does not detect PDF
10-
const data = [];
11-
res.on('data', chunk => data.push(chunk));
12-
res.on('end', () => fn(null, Buffer.concat(data)));
11+
const data = [];
12+
res.on('data', chunk => data.push(chunk));
13+
res.on('end', () => fn(null, Buffer.concat(data)));
1314
};
1415

1516
describe('stability', () => {
16-
describe('POST /pdf', () => {
17-
it('should render proper PDF\'s when posting large amounts of big HTML chunks', function (done) {
18-
this.timeout(60000);
19-
this.slow(30000);
20-
21-
const fixturePath = path.join(__dirname, 'fixtures');
22-
const examplePdfPath = path.join(fixturePath, 'bigTable.pdf');
23-
const fixture = fs.readFileSync(examplePdfPath);
24-
25-
var q = async.queue(function(task, callback) {
26-
request
27-
.post('/pdf')
28-
.parse(parseBuffer) // Superagent does not detect PDF
29-
.type('form')
30-
.send(bigTableHtml)
31-
.query({ accessKey: process.env.RENDERER_ACCESS_KEY })
32-
.expect((res) => {
33-
if (res.statusCode !== 200) {
34-
const errMsg = `Invalid response code: ${res.statusCode}\n${JSON.stringify(res.body)}`;
35-
throw new Error(errMsg);
36-
}
37-
38-
if (res.body.slice(150).compare(fixture.slice(150)) === 0) return; // Slice out ModDate
39-
40-
fs.writeFileSync('./bigTable_failed.pdf', res.body);
41-
execSync('curl --upload-file ./bigTable_failed.pdf https://transfer.sh/bigTable_failed.pdf', { stdio: 'inherit' });
42-
throw new Error(`${examplePdfPath} (${task}) does not match rendered screenshot`);
43-
})
44-
.end(callback);
45-
}, 8);
46-
47-
for (var i = 0; i < 80; i++) {
48-
q.push(i, function (err) {
49-
if (err) {
50-
done(err);
51-
}
52-
});
53-
};
54-
55-
q.drain = done;
56-
});
57-
});
17+
describe('POST /pdf', () => {
18+
it('should render proper PDF\'s when posting large amounts of big HTML chunks', function largeHTMLTest(done) {
19+
this.timeout(60000);
20+
this.slow(30000);
21+
22+
const fixturePath = path.join(__dirname, 'fixtures');
23+
const examplePdfPath = path.join(fixturePath, 'bigTable.pdf');
24+
const fixture = fs.readFileSync(examplePdfPath);
25+
26+
const q = async.queue((task, callback) => {
27+
request
28+
.post('/pdf')
29+
.parse(parseBuffer) // Superagent does not detect PDF
30+
.type('form')
31+
.send(bigTableHtml)
32+
.query({ accessKey: process.env.RENDERER_ACCESS_KEY })
33+
.expect((res) => {
34+
if (res.statusCode !== 200) {
35+
const errMsg = `Invalid response code: ${res.statusCode}\n${JSON.stringify(res.body)}`;
36+
throw new Error(errMsg);
37+
}
38+
39+
if (res.body.slice(150).compare(fixture.slice(150)) === 0) return; // Slice out ModDate
40+
41+
fs.writeFileSync('./bigTable_failed.pdf', res.body);
42+
execSync('curl --upload-file ./bigTable_failed.pdf https://transfer.sh/bigTable_failed.pdf', { stdio: 'inherit' });
43+
throw new Error(`${examplePdfPath} (${task}) does not match rendered screenshot`);
44+
})
45+
.end(callback);
46+
}, 8);
47+
48+
for (let i = 0; i < 80; i += 1) {
49+
q.push(i, (err) => {
50+
if (err) done(err);
51+
});
52+
}
53+
54+
q.drain = done;
55+
});
56+
});
5857
});

0 commit comments

Comments
 (0)