Skip to content

Commit

Permalink
Update tests to only snapshot test headers
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed May 18, 2017
1 parent 9c2c3ac commit 4b171e3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 100 deletions.
132 changes: 37 additions & 95 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,116 +1,58 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`servie-send should send 304 with matching etag 1`] = `
Object {
"body": undefined,
"bytesTransferred": 0,
"finished": false,
"headers": Object {
"etag": "\\"0-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU\\"",
},
"started": false,
"status": 304,
"statusText": undefined,
"trailers": Object {},
Headers {
"raw": Array [
"ETag",
"\\"0-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU\\"",
],
}
`;

exports[`servie-send should send an empty response 1`] = `
Object {
"body": "",
"bytesTransferred": 0,
"finished": false,
"headers": Object {
"content-length": "0",
"content-type": "text/plain",
"etag": "\\"0-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU\\"",
},
"started": false,
"status": 200,
"statusText": undefined,
"trailers": Object {},
Headers {
"raw": Array [
"Content-Type",
"text/plain",
"Content-Length",
"0",
"ETag",
"\\"0-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU\\"",
],
}
`;

exports[`servie-send should send json 1`] = `
Object {
"body": "{\\"hello\\":\\"world\\"}",
"bytesTransferred": 0,
"finished": false,
"headers": Object {
"content-length": "17",
"content-type": "application/json",
"etag": "\\"h-k6I5cakU5erL8KjSUVTNownDwccvu5kU1Hxg88toFYg\\"",
},
"started": false,
"status": 200,
"statusText": undefined,
"trailers": Object {},
Headers {
"raw": Array [
"Content-Type",
"application/json",
"Content-Length",
"17",
"ETag",
"\\"h-k6I5cakU5erL8KjSUVTNownDwccvu5kU1Hxg88toFYg\\"",
],
}
`;

exports[`servie-send should send stream 1`] = `
Object {
"body": Readable {
"_events": Object {},
"_eventsCount": 0,
"_maxListeners": undefined,
"_read": [Function],
"_readableState": ReadableState {
"awaitDrain": 0,
"buffer": BufferList {
"head": null,
"length": 0,
"tail": null,
},
"decoder": null,
"defaultEncoding": "utf8",
"emittedReadable": false,
"encoding": null,
"endEmitted": false,
"ended": false,
"flowing": null,
"highWaterMark": 16384,
"length": 0,
"needReadable": false,
"objectMode": false,
"pipes": null,
"pipesCount": 0,
"ranOut": false,
"readableListening": false,
"reading": false,
"readingMore": false,
"resumeScheduled": false,
"sync": true,
},
"domain": null,
"readable": true,
},
"bytesTransferred": 0,
"finished": false,
"headers": Object {
"content-type": "application/octet-stream",
},
"started": false,
"status": 200,
"statusText": undefined,
"trailers": Object {},
Headers {
"raw": Array [
"Content-Type",
"application/octet-stream",
],
}
`;

exports[`servie-send should send text 1`] = `
Object {
"body": "hello world",
"bytesTransferred": 0,
"finished": false,
"headers": Object {
"content-length": "11",
"content-type": "text/plain",
"etag": "\\"b-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek\\"",
},
"started": false,
"status": 200,
"statusText": undefined,
"trailers": Object {},
Headers {
"raw": Array [
"Content-Type",
"text/plain",
"Content-Length",
"11",
"ETag",
"\\"b-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek\\"",
],
}
`;
26 changes: 21 additions & 5 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@ import { Readable } from 'stream'
describe('servie-send', () => {
it('should send text', () => {
const req = new Request({ url: '/' })
const res = send(req, 'hello world')

expect(send(req, 'hello world')).toMatchSnapshot()
expect(res.status).toEqual(200)
expect(res.headers).toMatchSnapshot()
expect(res.body).toEqual('hello world')
})

it('should send an empty response', () => {
const req = new Request({ url: '/' })
const res = send(req, null)

expect(send(req, null)).toMatchSnapshot()
expect(res.status).toEqual(200)
expect(res.headers).toMatchSnapshot()
expect(res.body).toEqual('')
})

it('should send json', () => {
const req = new Request({ url: '/' })
const res = send(req, { hello: 'world' })

expect(send(req, { hello: 'world' })).toMatchSnapshot()
expect(res.status).toEqual(200)
expect(res.headers).toMatchSnapshot()
expect(res.body).toEqual('{"hello":"world"}')
})

it('should send stream', () => {
Expand All @@ -32,7 +41,10 @@ describe('servie-send', () => {
}
})

expect(send(req, stream)).toMatchSnapshot()
const res = send(req, stream)

expect(res.status).toEqual(200)
expect(res.headers).toMatchSnapshot()
})

it('should send 304 with matching etag', () => {
Expand All @@ -44,6 +56,10 @@ describe('servie-send', () => {
body: ''
})

expect(send(req, '')).toMatchSnapshot()
const res = send(req, '')

expect(res.status).toEqual(304)
expect(res.headers).toMatchSnapshot()
expect(res.body).toEqual(undefined)
})
})

0 comments on commit 4b171e3

Please sign in to comment.