2
2
"use strict" ;
3
3
import assert from "power-assert" ;
4
4
import connect from "connect" ;
5
+ import errorHandler from "../../src/connect/errorHandler" ;
5
6
import nosniff from "../../src/connect/nosniff" ;
6
7
import hello from "../../src/connect/hello" ;
7
8
import http from "http" ;
8
9
import fetch from "node-fetch" ;
9
10
describe ( "connect" , function ( ) {
10
11
var responseText = "test" ;
11
12
var server ;
12
- before ( function ( done ) {
13
- var app = connect ( ) ;
14
- app . use ( nosniff ( ) ) ;
15
- app . use ( hello ( responseText ) ) ;
16
- server = http . createServer ( app ) . listen ( 3000 , done ) ;
17
- } ) ;
18
- after ( function ( ) {
19
- server . close ( ) ;
13
+ describe ( "errorHandler" , function ( ) {
14
+ beforeEach ( function ( done ) {
15
+ var app = connect ( ) ;
16
+ app . use ( errorHandler ( ) ) ;
17
+ app . use ( ( req , res , next ) => {
18
+ next ( new Error ( "wrong" ) ) ;
19
+ } ) ;
20
+ server = http . createServer ( app ) . listen ( 3000 , done ) ;
21
+ } ) ;
22
+ afterEach ( function ( ) {
23
+ server && server . close ( ) ;
24
+ } ) ;
25
+ it ( "should return 500 status response" , function ( ) {
26
+ return fetch ( "http://localhost:3000" )
27
+ . then ( res => res . status )
28
+ . then ( status => {
29
+ assert ( status , 500 ) ;
30
+ } ) ;
31
+ } ) ;
32
+
20
33
} ) ;
21
34
describe ( "hello" , function ( ) {
35
+ beforeEach ( function ( done ) {
36
+ var app = connect ( ) ;
37
+ app . use ( errorHandler ( ) ) ;
38
+ app . use ( hello ( responseText ) ) ;
39
+ server = http . createServer ( app ) . listen ( 3000 , done ) ;
40
+ } ) ;
41
+ afterEach ( function ( ) {
42
+ server && server . close ( ) ;
43
+ } ) ;
22
44
it ( "should return response text" , function ( ) {
23
45
return fetch ( "http://localhost:3000" )
24
46
. then ( res => res . text ( ) )
@@ -28,6 +50,15 @@ describe("connect", function () {
28
50
} ) ;
29
51
} ) ;
30
52
describe ( "sniff" , function ( ) {
53
+ beforeEach ( function ( done ) {
54
+ var app = connect ( ) ;
55
+ app . use ( nosniff ( ) ) ;
56
+ app . use ( hello ( responseText ) ) ;
57
+ server = http . createServer ( app ) . listen ( 3000 , done ) ;
58
+ } ) ;
59
+ afterEach ( function ( ) {
60
+ server && server . close ( ) ;
61
+ } ) ;
31
62
it ( "should return response has `X-Content-Type-Options` header" , function ( ) {
32
63
return fetch ( "http://localhost:3000" )
33
64
. then ( res => {
0 commit comments