@@ -25,22 +25,69 @@ describe("Resolver Plugin Tests", () => {
25
25
extensions : [ ".js" ] ,
26
26
alias : {
27
27
"_" : "/path/to/src" ,
28
+ "@" : "assets/images" ,
28
29
} ,
29
30
} ,
30
31
} ,
31
32
} ) , { virtual : true } ) ;
32
33
33
34
// JS module
34
- let result = resolver . resolve ( "_/module" , "/path/to/file.js" , { configPath : "/path/to/vite.config.js" } ) ;
35
+ let result = resolver . resolve ( "_/@/_module@" , "/path/to/file.js" , { configPath : "/path/to/vite.config.js" } ) ;
36
+
37
+ expect ( result . found ) . toBe ( true ) ;
38
+ expect ( result . path ) . toBe ( "/path/to/resolved.js" ) ;
39
+ expect ( resolve . sync ) . toHaveBeenCalledWith (
40
+ "/path/to/src/assets/images/_module@" ,
41
+ { basedir : "/path/to" , extensions : [ ".js" ] }
42
+ ) ;
43
+ } ) ;
44
+
45
+ test ( "should resolve non-core module (array alias pairs)" , ( ) => {
46
+ resolve . sync = jest . fn ( ( ) => "/path/to/resolved.js" ) ;
47
+ fs . existsSync = jest . fn ( ( ) => true ) ;
48
+
49
+ jest . mock ( "/path/to/vite.config.js" , ( ) => ( {
50
+ default : {
51
+ resolve : {
52
+ extensions : [ ".js" ] ,
53
+ alias : [
54
+ { find : "_" , replacement : "/path/to/src" } ,
55
+ { find : "@" , replacement : "assets/images" } ,
56
+ ] ,
57
+ } ,
58
+ } ,
59
+ } ) , { virtual : true } ) ;
60
+
61
+ // JS module
62
+ let result = resolver . resolve ( "_/@/_module@" , "/path/to/file.js" , { configPath : "/path/to/vite.config.js" } ) ;
35
63
36
64
expect ( result . found ) . toBe ( true ) ;
37
65
expect ( result . path ) . toBe ( "/path/to/resolved.js" ) ;
38
66
expect ( resolve . sync ) . toHaveBeenCalledWith (
39
- "/path/to/src/module " ,
67
+ "/path/to/src/assets/images/_module@ " ,
40
68
{ basedir : "/path/to" , extensions : [ ".js" ] }
41
69
) ;
42
70
} ) ;
43
71
72
+ test ( "should throw error when alias type is invalid" , ( ) => {
73
+ resolve . sync = jest . fn ( ( ) => "/path/to/resolved.js" ) ;
74
+ fs . existsSync = jest . fn ( ( ) => true ) ;
75
+
76
+ jest . mock ( "/path/to/vite.config.js" , ( ) => ( {
77
+ default : {
78
+ resolve : {
79
+ extensions : [ ".js" ] ,
80
+ alias : "test" ,
81
+ } ,
82
+ } ,
83
+ } ) , { virtual : true } ) ;
84
+
85
+ // JS module
86
+ let result = resolver . resolve ( "_/module" , "/path/to/file.js" , { configPath : "/path/to/vite.config.js" } ) ;
87
+
88
+ expect ( result . found ) . toBe ( false ) ;
89
+ } ) ;
90
+
44
91
test ( "should resolve non-core module with publicDir" , ( ) => {
45
92
resolve . sync = jest . fn ( ( ) => "/path/to/resolved.js" ) ;
46
93
fs . existsSync = jest . fn ( ( param ) => {
0 commit comments