@@ -25,6 +25,13 @@ describe('findScriptFromPartialPath', function () {
25
25
// Test case for when there's multiple partial matches
26
26
listener ( { params : { scriptId : 'should-match' , url : 'file:///server/index.js' } } )
27
27
listener ( { params : { scriptId : 'should-not-match' , url : 'file:///index.js' } } )
28
+
29
+ // Test case for when there's two equal length partial matches
30
+ listener ( { params : { scriptId : 'should-not-match-longest-a' , url : 'file:///node_modules/foo/index.js' } } )
31
+ listener ( { params : { scriptId : 'should-match-shortest-a' , url : 'file:///foo/index.js' } } )
32
+ // The same, but in reverse order to ensure this doesn't influence the result
33
+ listener ( { params : { scriptId : 'should-match-shortest-b' , url : 'file:///bar/index.js' } } )
34
+ listener ( { params : { scriptId : 'should-not-match-longest-b' , url : 'file:///node_modules/bar/index.js' } } )
28
35
}
29
36
}
30
37
}
@@ -117,14 +124,30 @@ describe('findScriptFromPartialPath', function () {
117
124
const result = state . findScriptFromPartialPath ( 'server/index.js' )
118
125
expect ( result ) . to . deep . equal ( [ 'file:///server/index.js' , 'should-match' , undefined ] )
119
126
} )
127
+
128
+ it ( 'should match the shorter of two equal length partial matches' , function ( ) {
129
+ const result1 = state . findScriptFromPartialPath ( 'foo/index.js' )
130
+ expect ( result1 ) . to . deep . equal ( [ 'file:///foo/index.js' , 'should-match-shortest-a' , undefined ] )
131
+
132
+ const result2 = state . findScriptFromPartialPath ( 'bar/index.js' )
133
+ expect ( result2 ) . to . deep . equal ( [ 'file:///bar/index.js' , 'should-match-shortest-b' , undefined ] )
134
+ } )
120
135
} )
121
136
122
- describe ( 'circuit breakers' , function ( ) {
123
- it ( 'should abort if the path is unknown' , testPathNoMatch ( 'this/path/does/not/exist.js' ) )
137
+ describe ( 'should abort if the path is' , function ( ) {
138
+ it ( 'unknown' , testPathNoMatch ( 'this/path/does/not/exist.js' ) )
139
+
140
+ it ( 'undefined' , testPathNoMatch ( undefined ) )
141
+
142
+ it ( 'an empty string' , testPathNoMatch ( '' ) )
143
+
144
+ it ( 'a slash' , testPathNoMatch ( '/' ) )
145
+
146
+ it ( 'a backslash' , testPathNoMatch ( '\\' ) )
124
147
125
- it ( 'should abort if the path is undefined ' , testPathNoMatch ( undefined ) )
148
+ it ( 'a Windows drive letter ' , testPathNoMatch ( 'c:' ) )
126
149
127
- it ( 'should abort if the path is an empty string ' , testPathNoMatch ( '' ) )
150
+ it ( 'a Windows drive letter with a backslash ' , testPathNoMatch ( 'c:\\ ' ) )
128
151
} )
129
152
130
153
function testPathNoMatch ( path ) {
0 commit comments