Skip to content

Commit

Permalink
Add a failing test :(
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco committed Dec 7, 2017
1 parent 62b8a4a commit 1a269ca
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions tests/server.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
const createServer = require('../lib/server')
const request = require('supertest')
const EventSource = require('eventsource')

describe('server', () => {
let server
let app, server, events, url, channel

beforeEach(() => {
server = createServer()
beforeEach((done) => {
channel = '/fake-channel'
app = createServer()

server = app.listen(0, () => {
url = `http://127.0.0.1:${server.address().port}${channel}`

// Wait for event source to be ready
events = new EventSource(url)
events.addEventListener('ready', () => done())
})
})

afterEach(() => {
server && server.close()
events && events.close()
})

describe('GET /', () => {
Expand All @@ -18,12 +33,26 @@ describe('server', () => {

describe('GET /:channel', () => {
it('returns the proper HTML', async () => {
const res = await request(server).get('/fake-channel')
const res = await request(server).get(channel)
expect(res.status).toBe(200)
expect(res.text).toMatchSnapshot()
})
})

describe('events', () => {
it('emits events', async () => {
const spy = jest.fn()

events.addEventListener('message', (message) => {
spy(message)
})

const res = await request(server).post(channel).send({ payload: true })
expect(res.status).toBe(200)
expect(spy).toHaveBeenCalled()
})
})

it('POST /:channel/redeliver re-emits a payload', async () => {
const payload = {
foo: true,
Expand Down

0 comments on commit 1a269ca

Please sign in to comment.