Skip to content

Commit 6744d2e

Browse files
committed
Add symbol docs and revrite tests from TODO
1 parent b17bf88 commit 6744d2e

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import pify from "pify";
77
import bodyParser, { OptionsJson, OptionsText, OptionsUrlencoded } from "body-parser";
88

99
// Thank @midgleyc for providing the type definitions
10+
/** The test server itself */
1011
export type TestServer = TestServerWrapper
1112
& Omit<express.Express, 'listen'>
1213
& {get: (url: string, response: unknown) => void};
1314

14-
export interface Options {
15+
/** Options that can be provided to the `createTestServer` function */
16+
export interface TestServerOptions {
1517
/**
1618
* Body parser options object to be passed to `body-parser` methods.
1719
*
@@ -23,6 +25,7 @@ export interface Options {
2325
& OptionsUrlencoded;
2426
}
2527

28+
/** Internal wrapper for the test server */
2629
export interface TestServerWrapper {
2730
/**
2831
* The url you can reach the HTTP server on.
@@ -61,7 +64,8 @@ export interface TestServerWrapper {
6164
close: () => Promise<void>;
6265
}
6366

64-
export const createTestServer = (opts: Options = {}): Promise<TestServer> => {
67+
/** Creates the test server that you can use it the tests */
68+
export const createTestServer = (opts: TestServerOptions = {}): Promise<TestServer> => {
6569
const _express = express();
6670
const server = _express as never as TestServer;
6771
server.http = http.createServer(_express);

test/index.test.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createTestServer } from '../src';
33
import { expect, test } from 'vitest'
44
import * as querystring from 'querystring';
55
import axios from 'axios';
6-
import express from "express";
76

87
test('server instance exposes useful properties', async () => {
98
const server = await createTestServer();
@@ -119,7 +118,7 @@ test('opts.bodyParser is passed through to bodyParser', async () => {
119118
const buf = Buffer.alloc(150 * 1024);
120119

121120
// Custom error handler so we don't dump the stack trace in the test output
122-
smallServer.use((_err: any, _req: any, res: any, _next: any) => { // eslint-disable-line no-unused-vars
121+
smallServer.use((_err: any, _req: any, res: any, _next: any) => {
123122
res.status(500).end();
124123
});
125124

@@ -134,15 +133,13 @@ test('opts.bodyParser is passed through to bodyParser', async () => {
134133
});
135134

136135
// TODO: Rewrite
137-
// await t.throws(got.post(smallServer.url, {
138-
// headers: { 'content-type': 'application/octet-stream' },
139-
// body: buf
140-
// }));
141-
142-
// await t.notThrows(got.post(bigServer.url, {
143-
// headers: { 'content-type': 'application/octet-stream' },
144-
// body: buf
145-
// }));
136+
await expect(axios.post(smallServer.url!, buf, {
137+
headers: { 'content-type': 'application/octet-stream' },
138+
})).rejects.toThrow("500")
139+
140+
await expect(axios.post(bigServer.url!, buf, {
141+
headers: { 'content-type': 'application/octet-stream' },
142+
})).resolves.toMatchObject({status: 200});
146143
});
147144

148145
test('if opts.bodyParser is false body parsing middleware is disabled', async () => {

0 commit comments

Comments
 (0)