Skip to content

Commit

Permalink
Add test cases for shouldExternalize
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswheeldon-peakon committed Aug 6, 2024
1 parent 3d0adbc commit 8c78068
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/vite-node/test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,55 @@ describe('server correctly caches data', () => {
expect(webFiles).toHaveLength(1)
})
})

describe('externalize', () => {
describe('by default', () => {
test('should externalize vite\'s cached dependencies', async () => {
const vnServer = new ViteNodeServer({
config: {
root: '/',
cacheDir: '/node_modules/.vite',
},
} as any, {})

const externalize = await vnServer.shouldExternalize('/node_modules/.vite/cached.js')
expect(externalize).toBeTruthy()
})
})

describe('with server.deps.inline: true', () => {
test('should not externalize vite\'s cached dependencies', async () => {
const vnServer = new ViteNodeServer({
config: {
root: '/',
cacheDir: '/node_modules/.vite',
},
} as any, {
deps: {
inline: true,
},
})

const externalize = await vnServer.shouldExternalize('/node_modules/.vite/cached.js')
expect(externalize).toBeFalsy()
})
})

describe('with server.deps.inline including the cache dir', () => {
test('should not externalize vite\'s cached dependencies', async () => {
const vnServer = new ViteNodeServer({
config: {
root: '/',
cacheDir: '/node_modules/.vite',
},
} as any, {
deps: {
inline: [/node_modules\/\.vite/],
},
})

const externalize = await vnServer.shouldExternalize('/node_modules/.vite/cached.js')
expect(externalize).toBeFalsy()
})
})
})

0 comments on commit 8c78068

Please sign in to comment.