Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vercel/test-listen
Quick ephemeral URLs for your tests
https://github.com/vercel/test-listen
Last synced: 27 days ago
JSON representation
Quick ephemeral URLs for your tests
- Host: GitHub
- URL: https://github.com/vercel/test-listen
- Owner: vercel
- License: mit
- Created: 2016-02-05T01:26:02.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2023-07-20T00:53:01.000Z (over 1 year ago)
- Last Synced: 2024-09-30T12:41:36.747Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://npmjs.com/test-listen
- Size: 581 KB
- Stars: 155
- Watchers: 51
- Forks: 19
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: license.md
Awesome Lists containing this project
README
> **Warning**
> `test-listen` is deprecated. Please use [`async-listen`](https://github.com/vercel/async-listen) instead.# test-listen
URLs with ephemeral ports. `async`/`await` ready.
## Usage
Install it:
```
npm install --save-dev test-listen
```Pass a `http.Server` to `test-listen` and it will return an URL in the format `http://localhost:{port}`.
The second parameter can optionally be a hostname to return in the URL
instead of `localhost`.Useful for running HTTP server testsuites:
```js
const http = require('http')
const listen = require('test-listen')const srv = http.createServer((req, res) => res.end('1'))
const srv2 = http.createServer((req, res) => res.end('2'))test('urls', async t => {
let url = await listen(srv)
t.ok(url == 'http://localhost:11401')
let url = await listen(srv2)
t.ok(url == 'http://localhost:42333')
})
```It also works with Express:
```js
const http = require('http')
const express = require('express')
const listen = require('test-listen')const srv = express()
test('urls', async t => {
let url = await listen(http.createServer(srv))
t.ok(url == 'http://localhost:11401')
})
```Or Koa:
```js
const http = require('http')
const Koa = require('koa')
const listen = require('test-listen')const srv = new Koa();
test('urls', async t => {
let url = await listen(http.createServer(srv.callback()))
t.ok(url == 'http://localhost:11401')
})
```## Authors
- Guillermo Rauch ([@rauchg](https://twitter.com/rauchg)) - [Vercel](https://vercel.com)
- Leo Lamprecht ([@notquiteleo](https://twitter.com/notquiteleo)) - [Vercel](https://vercel.com)