1- import { existsSync , rmSync } from 'fs' ;
2- import { tmpdir } from 'os' ;
1+ import { existsSync , mkdirSync , realpathSync , rmSync } from 'fs' ;
32import { join } from 'path' ;
43import { afterEach , describe , expect , it } from 'vitest' ;
54import { execa } from 'execa' ;
@@ -13,7 +12,14 @@ import { ProjectGenerator } from '../../generator/index.js';
1312 */
1413
1514function getTempProjectPath ( name : string ) : string {
16- return join ( tmpdir ( ) , `react-setup-build-${ name } -${ Date . now ( ) } ` ) ;
15+ const baseDir = join ( process . cwd ( ) , '.tmp-test-projects' ) ;
16+ if ( ! existsSync ( baseDir ) ) {
17+ mkdirSync ( baseDir , { recursive : true } ) ;
18+ }
19+ return join (
20+ baseDir ,
21+ `react-setup-build-${ name } -${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 8 ) } `
22+ ) ;
1723}
1824
1925function cleanupProject ( path : string ) : void {
@@ -46,13 +52,39 @@ function createConfig(name: string, overrides: Partial<ProjectConfig>): ProjectC
4652 } ;
4753}
4854
55+ const NPM_INSTALL_TIMEOUT_MS = Number ( process . env . CRF_NPM_INSTALL_TIMEOUT_MS ?? 600000 ) ;
56+ const NPM_BUILD_TIMEOUT_MS = Number ( process . env . CRF_NPM_BUILD_TIMEOUT_MS ?? 600000 ) ;
57+ const TEST_HOOK_TIMEOUT_MS = Number ( process . env . CRF_TEST_HOOK_TIMEOUT_MS ?? 300000 ) ;
58+
59+ async function installDependencies ( projectPath : string ) {
60+ return execa ( 'npm' , [ 'install' , '--no-audit' , '--no-fund' ] , {
61+ cwd : getCommandCwd ( projectPath ) ,
62+ timeout : NPM_INSTALL_TIMEOUT_MS ,
63+ } ) ;
64+ }
65+
66+ async function buildProject ( projectPath : string ) {
67+ return execa ( 'npm' , [ 'run' , 'build' ] , {
68+ cwd : getCommandCwd ( projectPath ) ,
69+ timeout : NPM_BUILD_TIMEOUT_MS ,
70+ } ) ;
71+ }
72+
73+ function getCommandCwd ( projectPath : string ) : string {
74+ try {
75+ return realpathSync ( projectPath ) ;
76+ } catch {
77+ return projectPath ;
78+ }
79+ }
80+
4981describe ( 'Build Verification Tests' , ( ) => {
5082 const projectPaths : string [ ] = [ ] ;
5183
5284 afterEach ( ( ) => {
5385 projectPaths . forEach ( cleanupProject ) ;
5486 projectPaths . length = 0 ;
55- } ) ;
87+ } , TEST_HOOK_TIMEOUT_MS ) ;
5688
5789 describe ( 'Next.js Projects' , ( ) => {
5890 it ( 'should generate and build a minimal Next.js project' , async ( ) => {
@@ -70,23 +102,17 @@ describe('Build Verification Tests', () => {
70102
71103 // Install dependencies
72104 console . log ( 'Installing dependencies for Next.js project...' ) ;
73- const installResult = await execa ( 'npm' , [ 'install' ] , {
74- cwd : config . path ,
75- timeout : 120000 , // 2 minutes
76- } ) ;
105+ const installResult = await installDependencies ( config . path ) ;
77106 expect ( installResult . exitCode ) . toBe ( 0 ) ;
78107
79108 // Build the project
80109 console . log ( 'Building Next.js project...' ) ;
81- const buildResult = await execa ( 'npm' , [ 'run' , 'build' ] , {
82- cwd : config . path ,
83- timeout : 180000 , // 3 minutes
84- } ) ;
110+ const buildResult = await buildProject ( config . path ) ;
85111 expect ( buildResult . exitCode ) . toBe ( 0 ) ;
86112
87113 // Verify build output exists
88114 expect ( existsSync ( join ( config . path , '.next' ) ) ) . toBe ( true ) ;
89- } , 360000 ) ; // 6 minute timeout for entire test
115+ } , 720000 ) ; // 12 minute timeout for entire test
90116
91117 it ( 'should generate and build Next.js with Tailwind' , async ( ) => {
92118 const config = createConfig ( 'nextjs-build-tailwind' , {
@@ -102,22 +128,16 @@ describe('Build Verification Tests', () => {
102128
103129 // Install dependencies
104130 console . log ( 'Installing dependencies for Next.js + Tailwind project...' ) ;
105- const installResult = await execa ( 'npm' , [ 'install' ] , {
106- cwd : config . path ,
107- timeout : 120000 ,
108- } ) ;
131+ const installResult = await installDependencies ( config . path ) ;
109132 expect ( installResult . exitCode ) . toBe ( 0 ) ;
110133
111134 // Build the project
112135 console . log ( 'Building Next.js + Tailwind project...' ) ;
113- const buildResult = await execa ( 'npm' , [ 'run' , 'build' ] , {
114- cwd : config . path ,
115- timeout : 180000 ,
116- } ) ;
136+ const buildResult = await buildProject ( config . path ) ;
117137 expect ( buildResult . exitCode ) . toBe ( 0 ) ;
118138
119139 expect ( existsSync ( join ( config . path , '.next' ) ) ) . toBe ( true ) ;
120- } , 360000 ) ;
140+ } , 720000 ) ;
121141
122142 it ( 'should generate and build Next.js with state management' , async ( ) => {
123143 const config = createConfig ( 'nextjs-build-zustand' , {
@@ -134,22 +154,16 @@ describe('Build Verification Tests', () => {
134154
135155 // Install dependencies
136156 console . log ( 'Installing dependencies for Next.js + Zustand project...' ) ;
137- const installResult = await execa ( 'npm' , [ 'install' ] , {
138- cwd : config . path ,
139- timeout : 120000 ,
140- } ) ;
157+ const installResult = await installDependencies ( config . path ) ;
141158 expect ( installResult . exitCode ) . toBe ( 0 ) ;
142159
143160 // Build the project
144161 console . log ( 'Building Next.js + Zustand project...' ) ;
145- const buildResult = await execa ( 'npm' , [ 'run' , 'build' ] , {
146- cwd : config . path ,
147- timeout : 180000 ,
148- } ) ;
162+ const buildResult = await buildProject ( config . path ) ;
149163 expect ( buildResult . exitCode ) . toBe ( 0 ) ;
150164
151165 expect ( existsSync ( join ( config . path , '.next' ) ) ) . toBe ( true ) ;
152- } , 360000 ) ;
166+ } , 720000 ) ;
153167 } ) ;
154168
155169 describe ( 'Vite Projects' , ( ) => {
@@ -168,23 +182,17 @@ describe('Build Verification Tests', () => {
168182
169183 // Install dependencies
170184 console . log ( 'Installing dependencies for Vite project...' ) ;
171- const installResult = await execa ( 'npm' , [ 'install' ] , {
172- cwd : config . path ,
173- timeout : 120000 ,
174- } ) ;
185+ const installResult = await installDependencies ( config . path ) ;
175186 expect ( installResult . exitCode ) . toBe ( 0 ) ;
176187
177188 // Build the project
178189 console . log ( 'Building Vite project...' ) ;
179- const buildResult = await execa ( 'npm' , [ 'run' , 'build' ] , {
180- cwd : config . path ,
181- timeout : 120000 ,
182- } ) ;
190+ const buildResult = await buildProject ( config . path ) ;
183191 expect ( buildResult . exitCode ) . toBe ( 0 ) ;
184192
185193 // Verify build output exists
186194 expect ( existsSync ( join ( config . path , 'dist' ) ) ) . toBe ( true ) ;
187- } , 300000 ) ; // 5 minute timeout
195+ } , 600000 ) ; // 10 minute timeout
188196
189197 it ( 'should generate and build Vite with Tailwind' , async ( ) => {
190198 const config = createConfig ( 'vite-build-tailwind' , {
@@ -200,22 +208,16 @@ describe('Build Verification Tests', () => {
200208
201209 // Install dependencies
202210 console . log ( 'Installing dependencies for Vite + Tailwind project...' ) ;
203- const installResult = await execa ( 'npm' , [ 'install' ] , {
204- cwd : config . path ,
205- timeout : 120000 ,
206- } ) ;
211+ const installResult = await installDependencies ( config . path ) ;
207212 expect ( installResult . exitCode ) . toBe ( 0 ) ;
208213
209214 // Build the project
210215 console . log ( 'Building Vite + Tailwind project...' ) ;
211- const buildResult = await execa ( 'npm' , [ 'run' , 'build' ] , {
212- cwd : config . path ,
213- timeout : 120000 ,
214- } ) ;
216+ const buildResult = await buildProject ( config . path ) ;
215217 expect ( buildResult . exitCode ) . toBe ( 0 ) ;
216218
217219 expect ( existsSync ( join ( config . path , 'dist' ) ) ) . toBe ( true ) ;
218- } , 300000 ) ;
220+ } , 600000 ) ;
219221
220222 it ( 'should generate and build Vite with full stack (Tailwind + Zustand + TanStack Query)' , async ( ) => {
221223 const config = createConfig ( 'vite-build-full' , {
@@ -233,22 +235,15 @@ describe('Build Verification Tests', () => {
233235
234236 // Install dependencies
235237 console . log ( 'Installing dependencies for Vite full stack project...' ) ;
236- const installResult = await execa ( 'npm' , [ 'install' ] , {
237- cwd : config . path ,
238- timeout : 120000 ,
239- } ) ;
238+ const installResult = await installDependencies ( config . path ) ;
240239 expect ( installResult . exitCode ) . toBe ( 0 ) ;
241240
242241 // Build the project
243242 console . log ( 'Building Vite full stack project...' ) ;
244- const buildResult = await execa ( 'npm' , [ 'run' , 'build' ] , {
245- cwd : config . path ,
246- timeout : 120000 ,
247- } ) ;
243+ const buildResult = await buildProject ( config . path ) ;
248244 expect ( buildResult . exitCode ) . toBe ( 0 ) ;
249245
250246 expect ( existsSync ( join ( config . path , 'dist' ) ) ) . toBe ( true ) ;
251- } , 300000 ) ;
247+ } , 600000 ) ;
252248 } ) ;
253249} ) ;
254-
0 commit comments