Skip to content

Commit

Permalink
test(v6): add runner dynamic import test
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jun 8, 2024
1 parent bbca0b4 commit c7e8cfb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/vite/src/node/__tests__/dev.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect, test } from 'vitest'
import { resolveConfig } from '..'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import { describe, expect, onTestFinished, test } from 'vitest'
import { createServer, createServerModuleRunner, resolveConfig } from '..'

describe('resolveBuildEnvironmentOptions in dev', () => {
test('build.rollupOptions should not have input in lib', async () => {
Expand All @@ -17,3 +19,27 @@ describe('resolveBuildEnvironmentOptions in dev', () => {
expect(config.build.rollupOptions).not.toHaveProperty('input')
})
})

test('runner dynamic import', async () => {
const root = fileURLToPath(
new URL('./fixtures/runner-import', import.meta.url),
)
const server = await createServer({
clearScreen: false,
configFile: false,
root,
environments: {
custom: {},
},
})
onTestFinished(async () => {
await server.close()
})

const environment = server.environments.custom
const runner = createServerModuleRunner(environment)

const { getDep, customImport } = await runner.import('/entry.js')
const mod = await customImport(path.join(root, 'dep.js'))
expect(mod.dep).toBe(getDep())
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const dep = ['test']
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { dep } from './dep.js'

export function getDep() {
return dep
}

export function customImport(id) {
return import(/* @vite-ignore */ id)
}

0 comments on commit c7e8cfb

Please sign in to comment.