@@ -3,12 +3,17 @@ import { posix, win32 } from 'node:path'
33import { fileURLToPath } from 'node:url'
44import { describe , expect , vi } from 'vitest'
55import { isWindows } from '../../../../shared/utils'
6+ import type { ExternalFetchResult } from '../../../../shared/invokeMethods'
67import { createModuleRunnerTester } from './utils'
78
89const _URL = URL
910
1011describe ( 'module runner initialization' , async ( ) => {
11- const it = await createModuleRunnerTester ( )
12+ const it = await createModuleRunnerTester ( {
13+ resolve : {
14+ external : [ 'tinyglobby' ] ,
15+ } ,
16+ } )
1217
1318 it ( 'correctly runs ssr code' , async ( { runner } ) => {
1419 const mod = await runner . import ( '/fixtures/simple.js' )
@@ -489,4 +494,24 @@ describe('virtual module hmr', async () => {
489494 expect ( mod ?. exports . default ) . toBe ( 'reloaded' )
490495 } )
491496 } )
497+
498+ it ( "the external module's ID and file are resolved correctly" , async ( {
499+ server,
500+ runner,
501+ } ) => {
502+ await runner . import (
503+ posix . join ( server . config . root , 'fixtures/import-external.ts' ) ,
504+ )
505+ const moduleNode = runner . evaluatedModules . getModuleByUrl ( 'tinyglobby' ) !
506+ const meta = moduleNode . meta as ExternalFetchResult
507+ if ( process . platform === 'win32' ) {
508+ expect ( meta . externalize ) . toMatch ( / ^ f i l e : \/ \/ \/ \w : \/ / ) // file:///C:/
509+ expect ( moduleNode . id ) . toMatch ( / ^ \w : \/ / ) // C:/
510+ expect ( moduleNode . file ) . toMatch ( / ^ \w : \/ / ) // C:/
511+ } else {
512+ expect ( meta . externalize ) . toMatch ( / ^ f i l e : \/ \/ \/ / ) // file:///
513+ expect ( moduleNode . id ) . toMatch ( / ^ \/ / ) // /
514+ expect ( moduleNode . file ) . toMatch ( / ^ \/ / ) // /
515+ }
516+ } )
492517} )
0 commit comments