4
4
*/
5
5
'use strict' ;
6
6
7
- const { resolve} = require ( 'path' ) ;
7
+ const { resolve, sep} = require ( 'path' ) ;
8
+ const { platform} = require ( 'os' ) ;
8
9
const tape = require ( 'blue-tape' ) ;
9
10
const sinon = require ( 'sinon' ) ;
10
11
const outdent = require ( 'outdent' ) ;
@@ -17,6 +18,15 @@ const json = (strings, ...substitutions) =>
17
18
...substitutions . map ( v => JSON . stringify ( v , ( _ , vv ) => Number . isNaN ( vv ) ? 'NaN' : vv ) )
18
19
) ;
19
20
21
+ const cwd = ( ...args ) =>
22
+ resolve ( ...String . raw ( ...args ) . split ( '/' ) ) ;
23
+
24
+ const root = ( ...args ) =>
25
+ resolve (
26
+ platform ( ) === 'win32' ? ( process . cwd ( ) . split ( sep ) . shift ( ) + sep ) : sep ,
27
+ ...String . raw ( ...args ) . split ( '/' )
28
+ ) ;
29
+
20
30
tape (
21
31
'debug' ,
22
32
( { name, test, end : end1 , equal, looseEqual} ) => {
@@ -25,16 +35,16 @@ tape(
25
35
// absolute within cwd
26
36
[
27
37
[
28
- resolve ( ' my-source-file.js' ) ,
38
+ cwd ` my-source-file.js` ,
29
39
'my-asset.png' ,
30
40
[
31
41
{
32
- base : resolve ( ' foo' ) ,
33
- joined : resolve ( ' foo' , ' my-asset.png' ) ,
42
+ base : cwd ` foo` ,
43
+ joined : cwd ` foo/ my-asset.png` ,
34
44
isSuccess : false
35
45
} , {
36
- base : resolve ( ' bar' , ' baz' ) ,
37
- joined : resolve ( ' bar' , ' baz' , ' my-asset.png' ) ,
46
+ base : cwd ` bar/ baz` ,
47
+ joined : cwd ` bar/ baz/ my-asset.png` ,
38
48
isSuccess : true
39
49
}
40
50
]
@@ -49,24 +59,24 @@ tape(
49
59
// absolute otherwise
50
60
[
51
61
[
52
- '/ my-source-file.js' ,
53
- '#anything\\ ./goes' ,
62
+ root ` my-source-file.js` ,
63
+ '#anything@ ./goes' ,
54
64
[
55
65
{
56
- base : '/ foo' ,
57
- joined : '/ foo/#anything\\ ./goes' ,
66
+ base : root ` foo` ,
67
+ joined : root ` foo/#anything@ ./goes` ,
58
68
isSuccess : false
59
69
} , {
60
- base : '/ bar/baz' ,
61
- joined : '/ bar/baz/#anything\\ ./goes' ,
70
+ base : root ` bar/baz` ,
71
+ joined : root ` bar/baz/#anything@ ./goes` ,
62
72
isSuccess : false
63
73
}
64
74
]
65
75
] ,
66
76
outdent `
67
- resolve-url-loader: /my-source-file.js: #anything\\ ./goes
68
- /foo --> /foo/#anything\\ ./goes
69
- /bar/baz --> /bar/baz/#anything\\ ./goes
77
+ resolve-url-loader: /my-source-file.js: #anything@ ./goes
78
+ /foo --> /foo/#anything@ ./goes
79
+ /bar/baz --> /bar/baz/#anything@ ./goes
70
80
NOT FOUND
71
81
`
72
82
] ,
0 commit comments