|
1 |
| -import * as fs from 'fs'; |
2 |
| -import { afterEach, describe, expect, it, vi } from 'vitest'; |
| 1 | +import { describe, expect, it } from 'vitest'; |
3 | 2 | import * as util from '../../src/config/util';
|
4 | 3 |
|
5 |
| -// Mock fs to control what getNextjsVersion reads |
6 |
| -vi.mock('fs'); |
7 |
| - |
8 | 4 | describe('util', () => {
|
9 | 5 | describe('supportsProductionCompileHook', () => {
|
10 |
| - afterEach(() => { |
11 |
| - vi.restoreAllMocks(); |
12 |
| - }); |
13 |
| - |
14 | 6 | describe('supported versions', () => {
|
15 | 7 | it('returns true for Next.js 15.4.1', () => {
|
16 |
| - const mockReadFileSync = fs.readFileSync as any; |
17 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.1' })); |
18 |
| - |
19 |
| - const result = util.supportsProductionCompileHook(); |
| 8 | + const result = util.supportsProductionCompileHook('15.4.1'); |
20 | 9 | expect(result).toBe(true);
|
21 | 10 | });
|
22 | 11 |
|
23 | 12 | it('returns true for Next.js 15.4.2', () => {
|
24 |
| - const mockReadFileSync = fs.readFileSync as any; |
25 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.2' })); |
26 |
| - |
27 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 13 | + expect(util.supportsProductionCompileHook('15.4.2')).toBe(true); |
28 | 14 | });
|
29 | 15 |
|
30 | 16 | it('returns true for Next.js 15.5.0', () => {
|
31 |
| - const mockReadFileSync = fs.readFileSync as any; |
32 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.5.0' })); |
33 |
| - |
34 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 17 | + expect(util.supportsProductionCompileHook('15.5.0')).toBe(true); |
35 | 18 | });
|
36 | 19 |
|
37 | 20 | it('returns true for Next.js 16.0.0', () => {
|
38 |
| - const mockReadFileSync = fs.readFileSync as any; |
39 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '16.0.0' })); |
40 |
| - |
41 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 21 | + expect(util.supportsProductionCompileHook('16.0.0')).toBe(true); |
42 | 22 | });
|
43 | 23 |
|
44 | 24 | it('returns true for Next.js 17.0.0', () => {
|
45 |
| - const mockReadFileSync = fs.readFileSync as any; |
46 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '17.0.0' })); |
47 |
| - |
48 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 25 | + expect(util.supportsProductionCompileHook('17.0.0')).toBe(true); |
49 | 26 | });
|
50 | 27 |
|
51 | 28 | it('returns true for supported canary versions', () => {
|
52 |
| - const mockReadFileSync = fs.readFileSync as any; |
53 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.1-canary.42' })); |
54 |
| - |
55 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 29 | + expect(util.supportsProductionCompileHook('15.4.1-canary.42')).toBe(true); |
56 | 30 | });
|
57 | 31 |
|
58 | 32 | it('returns true for supported rc versions', () => {
|
59 |
| - const mockReadFileSync = fs.readFileSync as any; |
60 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.1-rc.1' })); |
61 |
| - |
62 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 33 | + expect(util.supportsProductionCompileHook('15.4.1-rc.1')).toBe(true); |
63 | 34 | });
|
64 | 35 | });
|
65 | 36 |
|
66 | 37 | describe('unsupported versions', () => {
|
67 | 38 | it('returns false for Next.js 15.4.0', () => {
|
68 |
| - const mockReadFileSync = fs.readFileSync as any; |
69 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.0' })); |
70 |
| - |
71 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 39 | + expect(util.supportsProductionCompileHook('15.4.0')).toBe(false); |
72 | 40 | });
|
73 | 41 |
|
74 | 42 | it('returns false for Next.js 15.3.9', () => {
|
75 |
| - const mockReadFileSync = fs.readFileSync as any; |
76 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.3.9' })); |
77 |
| - |
78 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 43 | + expect(util.supportsProductionCompileHook('15.3.9')).toBe(false); |
79 | 44 | });
|
80 | 45 |
|
81 | 46 | it('returns false for Next.js 15.0.0', () => {
|
82 |
| - const mockReadFileSync = fs.readFileSync as any; |
83 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.0.0' })); |
84 |
| - |
85 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 47 | + expect(util.supportsProductionCompileHook('15.0.0')).toBe(false); |
86 | 48 | });
|
87 | 49 |
|
88 | 50 | it('returns false for Next.js 14.2.0', () => {
|
89 |
| - const mockReadFileSync = fs.readFileSync as any; |
90 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '14.2.0' })); |
91 |
| - |
92 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 51 | + expect(util.supportsProductionCompileHook('14.2.0')).toBe(false); |
93 | 52 | });
|
94 | 53 |
|
95 | 54 | it('returns false for unsupported canary versions', () => {
|
96 |
| - const mockReadFileSync = fs.readFileSync as any; |
97 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.0-canary.42' })); |
98 |
| - |
99 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 55 | + expect(util.supportsProductionCompileHook('15.4.0-canary.42')).toBe(false); |
100 | 56 | });
|
101 | 57 | });
|
102 | 58 |
|
103 | 59 | describe('edge cases', () => {
|
104 | 60 | it('returns false for invalid version strings', () => {
|
105 |
| - const mockReadFileSync = fs.readFileSync as any; |
106 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: 'invalid.version' })); |
107 |
| - |
108 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 61 | + expect(util.supportsProductionCompileHook('invalid.version')).toBe(false); |
109 | 62 | });
|
110 | 63 |
|
111 | 64 | it('handles versions with build metadata', () => {
|
112 |
| - const mockReadFileSync = fs.readFileSync as any; |
113 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.1+build.123' })); |
114 |
| - |
115 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 65 | + expect(util.supportsProductionCompileHook('15.4.1+build.123')).toBe(true); |
116 | 66 | });
|
117 | 67 |
|
118 | 68 | it('handles versions with pre-release identifiers', () => {
|
119 |
| - const mockReadFileSync = fs.readFileSync as any; |
120 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.1-alpha.1' })); |
121 |
| - |
122 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 69 | + expect(util.supportsProductionCompileHook('15.4.1-alpha.1')).toBe(true); |
123 | 70 | });
|
124 | 71 |
|
125 | 72 | it('returns false for versions missing patch number', () => {
|
126 |
| - const mockReadFileSync = fs.readFileSync as any; |
127 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4' })); |
128 |
| - |
129 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 73 | + expect(util.supportsProductionCompileHook('15.4')).toBe(false); |
130 | 74 | });
|
131 | 75 |
|
132 | 76 | it('returns false for versions missing minor number', () => {
|
133 |
| - const mockReadFileSync = fs.readFileSync as any; |
134 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15' })); |
135 |
| - |
136 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 77 | + expect(util.supportsProductionCompileHook('15')).toBe(false); |
137 | 78 | });
|
138 | 79 | });
|
139 | 80 |
|
140 | 81 | describe('version boundary tests', () => {
|
141 | 82 | it('returns false for 15.4.0 (just below threshold)', () => {
|
142 |
| - const mockReadFileSync = fs.readFileSync as any; |
143 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.0' })); |
144 |
| - |
145 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 83 | + expect(util.supportsProductionCompileHook('15.4.0')).toBe(false); |
146 | 84 | });
|
147 | 85 |
|
148 | 86 | it('returns true for 15.4.1 (exact threshold)', () => {
|
149 |
| - const mockReadFileSync = fs.readFileSync as any; |
150 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.1' })); |
151 |
| - |
152 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 87 | + expect(util.supportsProductionCompileHook('15.4.1')).toBe(true); |
153 | 88 | });
|
154 | 89 |
|
155 | 90 | it('returns true for 15.4.2 (just above threshold)', () => {
|
156 |
| - const mockReadFileSync = fs.readFileSync as any; |
157 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.4.2' })); |
158 |
| - |
159 |
| - expect(util.supportsProductionCompileHook()).toBe(true); |
| 91 | + expect(util.supportsProductionCompileHook('15.4.2')).toBe(true); |
160 | 92 | });
|
161 | 93 |
|
162 | 94 | it('returns false for 15.3.999 (high patch but wrong minor)', () => {
|
163 |
| - const mockReadFileSync = fs.readFileSync as any; |
164 |
| - mockReadFileSync.mockReturnValue(JSON.stringify({ version: '15.3.999' })); |
165 |
| - |
166 |
| - expect(util.supportsProductionCompileHook()).toBe(false); |
| 95 | + expect(util.supportsProductionCompileHook('15.3.999')).toBe(false); |
167 | 96 | });
|
168 | 97 | });
|
169 | 98 | });
|
|
0 commit comments