|
| 1 | +import { describe, expect, test } from 'vitest' |
| 2 | +import { resolve } from 'pathe' |
| 3 | +import { runVitest } from '../../test-utils' |
| 4 | + |
| 5 | +const root = resolve(__dirname, '../fixtures/cache') |
| 6 | +const project = resolve(__dirname, '../') |
| 7 | + |
| 8 | +test('default', async () => { |
| 9 | + const { vitest, stdout, stderr } = await runVitest({ |
| 10 | + root, |
| 11 | + include: ['*.test.ts'], |
| 12 | + }) |
| 13 | + |
| 14 | + expect(stdout).toContain('✓ basic.test.ts >') |
| 15 | + expect(stderr).toBe('') |
| 16 | + |
| 17 | + const cachePath = vitest!.cache.results.getCachePath() |
| 18 | + const path = resolve(project, 'node_modules/.vite/vitest/results.json') |
| 19 | + expect(cachePath).toMatch(path) |
| 20 | +}) |
| 21 | + |
| 22 | +test('use cache.dir', async () => { |
| 23 | + const { vitest, stdout, stderr } = await runVitest( |
| 24 | + { |
| 25 | + root, |
| 26 | + include: ['*.test.ts'], |
| 27 | + cache: { |
| 28 | + dir: 'node_modules/.vitest-custom', |
| 29 | + }, |
| 30 | + }, |
| 31 | + ) |
| 32 | + |
| 33 | + expect(stdout).toContain('✓ basic.test.ts >') |
| 34 | + expect(stderr).toContain('"cache.dir" is deprecated') |
| 35 | + |
| 36 | + const cachePath = vitest!.cache.results.getCachePath() |
| 37 | + const path = resolve(root, 'node_modules/.vitest-custom/results.json') |
| 38 | + expect(cachePath).toMatch(path) |
| 39 | +}) |
| 40 | + |
| 41 | +test('use cacheDir', async () => { |
| 42 | + const { vitest, stdout, stderr } = await runVitest( |
| 43 | + { |
| 44 | + root, |
| 45 | + include: ['*.test.ts'], |
| 46 | + }, |
| 47 | + [], |
| 48 | + 'test', |
| 49 | + { cacheDir: 'node_modules/.vite-custom' }, |
| 50 | + ) |
| 51 | + |
| 52 | + expect(stdout).toContain('✓ basic.test.ts >') |
| 53 | + expect(stderr).toBe('') |
| 54 | + |
| 55 | + const cachePath = vitest!.cache.results.getCachePath() |
| 56 | + const path = resolve(root, 'node_modules/.vite-custom/vitest/results.json') |
| 57 | + expect(cachePath).toMatch(path) |
| 58 | +}) |
| 59 | + |
| 60 | +describe('with optimizer enabled', () => { |
| 61 | + const deps = { |
| 62 | + optimizer: { |
| 63 | + web: { |
| 64 | + enabled: true, |
| 65 | + }, |
| 66 | + }, |
| 67 | + } |
| 68 | + |
| 69 | + test('default', async () => { |
| 70 | + const { vitest, stdout, stderr } = await runVitest({ |
| 71 | + root, |
| 72 | + include: ['*.test.ts'], |
| 73 | + deps, |
| 74 | + }) |
| 75 | + |
| 76 | + expect(stdout).toContain('✓ basic.test.ts >') |
| 77 | + expect(stderr).toBe('') |
| 78 | + |
| 79 | + const cachePath = vitest!.cache.results.getCachePath() |
| 80 | + const path = resolve(project, 'node_modules/.vite/vitest/results.json') |
| 81 | + expect(cachePath).toBe(path) |
| 82 | + }) |
| 83 | + |
| 84 | + test('use cache.dir', async () => { |
| 85 | + const { vitest, stdout, stderr } = await runVitest( |
| 86 | + { |
| 87 | + root, |
| 88 | + include: ['*.test.ts'], |
| 89 | + deps, |
| 90 | + cache: { |
| 91 | + dir: 'node_modules/.vitest-custom', |
| 92 | + }, |
| 93 | + }, |
| 94 | + ) |
| 95 | + |
| 96 | + expect(stdout).toContain('✓ basic.test.ts >') |
| 97 | + expect(stderr).toContain('"cache.dir" is deprecated') |
| 98 | + |
| 99 | + const cachePath = vitest!.cache.results.getCachePath() |
| 100 | + const path = resolve(root, 'node_modules/.vitest-custom/results.json') |
| 101 | + expect(cachePath).toBe(path) |
| 102 | + }) |
| 103 | + |
| 104 | + test('use cacheDir', async () => { |
| 105 | + const { vitest, stdout, stderr } = await runVitest( |
| 106 | + { |
| 107 | + root, |
| 108 | + include: ['*.test.ts'], |
| 109 | + deps, |
| 110 | + }, |
| 111 | + [], |
| 112 | + 'test', |
| 113 | + { cacheDir: 'node_modules/.vite-custom' }, |
| 114 | + ) |
| 115 | + |
| 116 | + expect(stdout).toContain('✓ basic.test.ts >') |
| 117 | + expect(stderr).toBe('') |
| 118 | + |
| 119 | + const cachePath = vitest!.cache.results.getCachePath() |
| 120 | + const path = resolve(root, 'node_modules/.vite-custom/vitest/results.json') |
| 121 | + expect(cachePath).toBe(path) |
| 122 | + }) |
| 123 | +}) |
0 commit comments