Skip to content

Commit

Permalink
chore: Adds tests to cover #101
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmit committed Aug 22, 2018
1 parent 20b4125 commit 1fdcfea
Show file tree
Hide file tree
Showing 10 changed files with 802 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/helpers/setup-fetch-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ setupFetchRecord.beforeEach = function(options = {}) {
const { host, fetch } = options;

this.fetch = fetch;

this.relativeFetch = (url, options) => {
return this.fetch(`${host}${url}`, options);
}

this.recordUrl = () =>
`${host}/api/db/${encodeURIComponent(this.polly.recordingId)}`;
Expand Down
5 changes: 4 additions & 1 deletion tests/helpers/xhr-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export default function request(url, obj = {}) {

xhr.send(obj.body);
}).then(xhr => {
return new Response(xhr.responseText, {
const responseBody =
xhr.status === 204 && xhr.responseText === '' ? null : xhr.responseText;

return new Response(responseBody, {
status: xhr.status,
statusText: xhr.statusText,
headers: XHRUtils.serializeResponseHeaders(xhr.getAllResponseHeaders())
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/adapter-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export default function adapterTests() {
expect(res.status).to.equal(404);
});

it('should properly handle 204 status code response', async function() {
const noContentResponse = await this.relativeFetch('/echo?status=204');

expect(noContentResponse.status).to.equal(204);
expect((await noContentResponse.text())).to.equal('');
});

it('should intercept', async function() {
const { server } = this.polly;

Expand Down
4 changes: 4 additions & 0 deletions tests/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module.exports = function attachMiddleware(app) {

app.use(bodyParser.json());

app.get('/echo', (req, res) => {
res.sendStatus(req.query.status);
});

app.get('/api', (req, res) => {
res.sendStatus(200);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"log": {
"_recordingName": "@pollyjs/adapter-fetch/Integration | Fetch Adapter | Browser/should properly handle 204 status code response",
"browser": {
"name": "Chrome",
"version": "68.0"
},
"creator": {
"comment": "persister:rest",
"name": "Polly.JS",
"version": "1.1.3"
},
"entries": [
{
"_id": "5909f0e1318b6dcc04f333049dfb1aa6",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [],
"headersSize": 56,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "status",
"value": "204"
}
],
"url": "http://localhost:4000/echo?status=204"
},
"response": {
"bodySize": 10,
"content": {
"mimeType": "text/plain; charset=utf-8",
"size": 10
},
"cookies": [],
"headers": [
{
"name": "connection",
"value": "keep-alive"
},
{
"name": "content-length",
"value": "10"
},
{
"name": "content-type",
"value": "text/plain; charset=utf-8"
},
{
"name": "date",
"value": "Wed, 22 Aug 2018 07:03:38 GMT"
},
{
"name": "etag",
"value": "W/\"a-bAsFyilMr4Ra1hIU5PyoyFRunpI\""
},
{
"name": "x-powered-by",
"value": "Express"
}
],
"headersSize": 188,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 204,
"statusText": "No Content"
},
"startedDateTime": "2018-08-22T07:03:38.001Z",
"time": 23,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 23
}
}
],
"pages": [],
"version": "1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"log": {
"_recordingName": "@pollyjs/adapter-fetch/Integration | Fetch Adapter | Node/should properly handle 204 status code response",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "1.1.3"
},
"entries": [
{
"_id": "9168e14367587796869c4ba64c6d988b",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [],
"headersSize": 56,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "status",
"value": "204"
}
],
"url": "http://localhost:4000/echo?status=204"
},
"response": {
"bodySize": 10,
"content": {
"mimeType": "text/plain; charset=utf-8",
"size": 10
},
"cookies": [],
"headers": [
{
"name": "connection",
"value": "close"
},
{
"name": "content-length",
"value": "10"
},
{
"name": "content-type",
"value": "text/plain; charset=utf-8"
},
{
"name": "date",
"value": "Wed, 22 Aug 2018 07:03:38 GMT"
},
{
"name": "etag",
"value": "W/\"a-bAsFyilMr4Ra1hIU5PyoyFRunpI\""
},
{
"name": "x-powered-by",
"value": "Express"
}
],
"headersSize": 183,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 204,
"statusText": "No Content"
},
"startedDateTime": "2018-08-22T07:03:38.563Z",
"time": 18,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 18
}
}
],
"pages": [],
"version": "1.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,72 @@
"ssl": -1,
"wait": 15
}
},
{
"_id": "814d95c967e997997fec27f270b5743d",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "referer",
"value": "http://localhost:4000/api"
},
{
"name": "user-agent",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/70.0.3508.0 Safari/537.36"
}
],
"headersSize": 369,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [],
"url": "http://localhost:4000/api/db/-pollyjs_2160168770%2Fadapter-puppeteer_3356991759%2FIntegration-Puppeteer-Adapter_1203948916%2Fshould-be-able-to-abort-from-an-intercept_68559697"
},
"response": {
"bodySize": 0,
"content": {
"mimeType": "text/plain",
"size": 0
},
"cookies": [],
"headers": [
{
"name": "date",
"value": "Wed, 22 Aug 2018 07:03:40 GMT"
},
{
"name": "connection",
"value": "keep-alive"
},
{
"name": "x-powered-by",
"value": "Express"
},
{
"name": "content-length",
"value": "0"
}
],
"headersSize": 105,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 404,
"statusText": "Not Found"
},
"startedDateTime": "2018-08-22T07:03:40.494Z",
"time": 12,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 12
}
}
],
"pages": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"log": {
"_recordingName": "@pollyjs/adapter-puppeteer/Integration | Puppeteer Adapter/should properly handle 204 status code response",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "1.1.3"
},
"entries": [
{
"_id": "d5730011f27edae7e3f703c95a641430",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"name": "referer",
"value": "http://localhost:4000/api"
},
{
"name": "user-agent",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/70.0.3508.0 Safari/537.36"
}
],
"headersSize": 231,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "status",
"value": "204"
}
],
"url": "http://localhost:4000/echo?status=204"
},
"response": {
"bodySize": 10,
"content": {
"mimeType": "text/plain; charset=utf-8",
"size": 10
},
"cookies": [],
"headers": [
{
"name": "date",
"value": "Wed, 22 Aug 2018 07:03:39 GMT"
},
{
"name": "connection",
"value": "keep-alive"
},
{
"name": "x-powered-by",
"value": "Express"
},
{
"name": "etag",
"value": "W/\"a-bAsFyilMr4Ra1hIU5PyoyFRunpI\""
},
{
"name": "content-length",
"value": "10"
},
{
"name": "content-type",
"value": "text/plain; charset=utf-8"
}
],
"headersSize": 188,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 204,
"statusText": "No Content"
},
"startedDateTime": "2018-08-22T07:03:39.815Z",
"time": 11,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 11
}
}
],
"pages": [],
"version": "1.2"
}
}
Loading

0 comments on commit 1fdcfea

Please sign in to comment.