Package Exports
- @open-draft/test-server
- @open-draft/test-server/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@open-draft/test-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
test-server
Spawns HTTP/HTTPS/WS/WSS local servers for testing.
Install
npm install @open-draft/test-serverHTTP
import fetch from 'node-fetch'
import { createServer } from '@open-draft/test-server'
let server
beforeAll(async () => {
server = await createServer((app) => {
app.get('/numbers', (req, res) => {
return res.status(200).json([1, 2, 3])
})
})
})
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
const server = await createServer()
console.log('WebSocket server running at:', server.ws.address.toString())
server.ws.instance.on('connect', (socket) => {
console.log('new connection', socket.id)
})