0.6.2 • Published 3 months ago

@open-draft/test-server v0.6.2

Weekly downloads
56
License
MIT
Repository
github
Last release
3 months ago

npm

test-server

Spawns HTTP/HTTPS/WS/WSS local servers for testing.

Install

npm install @open-draft/test-server

HTTP

import fetch from 'node-fetch'
import { HttpServer } from '@open-draft/test-server/http'

const server = new HttpServer((app) => {
  app.get('/numbers', (req, res) => {
    return res.status(200).json([1, 2, 3])
  })
})

beforeAll(async () => {
  await server.listen()
})

afterAll(async () => {
  await server.close()
})

test('fetches all the numbers', async () => {
  const res = await fetch(server.http.url('/books'))
  expect(res.status).toBe(200)
  expect(await res.json()).toEqual([1, 2, 3])
})

WebSocket

import { WebSocketServer } from '@open-draft/test-server/ws'

const server = await WebSocketServer()

console.log('WebSocket server running at:', server.ws.address.href)

server.ws.instance.on('connect', (socket) => {
  console.log('new connection', socket.id)
})
0.6.2

3 months ago

0.6.1

6 months ago

0.6.0

6 months ago

0.5.1

1 year ago

0.5.0

2 years ago

0.3.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.4.2

2 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago