1
1
2
- var express = require ( '../' )
3
- , assert = require ( 'assert ' ) ;
2
+ var assert = require ( 'assert' ) ;
3
+ var express = require ( '.. ' ) ;
4
4
5
- describe ( 'config' , function ( ) {
6
- describe ( '.set()' , function ( ) {
7
- it ( 'should set a value' , function ( ) {
5
+ describe ( 'config' , function ( ) {
6
+ describe ( '.set()' , function ( ) {
7
+ it ( 'should set a value' , function ( ) {
8
8
var app = express ( ) ;
9
- app . set ( 'foo' , 'bar' ) . should . equal ( app ) ;
9
+ app . set ( 'foo' , 'bar' ) ;
10
+ assert . equal ( app . get ( 'foo' ) , 'bar' ) ;
11
+ } )
12
+
13
+ it ( 'should return the app' , function ( ) {
14
+ var app = express ( ) ;
15
+ assert . equal ( app . set ( 'foo' , 'bar' ) , app ) ;
10
16
} )
11
17
12
- it ( 'should return the app when undefined' , function ( ) {
18
+ it ( 'should return the app when undefined' , function ( ) {
13
19
var app = express ( ) ;
14
- app . set ( 'foo' , undefined ) . should . equal ( app ) ;
20
+ assert . equal ( app . set ( 'foo' , undefined ) , app ) ;
15
21
} )
16
22
17
23
describe ( '"etag"' , function ( ) {
18
24
it ( 'should throw on bad value' , function ( ) {
19
- var app = express ( )
20
- app . set . bind ( app , 'etag' , 42 ) . should . throw ( / u n k n o w n v a l u e / )
25
+ var app = express ( ) ;
26
+ assert . throws ( app . set . bind ( app , 'etag' , 42 ) , / u n k n o w n v a l u e / ) ;
21
27
} )
22
28
23
29
it ( 'should set "etag fn"' , function ( ) {
24
30
var app = express ( )
25
31
var fn = function ( ) { }
26
32
app . set ( 'etag' , fn )
27
- app . get ( 'etag fn' ) . should . equal ( fn )
33
+ assert . equal ( app . get ( 'etag fn' ) , fn )
28
34
} )
29
35
} )
30
36
@@ -33,85 +39,124 @@ describe('config', function(){
33
39
var app = express ( )
34
40
var fn = function ( ) { }
35
41
app . set ( 'trust proxy' , fn )
36
- app . get ( 'trust proxy fn' ) . should . equal ( fn )
42
+ assert . equal ( app . get ( 'trust proxy fn' ) , fn )
37
43
} )
38
44
} )
39
45
} )
40
46
41
47
describe ( '.get()' , function ( ) {
42
48
it ( 'should return undefined when unset' , function ( ) {
43
49
var app = express ( ) ;
44
- assert ( undefined === app . get ( 'foo' ) ) ;
50
+ assert . strictEqual ( app . get ( 'foo' ) , undefined ) ;
45
51
} )
46
52
47
53
it ( 'should otherwise return the value' , function ( ) {
48
54
var app = express ( ) ;
49
55
app . set ( 'foo' , 'bar' ) ;
50
- app . get ( 'foo' ) . should . equal ( 'bar' ) ;
56
+ assert . equal ( app . get ( 'foo' ) , 'bar' ) ;
51
57
} )
52
58
53
59
describe ( 'when mounted' , function ( ) {
54
60
it ( 'should default to the parent app' , function ( ) {
55
- var app = express ( )
56
- , blog = express ( ) ;
61
+ var app = express ( ) ;
62
+ var blog = express ( ) ;
57
63
58
64
app . set ( 'title' , 'Express' ) ;
59
65
app . use ( blog ) ;
60
- blog . get ( 'title' ) . should . equal ( 'Express' ) ;
66
+ assert . equal ( blog . get ( 'title' ) , 'Express' ) ;
61
67
} )
62
-
68
+
63
69
it ( 'should given precedence to the child' , function ( ) {
64
- var app = express ( )
65
- , blog = express ( ) ;
70
+ var app = express ( ) ;
71
+ var blog = express ( ) ;
66
72
67
73
app . use ( blog ) ;
68
74
app . set ( 'title' , 'Express' ) ;
69
75
blog . set ( 'title' , 'Some Blog' ) ;
70
76
71
- blog . get ( 'title' ) . should . equal ( 'Some Blog' ) ;
77
+ assert . equal ( blog . get ( 'title' ) , 'Some Blog' ) ;
78
+ } )
79
+
80
+ it ( 'should inherit "trust proxy" setting' , function ( ) {
81
+ var app = express ( ) ;
82
+ var blog = express ( ) ;
83
+
84
+ function fn ( ) { return false }
85
+
86
+ app . set ( 'trust proxy' , fn ) ;
87
+ assert . equal ( app . get ( 'trust proxy' ) , fn ) ;
88
+ assert . equal ( app . get ( 'trust proxy fn' ) , fn ) ;
89
+
90
+ app . use ( blog ) ;
91
+
92
+ assert . equal ( blog . get ( 'trust proxy' ) , fn ) ;
93
+ assert . equal ( blog . get ( 'trust proxy fn' ) , fn ) ;
94
+ } )
95
+
96
+ it ( 'should prefer child "trust proxy" setting' , function ( ) {
97
+ var app = express ( ) ;
98
+ var blog = express ( ) ;
99
+
100
+ function fn1 ( ) { return false }
101
+ function fn2 ( ) { return true }
102
+
103
+ app . set ( 'trust proxy' , fn1 ) ;
104
+ assert . equal ( app . get ( 'trust proxy' ) , fn1 ) ;
105
+ assert . equal ( app . get ( 'trust proxy fn' ) , fn1 ) ;
106
+
107
+ blog . set ( 'trust proxy' , fn2 ) ;
108
+ assert . equal ( blog . get ( 'trust proxy' ) , fn2 ) ;
109
+ assert . equal ( blog . get ( 'trust proxy fn' ) , fn2 ) ;
110
+
111
+ app . use ( blog ) ;
112
+
113
+ assert . equal ( app . get ( 'trust proxy' ) , fn1 ) ;
114
+ assert . equal ( app . get ( 'trust proxy fn' ) , fn1 ) ;
115
+ assert . equal ( blog . get ( 'trust proxy' ) , fn2 ) ;
116
+ assert . equal ( blog . get ( 'trust proxy fn' ) , fn2 ) ;
72
117
} )
73
118
} )
74
119
} )
75
120
76
121
describe ( '.enable()' , function ( ) {
77
122
it ( 'should set the value to true' , function ( ) {
78
123
var app = express ( ) ;
79
- app . enable ( 'tobi' ) . should . equal ( app ) ;
80
- app . get ( 'tobi' ) . should . be . true ;
124
+ assert . equal ( app . enable ( 'tobi' ) , app ) ;
125
+ assert . strictEqual ( app . get ( 'tobi' ) , true ) ;
81
126
} )
82
127
} )
83
128
84
129
describe ( '.disable()' , function ( ) {
85
130
it ( 'should set the value to false' , function ( ) {
86
131
var app = express ( ) ;
87
- app . disable ( 'tobi' ) . should . equal ( app ) ;
88
- app . get ( 'tobi' ) . should . be . false ;
132
+ assert . equal ( app . disable ( 'tobi' ) , app ) ;
133
+ assert . strictEqual ( app . get ( 'tobi' ) , false ) ;
89
134
} )
90
135
} )
91
136
92
137
describe ( '.enabled()' , function ( ) {
93
138
it ( 'should default to false' , function ( ) {
94
139
var app = express ( ) ;
95
- app . enabled ( 'foo' ) . should . be . false ;
140
+ assert . strictEqual ( app . enabled ( 'foo' ) , false ) ;
96
141
} )
97
142
98
143
it ( 'should return true when set' , function ( ) {
99
144
var app = express ( ) ;
100
145
app . set ( 'foo' , 'bar' ) ;
101
- app . enabled ( 'foo' ) . should . be . true ;
146
+ assert . strictEqual ( app . enabled ( 'foo' ) , true ) ;
102
147
} )
103
148
} )
104
149
105
150
describe ( '.disabled()' , function ( ) {
106
151
it ( 'should default to true' , function ( ) {
107
152
var app = express ( ) ;
108
- app . disabled ( 'foo' ) . should . be . true ;
153
+ assert . strictEqual ( app . disabled ( 'foo' ) , true ) ;
109
154
} )
110
155
111
156
it ( 'should return false when set' , function ( ) {
112
157
var app = express ( ) ;
113
158
app . set ( 'foo' , 'bar' ) ;
114
- app . disabled ( 'foo' ) . should . be . false ;
159
+ assert . strictEqual ( app . disabled ( 'foo' ) , false ) ;
115
160
} )
116
161
} )
117
162
} )
0 commit comments