@@ -191,7 +191,7 @@ describe('createImportResolver', () => {
191191 } )
192192} )
193193
194- describe ( 'resolveInternalSpecifier ' , ( ) => {
194+ describe ( 'resolveInternalImport ' , ( ) => {
195195 it ( 'resolves exact imports map matches to files in the package' , ( ) => {
196196 const files = new Set < string > ( [ 'dist/app/nuxt.js' ] )
197197
@@ -238,17 +238,62 @@ describe('resolveInternalSpecifier', () => {
238238 } )
239239
240240 it ( 'resolves prefix matches with extension resolution via guessInternalImportTarget' , ( ) => {
241- const files = new Set < string > ( [ 'dist/app/nuxt .js' ] )
241+ const files = new Set < string > ( [ 'dist/app/components/button .js' ] )
242242
243243 const resolved = resolveInternalImport (
244- '#app/nuxt ' ,
244+ '#app/components/button.js ' ,
245245 'dist/index.js' ,
246246 {
247247 '#app' : './dist/app/index.js' ,
248248 } ,
249249 files ,
250250 )
251251
252- expect ( resolved ?. path ) . toBe ( 'dist/app/nuxt.js' )
252+ expect ( resolved ?. path ) . toBe ( 'dist/app/components/button.js' )
253+ } )
254+
255+ it ( 'resolves file that could not found in the files' , ( ) => {
256+ const files = new Set < string > ( [ 'dist/app/index.js' ] )
257+
258+ const resolved = resolveInternalImport (
259+ '#app/components/button.js' ,
260+ 'dist/index.js' ,
261+ {
262+ '#app' : './dist/app/index.js' ,
263+ } ,
264+ files ,
265+ )
266+
267+ expect ( resolved ) . toBeNull ( )
268+ } )
269+
270+ it ( 'resolves file that prefix is "~/"' , ( ) => {
271+ const files = new Set < string > ( [ 'dist/app/components/button.js' ] )
272+
273+ const resolved = resolveInternalImport (
274+ '~/app/components/button.js' ,
275+ 'dist/index.js' ,
276+ {
277+ '~/app' : './dist/app/index.js' ,
278+ } ,
279+ files ,
280+ )
281+
282+ expect ( resolved ?. path ) . toBe ( 'dist/app/components/button.js' )
283+ } )
284+
285+ it ( 'resolves file that prefix is "@/"' , ( ) => {
286+ const files = new Set < string > ( [ 'dist/app/components/button.js' ] )
287+
288+ const resolved = resolveInternalImport (
289+ '@/app/components/button.js' ,
290+ 'dist/index.js' ,
291+ {
292+ '@/app' : './dist/app/index.js' ,
293+ } ,
294+ files ,
295+ )
296+
297+ expect ( resolved ?. path ) . toBe ( 'dist/app/components/button.js' )
253298 } )
254299} )
0 commit comments