@@ -5,6 +5,8 @@ const ecstatic = require('../lib/core');
55const http = require ( 'http' ) ;
66const request = require ( 'request' ) ;
77const eol = require ( 'eol' ) ;
8+ const fs = require ( 'fs' ) ;
9+ const path = require ( 'path' ) ;
810
911test ( 'range' , ( t ) => {
1012 t . plan ( 4 ) ;
@@ -51,6 +53,9 @@ test('range starts beyond the end', (t) => {
5153 const server = http . createServer ( ecstatic ( `${ __dirname } /public/subdir` ) ) ;
5254 t . on ( 'end' , ( ) => { server . close ( ) ; } ) ;
5355
56+ const filePath = path . join ( __dirname , 'public/subdir/e.html' ) ;
57+ const fileSize = fs . statSync ( filePath ) . size ;
58+
5459 server . listen ( 0 , ( ) => {
5560 const port = server . address ( ) . port ;
5661 const opts = {
@@ -60,7 +65,7 @@ test('range starts beyond the end', (t) => {
6065 request . get ( opts , ( err , res , body ) => {
6166 t . error ( err ) ;
6267 t . equal ( res . statusCode , 416 , 'range error status code' ) ;
63- t . equal ( res . headers [ 'content-range' ] , ' bytes */11' ) ;
68+ t . equal ( res . headers [ 'content-range' ] , ` bytes */${ fileSize } ` ) ;
6469 t . equal ( body , 'Requested range not satisfiable' ) ;
6570 } ) ;
6671 } ) ;
@@ -71,6 +76,9 @@ test('NaN range', (t) => {
7176 const server = http . createServer ( ecstatic ( `${ __dirname } /public/subdir` ) ) ;
7277 t . on ( 'end' , ( ) => { server . close ( ) ; } ) ;
7378
79+ const filePath = path . join ( __dirname , 'public/subdir/e.html' ) ;
80+ const fileSize = fs . statSync ( filePath ) . size ;
81+
7482 server . listen ( 0 , ( ) => {
7583 const port = server . address ( ) . port ;
7684 const opts = {
@@ -80,7 +88,7 @@ test('NaN range', (t) => {
8088 request . get ( opts , ( err , res , body ) => {
8189 t . error ( err ) ;
8290 t . equal ( res . statusCode , 416 , 'range error status code' ) ;
83- t . equal ( res . headers [ 'content-range' ] , ' bytes */11' ) ;
91+ t . equal ( res . headers [ 'content-range' ] , ` bytes */${ fileSize } ` ) ;
8492 t . equal ( body , 'Requested range not satisfiable' ) ;
8593 } ) ;
8694 } ) ;
@@ -91,6 +99,9 @@ test('flipped range', (t) => {
9199 const server = http . createServer ( ecstatic ( `${ __dirname } /public/subdir` ) ) ;
92100 t . on ( 'end' , ( ) => { server . close ( ) ; } ) ;
93101
102+ const filePath = path . join ( __dirname , 'public/subdir/e.html' ) ;
103+ const fileSize = fs . statSync ( filePath ) . size ;
104+
94105 server . listen ( 0 , ( ) => {
95106 const port = server . address ( ) . port ;
96107 const opts = {
@@ -100,7 +111,7 @@ test('flipped range', (t) => {
100111 request . get ( opts , ( err , res , body ) => {
101112 t . error ( err ) ;
102113 t . equal ( res . statusCode , 416 , 'range error status code' ) ;
103- t . equal ( res . headers [ 'content-range' ] , ' bytes */11' ) ;
114+ t . equal ( res . headers [ 'content-range' ] , ` bytes */${ fileSize } ` ) ;
104115 t . equal ( body , 'Requested range not satisfiable' ) ;
105116 } ) ;
106117 } ) ;
0 commit comments