|
1 | 1 | import fs from 'node:fs'; |
| 2 | +import { mkdtempSync } from 'node:fs'; |
| 3 | +import { tmpdir } from 'node:os'; |
2 | 4 | import path from 'node:path'; |
3 | 5 |
|
4 | 6 | import { afterEach, beforeEach, describe, expect, it } from 'vitest'; |
5 | | -import { mkdtempSync } from 'node:fs'; |
6 | | -import { tmpdir } from 'node:os'; |
7 | 7 |
|
8 | 8 | import { findViteConfigUp } from '../resolve-vite-config'; |
9 | 9 |
|
10 | 10 | describe('findViteConfigUp', () => { |
11 | 11 | let tempDir: string; |
12 | 12 |
|
13 | 13 | beforeEach(() => { |
14 | | - tempDir = mkdtempSync(path.join(tmpdir(), 'vite-config-test-')); |
| 14 | + // Resolve symlinks (macOS /var -> /private/var) to match path.resolve behavior |
| 15 | + tempDir = fs.realpathSync(mkdtempSync(path.join(tmpdir(), 'vite-config-test-'))); |
15 | 16 | }); |
16 | 17 |
|
17 | 18 | afterEach(() => { |
@@ -89,4 +90,31 @@ describe('findViteConfigUp', () => { |
89 | 90 | const result = findViteConfigUp(subDir, tempDir); |
90 | 91 | expect(result).toBe(path.join(tempDir, 'vite.config.mts')); |
91 | 92 | }); |
| 93 | + |
| 94 | + it('should find .cjs config files', () => { |
| 95 | + const subDir = path.join(tempDir, 'packages', 'my-lib'); |
| 96 | + fs.mkdirSync(subDir, { recursive: true }); |
| 97 | + fs.writeFileSync(path.join(tempDir, 'vite.config.cjs'), ''); |
| 98 | + |
| 99 | + const result = findViteConfigUp(subDir, tempDir); |
| 100 | + expect(result).toBe(path.join(tempDir, 'vite.config.cjs')); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should find .cts config files', () => { |
| 104 | + const subDir = path.join(tempDir, 'packages', 'my-lib'); |
| 105 | + fs.mkdirSync(subDir, { recursive: true }); |
| 106 | + fs.writeFileSync(path.join(tempDir, 'vite.config.cts'), ''); |
| 107 | + |
| 108 | + const result = findViteConfigUp(subDir, tempDir); |
| 109 | + expect(result).toBe(path.join(tempDir, 'vite.config.cts')); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should find .mjs config files', () => { |
| 113 | + const subDir = path.join(tempDir, 'packages', 'my-lib'); |
| 114 | + fs.mkdirSync(subDir, { recursive: true }); |
| 115 | + fs.writeFileSync(path.join(tempDir, 'vite.config.mjs'), ''); |
| 116 | + |
| 117 | + const result = findViteConfigUp(subDir, tempDir); |
| 118 | + expect(result).toBe(path.join(tempDir, 'vite.config.mjs')); |
| 119 | + }); |
92 | 120 | }); |
0 commit comments