Skip to content

Commit

Permalink
tests: use sync functions to compress body payload (graphql#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored and jliu670 committed Aug 14, 2020
1 parent a937556 commit 3c652a2
Showing 1 changed file with 8 additions and 37 deletions.
45 changes: 8 additions & 37 deletions src/__tests__/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,6 @@ function urlString(urlParams?: ?{ [param: string]: mixed }) {
return string;
}

function promiseTo(fn) {
return new Promise((resolve, reject) => {
fn((error, result) => (error ? reject(error) : resolve(result)));
});
}

describe('test harness', () => {
it('resolves callback promises', async () => {
const resolveValue = {};
const result = await promiseTo(cb => cb(null, resolveValue));
expect(result).to.equal(resolveValue);
});

it('rejects callback promises with errors', async () => {
const rejectError = new Error();
let caught;
try {
await promiseTo(cb => cb(rejectError));
} catch (error) {
caught = error;
}
expect(caught).to.equal(rejectError);
});
});

[
[connect, 'connect'],
[express, 'express'],
Expand Down Expand Up @@ -846,17 +821,15 @@ describe('test harness', () => {
})),
);

const data = { query: '{ test(who: "World") }' };
const json = JSON.stringify(data);
const gzippedJson = await promiseTo(cb => zlib.gzip(json, cb));

const req = request(app)
.post(urlString())
.set('Content-Type', 'application/json')
.set('Content-Encoding', 'gzip');
req.write(gzippedJson);
const response = await req;

// eslint-disable-next-line no-sync
req.write(zlib.gzipSync('{ "query": "{ test }" }'));

const response = await req;
expect(JSON.parse(response.text)).to.deep.equal({
data: {
test: 'Hello World',
Expand All @@ -875,17 +848,15 @@ describe('test harness', () => {
})),
);

const data = { query: '{ test(who: "World") }' };
const json = JSON.stringify(data);
const deflatedJson = await promiseTo(cb => zlib.deflate(json, cb));

const req = request(app)
.post(urlString())
.set('Content-Type', 'application/json')
.set('Content-Encoding', 'deflate');
req.write(deflatedJson);
const response = await req;

// eslint-disable-next-line no-sync
req.write(zlib.deflateSync('{ "query": "{ test }" }'));

const response = await req;
expect(JSON.parse(response.text)).to.deep.equal({
data: {
test: 'Hello World',
Expand Down

0 comments on commit 3c652a2

Please sign in to comment.