Skip to content

Commit 1c39be1

Browse files
chore: stub cache server via vite plugin
Co-authored-by: me <me@kentcdodds.com>
1 parent c067013 commit 1c39be1

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

vite.config.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import { iconsSpritesheet } from 'vite-plugin-icons-spritesheet'
1313
export default defineConfig((config) => {
1414
const mode = config.mode ?? process.env.NODE_ENV
1515
const isTest = mode === 'test' || Boolean(process.env.VITEST)
16+
const cacheServerStubPlugin = isTest
17+
? {
18+
name: 'vitest-cache-server-stub',
19+
resolveId(source: string) {
20+
if (source.endsWith('cache.server.ts')) {
21+
return path.resolve('tests/mocks/cache-server.ts')
22+
}
23+
return null
24+
},
25+
}
26+
: null
1627
return {
1728
build: {
1829
target: 'es2022',
@@ -39,19 +50,9 @@ export default defineConfig((config) => {
3950
ignored: ['**/playwright-report/**'],
4051
},
4152
},
42-
resolve: {
43-
alias:
44-
isTest
45-
? [
46-
{
47-
find: /cache\.server\.ts$/,
48-
replacement: path.resolve('tests/mocks/cache-server.ts'),
49-
},
50-
]
51-
: undefined,
52-
},
5353
sentryConfig,
5454
plugins: [
55+
cacheServerStubPlugin,
5556
envOnlyMacros(),
5657
tailwindcss(),
5758
reactRouterDevTools(),
@@ -71,12 +72,6 @@ export default defineConfig((config) => {
7172
: null,
7273
],
7374
test: {
74-
alias: [
75-
{
76-
find: /cache\.server\.ts$/,
77-
replacement: path.resolve('tests/mocks/cache-server.ts'),
78-
},
79-
],
8075
include: ['./app/**/*.test.{ts,tsx}'],
8176
setupFiles: ['./tests/setup/setup-test-env.ts'],
8277
globalSetup: ['./tests/setup/global-setup.ts'],

0 commit comments

Comments
 (0)