@@ -3,7 +3,7 @@ const sinon = require('sinon');
3
3
const Promise = require ( 'bluebird' ) ;
4
4
const fs = require ( 'fs' ) ;
5
5
const { join, resolve } = require ( 'path' ) ;
6
- const createHandler = require ( '../../lib/handler' ) ;
6
+ const subject = require ( '../../lib/handler' ) ;
7
7
8
8
describe ( 'handler' , ( ) => {
9
9
let sandbox ;
@@ -27,17 +27,20 @@ describe('handler', () => {
27
27
mockFiles = [ ] ;
28
28
} ) ;
29
29
30
- // Create a handler with the specified options and call it with the given URL
31
- function handlerExec ( url , options = { } ) {
32
- return new Promise ( ( resolve , reject ) => {
33
- let handler = createHandler ( Object . assign ( {
34
- cwd : '. ' ,
35
- name : 'serve ' ,
36
- endpoint : 'dist ' ,
37
- directoryIndexFile : 'index.html' ,
38
- indexPath : undefined ,
39
- } , options ) ) ;
30
+ // Create a handler with the specified options
31
+ function createHandler ( options ) {
32
+ return subject ( Object . assign ( {
33
+ cwd : '.' ,
34
+ name : 'serve ' ,
35
+ endpoint : 'dist ' ,
36
+ directoryIndexFile : 'index.html ' ,
37
+ indexPath : undefined ,
38
+ } , options ) ) ;
39
+ }
40
40
41
+ // Call the handler with the given URL
42
+ function callHandler ( handler , url ) {
43
+ return new Promise ( ( resolve , reject ) => {
41
44
handler ( { url } , ( { path, error } ) => {
42
45
if ( path !== undefined ) {
43
46
resolve ( path ) ;
@@ -48,13 +51,32 @@ describe('handler', () => {
48
51
} ) ;
49
52
}
50
53
54
+ // Create a handler with the specified options and call it with the given URL
55
+ function handlerExec ( url , options = { } ) {
56
+ return callHandler ( createHandler ( options ) , url ) ;
57
+ }
58
+
51
59
it ( 'works' , ( ) => {
52
60
mockFiles . push ( 'script.js' ) ;
53
61
return handlerExec ( 'serve://dist/script.js' ) . then ( path => {
54
62
assert . equal ( path , 'script.js' ) ;
55
63
} ) ;
56
64
} ) ;
57
65
66
+ it ( 'works with multiple requests' , ( ) => {
67
+ mockFiles . push ( 'script1.js' ) ;
68
+ mockFiles . push ( 'script2.js' ) ;
69
+
70
+ let handler = createHandler ( ) ;
71
+ return callHandler ( handler , 'serve://dist/script1.js' ) . then ( path => {
72
+ assert . equal ( path , 'script1.js' ) ;
73
+
74
+ return callHandler ( handler , 'serve://dist/script2.js' ) ;
75
+ } ) . then ( path => {
76
+ assert . equal ( path , 'script2.js' ) ;
77
+ } ) ;
78
+ } ) ;
79
+
58
80
it ( 'serves directoryIndexFile from the root' , ( ) => {
59
81
mockFiles . push ( 'foo.html' ) ;
60
82
return handlerExec ( 'serve://dist' , {
0 commit comments