@@ -6,115 +6,124 @@ const typescriptPaths = require('../dist').default;
6
6
7
7
const transform = ( path ) => path . replace ( / \. j s $ / i, '.cjs.js' ) ;
8
8
9
+ const tsConfigPath = process . env . WO_BASEURL
10
+ ? 'tsconfig-wo-baseurl.json'
11
+ : 'tsconfig.json'
12
+
9
13
const plugin = typescriptPaths ( {
10
- tsConfigPath : resolve ( __dirname , 'tsconfig.json' ) ,
14
+ tsConfigPath : resolve ( __dirname , tsConfigPath ) ,
11
15
} ) ;
12
16
13
17
const pluginNonAbs = typescriptPaths ( {
14
- tsConfigPath : resolve ( __dirname , 'tsconfig.json' ) ,
18
+ tsConfigPath : resolve ( __dirname , tsConfigPath ) ,
15
19
absolute : false ,
16
20
} ) ;
17
21
18
22
const pluginNonRelative = typescriptPaths ( {
19
- tsConfigPath : resolve ( __dirname , 'tsconfig.json' ) ,
23
+ tsConfigPath : resolve ( __dirname , tsConfigPath ) ,
20
24
nonRelative : true ,
21
25
} ) ;
22
26
23
27
const pluginTransform = typescriptPaths ( {
24
- tsConfigPath : resolve ( __dirname , 'tsconfig.json' ) ,
28
+ tsConfigPath : resolve ( __dirname , tsConfigPath ) ,
25
29
transform,
26
30
} ) ;
27
31
28
32
const pluginPreserveExtensions = typescriptPaths ( {
29
- tsConfigPath : resolve ( __dirname , 'tsconfig.json' ) ,
33
+ tsConfigPath : resolve ( __dirname , tsConfigPath ) ,
30
34
preserveExtensions : true ,
31
35
} ) ;
32
36
33
- try {
34
- // skips if module doesn't exist
35
- strictEqual ( plugin . resolveId ( 'foo/baz' , '' ) , null ) ;
36
-
37
- // skips if a matching path alias isn't found
38
- strictEqual ( plugin . resolveId ( '@asdf' , '' ) , null ) ;
39
-
40
- // skips if importee is a virtual module
41
- strictEqual ( plugin . resolveId ( '\0@foobar' , '' ) , null ) ;
42
-
43
- // resolves with non-wildcard paths
44
- strictEqual (
45
- plugin . resolveId ( '@foobar' , '' ) ,
46
- join ( __dirname , 'foo' , 'bar.js' ) ,
47
- ) ;
48
- strictEqual (
49
- plugin . resolveId ( '@foobar-react' , '' ) ,
50
- join ( __dirname , 'foo' , 'bar-react.js' ) ,
51
- ) ;
52
-
53
- // resolves with wildcard paths
54
- strictEqual (
55
- plugin . resolveId ( '@bar/foo' , '' ) ,
56
- join ( __dirname , 'bar' , 'foo.js' ) ,
57
- ) ;
58
-
59
- // resolves $/* paths
60
- strictEqual (
61
- plugin . resolveId ( '$/foo/bar' , '' ) ,
62
- join ( __dirname , 'foo' , 'bar.js' ) ,
63
- ) ;
64
-
65
- // resolves from a directory with index file
66
- strictEqual ( plugin . resolveId ( '@js' , '' ) , join ( __dirname , 'js' , 'index.js' ) ) ;
67
-
68
- // resolves without an `@` prefix
69
- strictEqual (
70
- plugin . resolveId ( 'bar/foo' , '' ) ,
71
- join ( __dirname , 'bar' , 'foo.js' ) ,
72
- ) ;
73
-
74
- // resolves with a different importer
75
- strictEqual (
76
- plugin . resolveId ( 'bar/foo' , join ( __dirname , 'foo' , 'bar.ts' ) ) ,
77
- join ( __dirname , 'bar' , 'foo.js' ) ,
78
- ) ;
79
-
80
- // doesn't accidentally resolve relative paths that also have an alias
81
- strictEqual (
82
- plugin . resolveId ( '../bar/foo' , join ( __dirname , 'foo' , 'bar.ts' ) ) ,
83
- null ,
84
- ) ;
85
-
86
- // skips non-relative paths unless enabled
87
- strictEqual ( plugin . resolveId ( 'foo/bar' , '' ) , null ) ;
88
37
89
- // resolves non-relative from baseUrl even if no path is matched
38
+ // skips if module doesn't exist
39
+ strictEqual ( plugin . resolveId ( 'foo/baz' , '' ) , null ) ;
40
+
41
+ // skips if a matching path alias isn't found
42
+ strictEqual ( plugin . resolveId ( '@asdf' , '' ) , null ) ;
43
+
44
+ // skips if importee is a virtual module
45
+ strictEqual ( plugin . resolveId ( '\0@foobar' , '' ) , null ) ;
46
+
47
+ // resolves with non-wildcard paths
48
+ strictEqual (
49
+ plugin . resolveId ( '@foobar' , '' ) ,
50
+ join ( __dirname , 'foo' , 'bar.js' ) ,
51
+ ) ;
52
+ strictEqual (
53
+ plugin . resolveId ( '@foobar-react' , '' ) ,
54
+ join ( __dirname , 'foo' , 'bar-react.js' ) ,
55
+ ) ;
56
+
57
+ // resolves with wildcard paths
58
+ strictEqual (
59
+ plugin . resolveId ( '@bar/foo' , '' ) ,
60
+ join ( __dirname , 'bar' , 'foo.js' ) ,
61
+ ) ;
62
+
63
+ // resolves $/* paths
64
+ strictEqual (
65
+ plugin . resolveId ( '$/foo/bar' , '' ) ,
66
+ join ( __dirname , 'foo' , 'bar.js' ) ,
67
+ ) ;
68
+
69
+ // resolves from a directory with index file
70
+ strictEqual ( plugin . resolveId ( '@js' , '' ) , join ( __dirname , 'js' , 'index.js' ) ) ;
71
+
72
+ // resolves without an `@` prefix
73
+ strictEqual (
74
+ plugin . resolveId ( 'bar/foo' , '' ) ,
75
+ join ( __dirname , 'bar' , 'foo.js' ) ,
76
+ ) ;
77
+
78
+ // resolves with a different importer
79
+ strictEqual (
80
+ plugin . resolveId ( 'bar/foo' , join ( __dirname , 'foo' , 'bar.ts' ) ) ,
81
+ join ( __dirname , 'bar' , 'foo.js' ) ,
82
+ ) ;
83
+
84
+ // doesn't accidentally resolve relative paths that also have an alias
85
+ strictEqual (
86
+ plugin . resolveId ( '../bar/foo' , join ( __dirname , 'foo' , 'bar.ts' ) ) ,
87
+ null ,
88
+ ) ;
89
+
90
+ // skips non-relative paths unless enabled
91
+ strictEqual ( plugin . resolveId ( 'foo/bar' , '' ) , null ) ;
92
+
93
+ // resolves non-relative from baseUrl even if no path is matched, baseUrl is necessary in config
94
+ if ( ! process . env . WO_BASEURL ) {
90
95
strictEqual (
91
96
pluginNonRelative . resolveId ( 'foo/bar' , '' ) ,
92
97
join ( __dirname , 'foo' , 'bar.js' ) ,
93
98
) ;
94
-
95
- // resolves as a relative path with option `absolute: false`
96
- strictEqual (
97
- pluginNonAbs . resolveId ( '@foobar' , '' ) ,
98
- join ( 'test' , 'foo' , 'bar.js' ) ,
99
- ) ;
100
-
101
- // applies function from `transform` option
102
- strictEqual (
103
- pluginTransform . resolveId ( '@foobar' , '' ) ,
104
- join ( __dirname , 'foo' , 'bar.cjs.js' ) ,
105
- ) ;
106
-
107
- // resolves including the file extension with option `preserveExtensions: true`
108
- strictEqual (
109
- pluginPreserveExtensions . resolveId ( '@foobar' , '' ) ,
110
- join ( __dirname , 'foo' , 'bar.ts' ) ,
111
- ) ;
112
- strictEqual (
113
- pluginPreserveExtensions . resolveId ( '@foobar-react' , '' ) ,
114
- join ( __dirname , 'foo' , 'bar-react.tsx' ) ,
115
- ) ;
116
-
117
- console . log ( 'PASSED' ) ;
118
- } catch ( error ) {
119
- throw error ;
99
+ } else {
100
+ console . log (
101
+ 'SKIP test forced nonRelative paths:\n' ,
102
+ '- Irrelevant since baseUrl is not provided in this case\n' ,
103
+ '- See WO_BASEURL environment variable in the test code'
104
+ )
120
105
}
106
+
107
+ // resolves as a relative path with option `absolute: false`
108
+ strictEqual (
109
+ pluginNonAbs . resolveId ( '@foobar' , '' ) ,
110
+ join ( 'test' , 'foo' , 'bar.js' ) ,
111
+ ) ;
112
+
113
+ // applies function from `transform` option
114
+ strictEqual (
115
+ pluginTransform . resolveId ( '@foobar' , '' ) ,
116
+ join ( __dirname , 'foo' , 'bar.cjs.js' ) ,
117
+ ) ;
118
+
119
+ // resolves including the file extension with option `preserveExtensions: true`
120
+ strictEqual (
121
+ pluginPreserveExtensions . resolveId ( '@foobar' , '' ) ,
122
+ join ( __dirname , 'foo' , 'bar.ts' ) ,
123
+ ) ;
124
+ strictEqual (
125
+ pluginPreserveExtensions . resolveId ( '@foobar-react' , '' ) ,
126
+ join ( __dirname , 'foo' , 'bar-react.tsx' ) ,
127
+ ) ;
128
+
129
+ console . log ( 'PASSED' ) ;
0 commit comments