@@ -67,6 +67,133 @@ describe('node-static (CLI)', function () {
6767 assert . equal ( text , 'hello world' , 'should respond with hello world' ) ;
6868 } ) ;
6969
70+ it ( 'serving file within directory with server info' , async function ( ) {
71+ const { response /* , stdout */ } =
72+ /**
73+ * @type {{
74+ * response: Response,
75+ * stdout: string
76+ * }}
77+ */ ( await spawnConditional (
78+ binFile ,
79+ [
80+ '-p' , this . port , fixturePath ,
81+ '--server-info' , 'my-server'
82+ ] ,
83+ timeout - 9000 ,
84+ {
85+ condition : / s e r v i n g " .* ?" / ,
86+ action : ( /* err, stdout */ ) => {
87+ return fetch (
88+ `http://localhost:${ this . port } /hello.txt`
89+ ) ;
90+ }
91+ } ) ) ;
92+
93+ const { status} = response ;
94+ const contentType = response . headers . get ( 'content-type' ) ;
95+ const server = response . headers . get ( 'server' ) ;
96+ const text = await response . text ( ) ;
97+
98+ assert . equal ( status , 200 , 'should respond with 200' ) ;
99+ assert . equal ( contentType , 'text/plain' , 'should respond with text/plain' ) ;
100+ assert . equal ( server , 'my-server' , 'should respond with my-server' )
101+ assert . equal ( text , 'hello world' , 'should respond with hello world' ) ;
102+ } ) ;
103+
104+ it ( 'serving file within directory with default extension' , async function ( ) {
105+ const { response /* , stdout */ } =
106+ /**
107+ * @type {{
108+ * response: Response,
109+ * stdout: string
110+ * }}
111+ */ ( await spawnConditional (
112+ binFile ,
113+ [
114+ '-p' , this . port , fixturePath ,
115+ '--default-extension' , 'txt'
116+ ] ,
117+ timeout - 9000 ,
118+ {
119+ condition : / s e r v i n g " .* ?" / ,
120+ action : ( /* err, stdout */ ) => {
121+ return fetch (
122+ `http://localhost:${ this . port } /hello`
123+ ) ;
124+ }
125+ } ) ) ;
126+
127+ const { status} = response ;
128+ const contentType = response . headers . get ( 'content-type' ) ;
129+ const text = await response . text ( ) ;
130+
131+ assert . equal ( status , 200 , 'should respond with 200' ) ;
132+ assert . equal ( contentType , 'text/plain' , 'should respond with text/plain' ) ;
133+ assert . equal ( text , 'hello world' , 'should respond with hello world' ) ;
134+ } ) ;
135+
136+ it ( 'serving file within directory with hidden extension' , async function ( ) {
137+ const { response /* , stdout */ } =
138+ /**
139+ * @type {{
140+ * response: Response,
141+ * stdout: string
142+ * }}
143+ */ ( await spawnConditional (
144+ binFile ,
145+ [
146+ '-p' , this . port , fixturePath ,
147+ '--serve-hidden'
148+ ] ,
149+ timeout - 9000 ,
150+ {
151+ condition : / s e r v i n g " .* ?" / ,
152+ action : ( /* err, stdout */ ) => {
153+ return fetch (
154+ `http://localhost:${ this . port } /.hidden-hello.txt`
155+ ) ;
156+ }
157+ } ) ) ;
158+
159+ const { status} = response ;
160+ const contentType = response . headers . get ( 'content-type' ) ;
161+ const text = await response . text ( ) ;
162+
163+ assert . equal ( status , 200 , 'should respond with 200' ) ;
164+ assert . equal ( contentType , 'text/plain' , 'should respond with text/plain' ) ;
165+ assert . equal ( text , 'hello world' , 'should respond with hello world' ) ;
166+ } ) ;
167+
168+ it ( 'serving 404 for file with hidden extension' , async function ( ) {
169+ const { response /* , stdout */ } =
170+ /**
171+ * @type {{
172+ * response: Response,
173+ * stdout: string
174+ * }}
175+ */ ( await spawnConditional (
176+ binFile ,
177+ [
178+ '-p' , this . port , fixturePath
179+ ] ,
180+ timeout - 9000 ,
181+ {
182+ condition : / s e r v i n g " .* ?" / ,
183+ action : ( /* err, stdout */ ) => {
184+ return fetch (
185+ `http://localhost:${ this . port } /.hidden-hello.txt`
186+ ) ;
187+ }
188+ } ) ) ;
189+
190+ const { status} = response ;
191+ const text = await response . text ( ) ;
192+
193+ assert . equal ( status , 404 , 'should respond with 404' ) ;
194+ assert . equal ( text , 'Not Found' , 'should respond with Not Found' ) ;
195+ } ) ;
196+
70197 it ( 'serving file without directory' , async function ( ) {
71198 const { response /* , stdout */ } =
72199 /**
0 commit comments