@open-draft/test-server

HTTP/HTTPS testing server for your tests.

Usage no npm install needed!

<script type="module">
  import openDraftTestServer from 'https://cdn.skypack.dev/@open-draft/test-server';
</script>

README

npm

Test Server

Creates HTTP and HTTPS server with an optional server middleware for testing purposes. Designed to re-create the "actual" server behavior.

Getting started

Install

$ npm install @open-draft/test-server

Usage

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.makeUrl('/books'))
  expect(res.status).toBe(200)
  expect(await res.json()).toEqual([1, 2, 3])
})