@@ -6,58 +6,29 @@ import { FileSystem, JsonFile } from '@rushstack/node-core-library';
66import { TestUtilities } from '@rushstack/heft-config-file' ;
77import { RushConfiguration } from '../../api/RushConfiguration' ;
88
9+ const MONOREPO_ROOT : string = path . dirname (
10+ RushConfiguration . tryFindRushJsonLocation ( { startingFolder : __dirname } ) !
11+ ) ;
12+ const CATALOG_SYNC_REPO_PATH : string = `${ __dirname } /catalogSyncTestRepo` ;
13+
914describe ( 'RushPnpmCommandLineParser' , ( ) => {
1015 describe ( 'catalog syncing' , ( ) => {
11- let testRepoPath : string ;
12- let pnpmConfigPath : string ;
13- let pnpmWorkspacePath : string ;
14-
15- beforeEach ( ( ) => {
16- testRepoPath = path . join ( __dirname , 'temp' , 'catalog-sync-test-repo' ) ;
17- FileSystem . ensureFolder ( testRepoPath ) ;
18-
19- const rushJsonPath : string = `${ testRepoPath / rush . json `;
20- const rushJson = {
21- $schema: 'https://developer.microsoft.com/json-schemas/rush/v5/rush.schema.json',
22- rushVersion: '5.166.0',
23- pnpmVersion: '10.28.1',
24- nodeSupportedVersionRange: '>=18.0.0',
25- projects: []
26- };
27- JsonFile.save(rushJson, rushJsonPath, { ensureFolderExists: true });
28-
29- const configDir: string = path.join(testRepoPath, 'common', 'config', 'rush');
30- FileSystem.ensureFolder(configDir);
31-
32- pnpmConfigPath = path.join(configDir, 'pnpm-config.json');
33- const pnpmConfig = {
34- globalCatalogs: {
35- default: {
36- react: '^18.0.0',
37- 'react-dom': '^18.0.0'
38- }
39- }
40- };
41- JsonFile.save(pnpmConfig, pnpmConfigPath);
16+ const testRepoPath : string = `${ MONOREPO_ROOT } /temp/catalog-sync-test-repo` ;
17+ const pnpmConfigPath : string = `${ testRepoPath } /common/config/rush/pnpm-config.json` ;
18+ const pnpmWorkspacePath : string = `${ testRepoPath } /common/temp/pnpm-workspace.yaml` ;
4219
43- const tempDir: string = path.join(testRepoPath, 'common', 'temp');
44- FileSystem.ensureFolder(tempDir );
20+ beforeEach ( async ( ) => {
21+ await FileSystem . copyFilesAsync ( { sourcePath : CATALOG_SYNC_REPO_PATH , destinationPath : testRepoPath } ) ;
4522
46- pnpmWorkspacePath = path.join(tempDir, 'pnpm-workspace.yaml');
47- const workspaceYaml = ` packages :
48- - '../../apps/*'
49- catalogs :
50- default :
51- react : ^ 18.0 .0
52- react - dom : ^ 18.0 .0
53- `;
54- FileSystem.writeFile(pnpmWorkspacePath, workspaceYaml);
23+ // common/temp is gitignored so it is not part of the static repo; copy the initial workspace file here
24+ await FileSystem . copyFilesAsync ( {
25+ sourcePath : `${ CATALOG_SYNC_REPO_PATH } /pnpm-workspace.yaml` ,
26+ destinationPath : pnpmWorkspacePath
27+ } ) ;
5528 } ) ;
5629
57- afterEach(() => {
58- if (FileSystem.exists(testRepoPath)) {
59- FileSystem.deleteFolder(testRepoPath);
60- }
30+ afterEach ( async ( ) => {
31+ await FileSystem . deleteFolderAsync ( testRepoPath ) ;
6132 } ) ;
6233
6334 it ( 'syncs updated catalogs from pnpm-workspace.yaml to pnpm-config.json' , async ( ) => {
@@ -71,10 +42,10 @@ catalogs:
7142 frontend:
7243 vue: ^3.4.0
7344` ;
74- FileSystem.writeFile (pnpmWorkspacePath, updatedWorkspaceYaml);
45+ await FileSystem . writeFileAsync ( pnpmWorkspacePath , updatedWorkspaceYaml ) ;
7546
7647 const rushConfiguration : RushConfiguration = RushConfiguration . loadFromConfigurationFile (
77- path.join( testRepoPath, ' rush.json')
48+ ` ${ testRepoPath } / rush.json`
7849 ) ;
7950
8051 const subspace = rushConfiguration . getSubspace ( 'default' ) ;
@@ -93,7 +64,7 @@ catalogs:
9364 pnpmOptions ?. updateGlobalCatalogs ( newCatalogs ) ;
9465
9566 const updatedRushConfiguration : RushConfiguration = RushConfiguration . loadFromConfigurationFile (
96- path.join( testRepoPath, ' rush.json')
67+ ` ${ testRepoPath } / rush.json`
9768 ) ;
9869 const updatedSubspace = updatedRushConfiguration . getSubspace ( 'default' ) ;
9970 const updatedPnpmOptions = updatedSubspace . getPnpmOptions ( ) ;
@@ -115,7 +86,7 @@ catalogs:
11586 const newCatalogs = await PnpmWorkspaceFile . loadCatalogsFromFileAsync ( pnpmWorkspacePath ) ;
11687
11788 const rushConfiguration : RushConfiguration = RushConfiguration . loadFromConfigurationFile (
118- path.join( testRepoPath, ' rush.json')
89+ ` ${ testRepoPath } / rush.json`
11990 ) ;
12091 const subspace = rushConfiguration . getSubspace ( 'default' ) ;
12192 const pnpmOptions = subspace . getPnpmOptions ( ) ;
@@ -135,23 +106,23 @@ catalogs:
135106 const workspaceWithoutCatalogs = `packages:
136107 - '../../apps/*'
137108` ;
138- FileSystem . writeFile ( pnpmWorkspacePath , workspaceWithoutCatalogs ) ;
109+ await FileSystem . writeFileAsync ( pnpmWorkspacePath , workspaceWithoutCatalogs ) ;
139110
140111 const { PnpmWorkspaceFile } = require ( '../../logic/pnpm/PnpmWorkspaceFile' ) ;
141112 const newCatalogs = await PnpmWorkspaceFile . loadCatalogsFromFileAsync ( pnpmWorkspacePath ) ;
142113
143114 expect ( newCatalogs ) . toBeUndefined ( ) ;
144115
145116 const rushConfiguration : RushConfiguration = RushConfiguration . loadFromConfigurationFile (
146- path . join ( testRepoPath , ' rush.json' )
117+ ` ${ testRepoPath } / rush.json`
147118 ) ;
148119 const subspace = rushConfiguration . getSubspace ( 'default' ) ;
149120 const pnpmOptions = subspace . getPnpmOptions ( ) ;
150121
151122 pnpmOptions ?. updateGlobalCatalogs ( newCatalogs ) ;
152123
153124 const updatedRushConfiguration : RushConfiguration = RushConfiguration . loadFromConfigurationFile (
154- path . join ( testRepoPath , ' rush.json' )
125+ ` ${ testRepoPath } / rush.json`
155126 ) ;
156127 const updatedSubspace = updatedRushConfiguration . getSubspace ( 'default' ) ;
157128 const updatedPnpmOptions = updatedSubspace . getPnpmOptions ( ) ;
0 commit comments