Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(v6): test ssrLoadModule and virtual module invalidation #17313

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,45 @@
expect(viteValue.dirname).toBe(path.dirname(filename))
expect(viteValue.filename).toBe(filename)
})

test('virtual module invalidation', async () => {
const server = await createServer({
configFile: false,
root,
logLevel: 'silent',
optimizeDeps: {
noDiscovery: true,
},
plugins: [
{
name: 'virtual-test',
resolveId(id) {
if (id === 'virtual:test') {
return '\0virtual:test'
}
},
load(id) {
if (id === '\0virtual:test') {
return `
globalThis.__virtual_test_state ??= 0;
globalThis.__virtual_test_state++;
export default globalThis.__virtual_test_state;
`
}
},
},
],
})
await server.pluginContainer.buildStart({})

const mod1 = await server.ssrLoadModule('virtual:test')
expect(mod1.default).toEqual(1)
const mod2 = await server.ssrLoadModule('virtual:test')
expect(mod2.default).toEqual(1)

const modNode = server.moduleGraph.getModuleById('\0virtual:test')
server.moduleGraph.invalidateModule(modNode!)

const mod3 = await server.ssrLoadModule('virtual:test')
expect(mod3.default).toEqual(2)

Check failure on line 105 in packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-18, ubuntu-latest

packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts > virtual module invalidation

AssertionError: expected 1 to deeply equal 2 - Expected + Received - 2 + 1 ❯ packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts:105:24

Check failure on line 105 in packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, ubuntu-latest

packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts > virtual module invalidation

AssertionError: expected 1 to deeply equal 2 - Expected + Received - 2 + 1 ❯ packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts:105:24

Check failure on line 105 in packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-20, windows-latest

packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts > virtual module invalidation

AssertionError: expected 1 to deeply equal 2 - Expected + Received - 2 + 1 ❯ packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts:105:24
})
Loading