-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e902b90
commit 8e40688
Showing
9 changed files
with
481 additions
and
570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// /test/helpers/server.ts | ||
// Create an Express server for testing | ||
|
||
import createApp, { | ||
type Application, | ||
type Request, | ||
type Response, | ||
type RequestHandler, | ||
} from 'express' | ||
|
||
/** | ||
* Create an Express server with the given middleware. | ||
*/ | ||
export const createServer = ( | ||
middleware: RequestHandler | RequestHandler[], | ||
): Application => { | ||
// Create an Express server, and register the middleware. | ||
const app = createApp() | ||
app.use(middleware) | ||
|
||
// Register test routes. | ||
app.all('/', (_request: Request, response: Response) => | ||
response.send('Hi there!'), | ||
) | ||
app.get('/ip', (request: Request, response: Response) => { | ||
response.setHeader('x-your-ip', request.ip) | ||
response.sendStatus(204) | ||
}) | ||
app.all('/sleepy', middleware, (_request: Request, response: Response) => { | ||
const timerId = setTimeout(() => response.send('Hallo there!'), 100) | ||
response.on('close', () => clearTimeout(timerId)) | ||
}) | ||
app.get('/error', (_request: Request, response: Response) => | ||
response.sendStatus(400), | ||
) | ||
app.post('/crash', (_request: Request, response: Response) => { | ||
response.emit('error', new Error('Oops!')) | ||
response.on('error', () => response.end()) | ||
}) | ||
|
||
// Return the application instance. | ||
return app | ||
} |
Oops, something went wrong.