Skip to content
This repository has been archived by the owner on Aug 16, 2019. It is now read-only.

Commit

Permalink
Run prettier on the e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Masters committed Jan 11, 2019
1 parent a3ac41d commit 6b238f5
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/__tests__/server.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ describe('server e2e', () => {
let counter: number;

beforeAll(async () => {
server = stoppable(await express()
.get('/counter', (req, res) => {
res.json({ counter: counter++ });
})
.listen(3001));
server = stoppable(
await express()
.get('/counter', (req, res) => {
res.json({ counter: counter++ });
})
.listen(3001)
);
});

beforeEach(async () => {
Expand All @@ -23,8 +25,8 @@ describe('server e2e', () => {
pollyResponse = await fetch(
'http://localhost:3000/stop?testName=server-e2e',
{
method: 'POST',
},
method: 'POST'
}
).then(x => x.text());

expect(pollyResponse).toBe('');
Expand All @@ -40,78 +42,78 @@ describe('server e2e', () => {
const random = Math.random();
const response = await fetch(
`http://localhost:3000/addproxy?proxyPath=${encodeURIComponent(
`http://localhost:${(server.address() as AddressInfo).port}`,
`http://localhost:${(server.address() as AddressInfo).port}`
)}`,
{
method: 'POST',
},
method: 'POST'
}
).then(x => x.json());
expect(response.port).toBeGreaterThan(3000);

// should be a cache miss
expect(
(await fetch(
`http://localhost:${response.port}/counter?random=${random}`,
).then(x => x.json())).counter,
`http://localhost:${response.port}/counter?random=${random}`
).then(x => x.json())).counter
).toBe(5);

// should still be a cache miss
expect(
(await fetch(
`http://localhost:${response.port}/counter?random=${random}`,
).then(x => x.json())).counter,
`http://localhost:${response.port}/counter?random=${random}`
).then(x => x.json())).counter
).toBe(6);
});

it('record API calls', async () => {
const response = await fetch(
`http://localhost:3000/addproxy?proxyPath=${encodeURIComponent(
`http://localhost:${(server.address() as AddressInfo).port}`,
`http://localhost:${(server.address() as AddressInfo).port}`
)}`,
{
method: 'POST',
},
method: 'POST'
}
).then(x => x.json());
expect(response.port).toBeGreaterThan(3000);

let replayResponse: string;
replayResponse = await fetch(
'http://localhost:3000/replay?testName=server-e2e',
'http://localhost:3000/record?testName=server-e2e',
{
method: 'POST',
},
method: 'POST'
}
).then(x => x.text());

expect(replayResponse).toBe('');

let random = Math.random();

let cacheMissResponse = (await fetch(
`http://localhost:${response.port}/counter?random=${random}`,
`http://localhost:${response.port}/counter?random=${random}`
).then(x => x.json())).counter;

// should be a cache miss
expect(cacheMissResponse).toBe(5);

await fetch('http://localhost:3000/stop?testName=server-e2e').then(x =>
x.text(),
x.text()
);

// "rewind" the recording
replayResponse = await fetch(
'http://localhost:3000/replay?testName=server-e2e',
{
method: 'POST',
},
method: 'POST'
}
).then(x => x.text());

expect(replayResponse).toBe('');

// should be a cache hit
expect(
(await fetch(
`http://localhost:${response.port}/counter?random=${random}`,
).then(x => x.json())).counter,
`http://localhost:${response.port}/counter?random=${random}`
).then(x => x.json())).counter
).toBe(5);
});

Expand Down

0 comments on commit 6b238f5

Please sign in to comment.