denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.11k stars 614 forks source link

Feature Require: HTTP mock tester #535

Closed axetroy closed 3 years ago

axetroy commented 5 years ago

The current HTTP test is tested by opening the child process, which will actually listen to the port.

We should provide a way to set up a simulated HTTP server without listening to the port.

so that we can test this HTTP server without any cost.

import { mock } from "https://deno.land/std/http/mock.ts";
import { serve } from "https://deno.land/std/http/server.ts";

const s = serve("0.0.0.0:8000");

const mocker = mock(s);

const response = mocker.get("/test");

// ...

The above code, it seems impossible, it is just a hypothesis of mine.

If anyone has a better idea, welcome post it.

This is the tool I wrote in Golang before. axetroy/mocker

zekth commented 5 years ago

To add for ref i like the Fastify implementation inject. Ref: https://github.com/fastify/fastify/blob/master/docs/Testing.md

ry commented 5 years ago

@axetroy How do they do this within the Go standard library?