Skip to content

Snippet: Node test runner request example that gracefully shutdown server #12

@trasherdk

Description

@trasherdk
import { test } from 'node:test'
import { strict as assert } from 'node:assert';

import uWS from 'uWebSockets.js'

test('test server request / response', (t, done) => {
  const port = 3000
  const app = uWS.App()

  app.get('/test', (res, req) => {
    res.writeStatus('200')
    res.end('hello world')
  })

  app.listen(port, async (listenSocket) => {
    const res = await fetch(new Request(`http://localhost:${port}/test`))
    const responseText = await res.text()
    assert.strictEqual(res.status, 200)
    assert.strictEqual(responseText, 'hello world')
    // uWS.us_listen_socket_close(listenSocket);
    // listenSocket = null;
    app.close()
    done()
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions