Skip to content

Commit

Permalink
test: fix some broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 16, 2022
1 parent 5f2bfce commit a75bf4e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
24 changes: 19 additions & 5 deletions packages/vite/src/node/server/__tests__/moduleGraph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,35 @@ describe('moduleGraph', () => {
moduleGraph.invalidateModule(entryModule)
expect(entryModule.ssrError).toBe(null)
})
})

describe('ensureEntryFromUrl', () => {
it('reuses an entry with same resolved id', async () => {
const moduleGraph = new ModuleGraph(async (url) => {
if (url === '/xx.js') {
return { id: '/x.js', meta: { vite: 'test' } }
} else {
return { id: url, meta: { vite: 'test' } }
}
})

const mod1 = await moduleGraph.ensureEntryFromUrl('/x.js', false)
const mod2 = await moduleGraph.ensureEntryFromUrl('/xx.js', false)
expect(mod1 === mod2).to.be.true
})

it('ensureEntryFromUrl should based on resolvedId', async () => {
it('creates a new entry if resolved "meta" differs', async () => {
const moduleGraph = new ModuleGraph(async (url) => {
if (url === '/xx.js') {
return { id: '/x.js' }
} else {
return { id: url }
return { id: url, meta: { vite: 'test' } }
}
})
const meta = { vite: 'test' }

const mod1 = await moduleGraph.ensureEntryFromUrl('/x.js', false)
mod1.meta = meta
const mod2 = await moduleGraph.ensureEntryFromUrl('/xx.js', false)
expect(mod2.meta).to.equal(meta)
expect(mod1 === mod2).to.be.false
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ async function getPluginContainer(
config.plugins = config.plugins.filter((p) => !/pre-alias/.test(p.name))

// @ts-ignore: So does this one and this mock one seems to work
const iap = config.plugins.find((p) => p.name === 'vite:import-analysis')
iap.configureServer(<ViteDevServer>{ moduleGraph })
const iap = config.plugins.find((p) => p.name === 'vite:import-analysis')!
if (typeof iap.configureServer === 'function') {
iap.configureServer(<ViteDevServer>{ moduleGraph })
} else {
throw 'Expected vite:import-analysis plugin to have a "configureServer" method'
}

resolveId = (id) => container.resolveId(id)
const container = await createPluginContainer(config, moduleGraph)
Expand Down

0 comments on commit a75bf4e

Please sign in to comment.