2323 * original author: dead_horse <dead_horse@qq.com>
2424 * ported by: yaycmyk <evan@yaycmyk.com>
2525 */
26+ 'use strict' ;
2627
27- jest . dontMock ( '../fastpath' ) ;
28+ jest . unmock ( '../fastpath' ) ;
2829
29- const fp = require ( '../fastpath' ) ;
30+ let fp ;
3031
3132describe ( 'fast-path' , ( ) => {
33+
3234 const actualPlatform = process . platform ;
3335 const invalidInputTests = [
3436 true ,
@@ -62,6 +64,7 @@ describe('fast-path', () => {
6264 it ( 'should resolve given paths' , ( ) => {
6365 process . platform = actualPlatform ;
6466
67+ fp = require ( '../fastpath' ) ;
6568 expect ( fp . basename ( __filename ) ) . toEqual ( 'fastpath-test.js' ) ;
6669 expect ( fp . basename ( __filename , '.js' ) ) . toEqual ( 'fastpath-test' ) ;
6770 expect ( fp . basename ( '' ) ) . toEqual ( '' ) ;
@@ -75,6 +78,7 @@ describe('fast-path', () => {
7578 it ( 'should handle backslashes properly (win32)' , ( ) => {
7679 process . platform = 'win32' ;
7780
81+ fp = require ( '../fastpath' ) ;
7882 expect ( fp . basename ( '\\dir\\basename.ext' ) ) . toEqual ( 'basename.ext' ) ;
7983 expect ( fp . basename ( '\\basename.ext' ) ) . toEqual ( 'basename.ext' ) ;
8084 expect ( fp . basename ( 'basename.ext' ) ) . toEqual ( 'basename.ext' ) ;
@@ -83,6 +87,7 @@ describe('fast-path', () => {
8387 } ) ;
8488
8589 it ( 'should handle backslashes properly (posix)' , ( ) => {
90+ fp = require ( '../fastpath' ) ;
8691 expect ( fp . basename ( '\\dir\\basename.ext' ) ) . toEqual ( '\\dir\\basename.ext' ) ;
8792 expect ( fp . basename ( '\\basename.ext' ) ) . toEqual ( '\\basename.ext' ) ;
8893 expect ( fp . basename ( 'basename.ext' ) ) . toEqual ( 'basename.ext' ) ;
@@ -91,6 +96,7 @@ describe('fast-path', () => {
9196 } ) ;
9297
9398 it ( 'should handle control characters (posix)' , ( ) => {
99+ fp = require ( '../fastpath' ) ;
94100 // POSIX filenames may include control characters
95101 // c.f. http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html
96102 const name = 'Icon' + String . fromCharCode ( 13 ) ;
@@ -102,6 +108,7 @@ describe('fast-path', () => {
102108 it ( 'should extract the extension from a path' , ( ) => {
103109 process . platform = actualPlatform ;
104110
111+ fp = require ( '../fastpath' ) ;
105112 expect ( fp . extname ( __filename ) ) . toEqual ( '.js' ) ;
106113 expect ( fp . extname ( '' ) ) . toEqual ( '' ) ;
107114 expect ( fp . extname ( '/path/to/file' ) ) . toEqual ( '' ) ;
@@ -149,6 +156,7 @@ describe('fast-path', () => {
149156 it ( 'should handle path backslashes (win32)' , ( ) => {
150157 process . platform = 'win32' ;
151158
159+ fp = require ( '../fastpath' ) ;
152160 // On windows, backspace is a path separator.
153161 expect ( fp . extname ( '.\\' ) ) . toEqual ( '' ) ;
154162 expect ( fp . extname ( '..\\' ) ) . toEqual ( '' ) ;
@@ -161,6 +169,8 @@ describe('fast-path', () => {
161169 } ) ;
162170
163171 it ( 'should handle path backslashes (posix)' , ( ) => {
172+ fp = require ( '../fastpath' ) ;
173+
164174 // On unix, backspace is a valid name component like any other character.
165175 expect ( fp . extname ( '.\\' ) ) . toEqual ( '' ) ;
166176 expect ( fp . extname ( '..\\' ) ) . toEqual ( '.\\' ) ;
@@ -175,6 +185,8 @@ describe('fast-path', () => {
175185
176186 describe ( 'dirname' , ( ) => {
177187 it ( 'should isolate the directory name from a path (posix)' , ( ) => {
188+ fp = require ( '../fastpath' ) ;
189+
178190 expect ( fp . dirname ( '/a/b/' ) ) . toEqual ( '/a' ) ;
179191 expect ( fp . dirname ( '/a/b' ) ) . toEqual ( '/a' ) ;
180192 expect ( fp . dirname ( '/a' ) ) . toEqual ( '/' ) ;
@@ -186,6 +198,7 @@ describe('fast-path', () => {
186198 it ( 'should isolate the directory name from a path (win32)' , ( ) => {
187199 process . platform = 'win32' ;
188200
201+ fp = require ( '../fastpath' ) ;
189202 expect ( fp . dirname ( 'C:\\' ) ) . toEqual ( 'C:\\' ) ;
190203 expect ( fp . dirname ( 'c:\\' ) ) . toEqual ( 'c:\\' ) ;
191204 expect ( fp . dirname ( 'c:\\foo' ) ) . toEqual ( 'c:\\' ) ;
@@ -314,6 +327,8 @@ describe('fast-path', () => {
314327 ] ) ;
315328
316329 it ( 'should join the paths correctly (posix)' , ( ) => {
330+ fp = require ( '../fastpath' ) ;
331+
317332 posixJoinTests . forEach ( test => {
318333 const actual = fp . join . apply ( fp , test [ 0 ] ) ;
319334 const expected = test [ 1 ] ;
@@ -329,6 +344,7 @@ describe('fast-path', () => {
329344 it ( 'should join the paths correctly (win32)' , ( ) => {
330345 process . platform = 'win32' ;
331346
347+ fp = require ( '../fastpath' ) ;
332348 win32JoinTests . forEach ( test => {
333349 const actual = fp . join . apply ( fp , test [ 0 ] ) ;
334350 const expected = test [ 1 ] . replace ( / \/ / g, '\\' ) ;
@@ -342,14 +358,18 @@ describe('fast-path', () => {
342358 } ) ;
343359
344360 it ( 'should throw for invalid input' , ( ) => {
361+ fp = require ( '../fastpath' ) ;
362+
345363 invalidInputTests . forEach ( test => {
346- expect ( ( ) => fp . jointest ) . toThrow ( ) ;
364+ expect ( ( ) => fp . join ( test ) ) . toThrow ( ) ;
347365 } ) ;
348366 } ) ;
349367 } ) ;
350368
351369 describe ( 'normalize' , ( ) => {
352370 it ( 'should return a valid path (posix)' , ( ) => {
371+ fp = require ( '../fastpath' ) ;
372+
353373 expect ( fp . normalize ( './fixtures///b/../b/c.js' ) ) . toEqual ( 'fixtures/b/c.js' ) ;
354374 expect ( fp . normalize ( '/foo/../../../bar' ) ) . toEqual ( '/bar' ) ;
355375 expect ( fp . normalize ( 'a//b//../b' ) ) . toEqual ( 'a/b' ) ;
@@ -359,6 +379,8 @@ describe('fast-path', () => {
359379
360380 it ( 'should return a valid path (win32)' , ( ) => {
361381 process . platform = 'win32' ;
382+
383+ fp = require ( '../fastpath' ) ;
362384 expect ( fp . normalize ( './fixtures///b/../b/c.js' ) ) . toEqual ( 'fixtures\\b\\c.js' ) ;
363385 expect ( fp . normalize ( '/foo/../../../bar' ) ) . toEqual ( '\\bar' ) ;
364386 expect ( fp . normalize ( 'a//b//../b' ) ) . toEqual ( 'a\\b' ) ;
@@ -394,13 +416,16 @@ describe('fast-path', () => {
394416 it ( 'should resolve the current working directory' , ( ) => {
395417 process . platform = actualPlatform ;
396418
419+ fp = require ( '../fastpath' ) ;
397420 const actual = fp . resolve ( '.' ) ;
398421 const expected = process . cwd ( ) ;
399422
400423 expect ( actual ) . toEqual ( expected , getErrorMessage ( 'resolve' , '.' , expected , actual ) ) ;
401424 } ) ;
402425
403426 it ( 'should resolve paths (posix)' , ( ) => {
427+ fp = require ( '../fastpath' ) ;
428+
404429 posixResolveTests . forEach ( test => {
405430 const actual = fp . resolve . apply ( fp , test [ 0 ] ) ;
406431 const expected = test [ 1 ] ;
@@ -412,6 +437,7 @@ describe('fast-path', () => {
412437 it ( 'should resolve paths (win32)' , ( ) => {
413438 process . platform = 'win32' ;
414439
440+ fp = require ( '../fastpath' ) ;
415441 win32ResolveTests . forEach ( test => {
416442 const actual = fp . resolve . apply ( fp , test [ 0 ] ) ;
417443 const expected = test [ 1 ] ;
@@ -421,14 +447,17 @@ describe('fast-path', () => {
421447 } ) ;
422448
423449 it ( 'should throw for invalid input' , ( ) => {
450+ fp = require ( '../fastpath' ) ;
424451 invalidInputTests . forEach ( test => {
425- expect ( ( ) => fp . resolvetest ) . toThrow ( ) ;
452+ expect ( ( ) => fp . resolve ( test ) ) . toThrow ( ) ;
426453 } ) ;
427454 } ) ;
428455 } ) ;
429456
430457 describe ( 'isAbsolute' , ( ) => {
431458 it ( 'should work (posix)' , ( ) => {
459+ fp = require ( '../fastpath' ) ;
460+
432461 expect ( fp . isAbsolute ( '/home/foo' ) ) . toEqual ( true ) ;
433462 expect ( fp . isAbsolute ( '/home/foo/..' ) ) . toEqual ( true ) ;
434463 expect ( fp . isAbsolute ( 'bar/' ) ) . toEqual ( false ) ;
@@ -437,6 +466,9 @@ describe('fast-path', () => {
437466
438467 it ( 'should work (win32)' , ( ) => {
439468 process . platform = 'win32' ;
469+
470+ fp = require ( '../fastpath' ) ;
471+
440472 expect ( fp . isAbsolute ( '//server/file' ) ) . toEqual ( true ) ;
441473 expect ( fp . isAbsolute ( '\\\\server\\file' ) ) . toEqual ( true ) ;
442474 expect ( fp . isAbsolute ( 'C:/Users/' ) ) . toEqual ( true ) ;
@@ -473,6 +505,7 @@ describe('fast-path', () => {
473505 ] ;
474506
475507 it ( 'should work (posix)' , ( ) => {
508+ fp = require ( '../fastpath' ) ;
476509 posixRelativeTests . forEach ( test => {
477510 const actual = fp . relative ( test [ 0 ] , test [ 1 ] ) ;
478511 const expected = test [ 2 ] ;
@@ -488,6 +521,7 @@ describe('fast-path', () => {
488521 it ( 'should work (win32)' , ( ) => {
489522 process . platform = 'win32' ;
490523
524+ fp = require ( '../fastpath' ) ;
491525 win32RelativeTests . forEach ( test => {
492526 const actual = fp . relative ( test [ 0 ] , test [ 1 ] ) ;
493527 const expected = test [ 2 ] ;
@@ -505,10 +539,12 @@ describe('fast-path', () => {
505539 it ( 'should be a backslash (win32)' , ( ) => {
506540 process . platform = 'win32' ;
507541
542+ fp = require ( '../fastpath' ) ;
508543 expect ( fp . sep ) . toEqual ( '\\' ) ;
509544 } ) ;
510545
511546 it ( 'should be a forward slash (posix)' , ( ) => {
547+ fp = require ( '../fastpath' ) ;
512548 expect ( fp . sep ) . toEqual ( '/' ) ;
513549 } ) ;
514550 } ) ;
@@ -517,10 +553,12 @@ describe('fast-path', () => {
517553 it ( 'should be a semicolon (win32)' , ( ) => {
518554 process . platform = 'win32' ;
519555
556+ fp = require ( '../fastpath' ) ;
520557 expect ( fp . delimiter ) . toEqual ( ';' ) ;
521558 } ) ;
522559
523560 it ( 'should be a colon (posix)' , ( ) => {
561+ fp = require ( '../fastpath' ) ;
524562 expect ( fp . delimiter ) . toEqual ( ':' ) ;
525563 } ) ;
526564 } ) ;
0 commit comments