11import { confirm , input } from '@inquirer/prompts' ;
22import { fs , vol } from 'memfs' ;
3- import { Mock , afterEach , describe , expect , test , vi } from 'vitest' ;
3+ import {
4+ Mock ,
5+ afterEach ,
6+ beforeEach ,
7+ describe ,
8+ expect ,
9+ test ,
10+ vi ,
11+ } from 'vitest' ;
412import exec from '../../util/exec' ;
513import print from '../../util/print' ;
614import { createApp } from '../createApp' ;
@@ -12,6 +20,10 @@ vi.mock('@inquirer/prompts', () => ({
1220vi . mock ( '../../util/addDependency' ) ;
1321vi . mock ( '../../util/print' , ( ) => ( { default : vi . fn ( ) } ) ) ;
1422
23+ beforeEach ( ( ) => {
24+ process . env . npm_config_user_agent = 'yarn/1.22.0' ;
25+ } ) ;
26+
1527afterEach ( ( ) => {
1628 vol . reset ( ) ;
1729 ( print as Mock ) . mockReset ( ) ;
@@ -84,18 +96,28 @@ describe('package manager options', () => {
8496 ( confirm as Mock ) . mockResolvedValueOnce ( true ) ;
8597 await createApp ( 'MyApp' , { npm : true } ) ;
8698 expect ( exec ) . toHaveBeenCalledWith ( 'npm install' ) ;
99+ expectFileContents ( 'MyApp/.npmrc' , 'legacy-peer-deps=true' ) ;
87100 } ) ;
88101
89102 test ( 'creates with bun' , async ( ) => {
90103 ( confirm as Mock ) . mockResolvedValueOnce ( true ) ;
91104 await createApp ( 'MyApp' , { bun : true } ) ;
92105 expect ( exec ) . toHaveBeenCalledWith ( 'bun install' ) ;
106+ expect ( ( ) => fs . readFileSync ( 'MyApp/.npmrc' , 'utf8' ) ) . toThrow ( ) ;
93107 } ) ;
94108
95109 test ( 'creates with pnpm' , async ( ) => {
96110 ( confirm as Mock ) . mockResolvedValueOnce ( true ) ;
97111 await createApp ( 'MyApp' , { pnpm : true } ) ;
98112 expect ( exec ) . toHaveBeenCalledWith ( 'pnpm install' ) ;
113+ expect ( ( ) => fs . readFileSync ( 'MyApp/.npmrc' , 'utf8' ) ) . toThrow ( ) ;
114+ } ) ;
115+
116+ test ( 'creates with yarn (does not add .npmrc)' , async ( ) => {
117+ ( confirm as Mock ) . mockResolvedValueOnce ( true ) ;
118+ await createApp ( 'MyApp' , { yarn : true } ) ;
119+ expect ( exec ) . toHaveBeenCalledWith ( 'yarn install' ) ;
120+ expect ( ( ) => fs . readFileSync ( 'MyApp/.npmrc' , 'utf8' ) ) . toThrow ( ) ;
99121 } ) ;
100122} ) ;
101123
0 commit comments