Skip to content

Commit 167f583

Browse files
author
Ben Keen
committed
Code review feedback
1 parent 3ee9066 commit 167f583

5 files changed

Lines changed: 16 additions & 27 deletions

File tree

libraries/rush-lib/src/cli/test/RushPnpmCommandLineParser.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,19 @@ import * as path from 'node:path';
55
import { FileSystem, JsonFile } from '@rushstack/node-core-library';
66
import { TestUtilities } from '@rushstack/heft-config-file';
77
import { RushConfiguration } from '../../api/RushConfiguration';
8+
import { PnpmWorkspaceFile } from '../../logic/pnpm/PnpmWorkspaceFile';
89

9-
const MONOREPO_ROOT: string = path.dirname(
10-
RushConfiguration.tryFindRushJsonLocation({ startingFolder: __dirname })!
11-
);
10+
const PACKAGE_ROOT: string = path.resolve(__dirname, '../../..');
1211
const CATALOG_SYNC_REPO_PATH: string = `${__dirname}/catalogSyncTestRepo`;
1312

1413
describe('RushPnpmCommandLineParser', () => {
1514
describe('catalog syncing', () => {
16-
const testRepoPath: string = `${MONOREPO_ROOT}/temp/catalog-sync-test-repo`;
15+
const testRepoPath: string = `${PACKAGE_ROOT}/temp/catalog-sync-test-repo`;
1716
const pnpmConfigPath: string = `${testRepoPath}/common/config/rush/pnpm-config.json`;
1817
const pnpmWorkspacePath: string = `${testRepoPath}/common/temp/pnpm-workspace.yaml`;
1918

2019
beforeEach(async () => {
2120
await FileSystem.copyFilesAsync({ sourcePath: CATALOG_SYNC_REPO_PATH, destinationPath: testRepoPath });
22-
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-
});
2821
});
2922

3023
afterEach(async () => {
@@ -58,7 +51,6 @@ catalogs:
5851
}
5952
});
6053

61-
const { PnpmWorkspaceFile } = require('../../logic/pnpm/PnpmWorkspaceFile');
6254
const newCatalogs = await PnpmWorkspaceFile.loadCatalogsFromFileAsync(pnpmWorkspacePath);
6355

6456
await pnpmOptions?.updateGlobalCatalogsAsync(newCatalogs);
@@ -82,7 +74,6 @@ catalogs:
8274
});
8375

8476
it('does not update pnpm-config.json when catalogs are unchanged', async () => {
85-
const { PnpmWorkspaceFile } = require('../../logic/pnpm/PnpmWorkspaceFile');
8677
const newCatalogs = await PnpmWorkspaceFile.loadCatalogsFromFileAsync(pnpmWorkspacePath);
8778

8879
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromConfigurationFile(
@@ -108,7 +99,6 @@ catalogs:
10899
`;
109100
await FileSystem.writeFileAsync(pnpmWorkspacePath, workspaceWithoutCatalogs);
110101

111-
const { PnpmWorkspaceFile } = require('../../logic/pnpm/PnpmWorkspaceFile');
112102
const newCatalogs = await PnpmWorkspaceFile.loadCatalogsFromFileAsync(pnpmWorkspacePath);
113103

114104
expect(newCatalogs).toBeUndefined();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!temp

libraries/rush-lib/src/cli/test/catalogSyncTestRepo/pnpm-workspace.yaml renamed to libraries/rush-lib/src/cli/test/catalogSyncTestRepo/common/temp/pnpm-workspace.yaml

File renamed without changes.

libraries/rush-lib/src/logic/pnpm/test/PnpmOptionsConfiguration.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import * as path from 'node:path';
55
import { FileSystem, JsonFile } from '@rushstack/node-core-library';
66
import { PnpmOptionsConfiguration } from '../PnpmOptionsConfiguration';
77
import { TestUtilities } from '@rushstack/heft-config-file';
8-
import { RushConfiguration } from '../../../api/RushConfiguration';
98

10-
const MONOREPO_ROOT: string = path.dirname(
11-
RushConfiguration.tryFindRushJsonLocation({ startingFolder: __dirname })!
12-
);
13-
const TEST_TEMP_FOLDER: string = `${MONOREPO_ROOT}/temp/pnpm-config-update-test`;
9+
const PACKAGE_ROOT: string = path.resolve(__dirname, '../../../..');
10+
const TEST_TEMP_FOLDER: string = `${PACKAGE_ROOT}/temp/pnpm-config-update-test`;
1411

1512
const fakeCommonTempFolder: string = `${__dirname}/common/temp`;
1613

libraries/rush-lib/src/logic/pnpm/test/PnpmWorkspaceFile.test.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ describe(PnpmWorkspaceFile.name, () => {
1414
let mockReadFile: jest.SpyInstance;
1515
let mockReadFileAsync: jest.SpyInstance;
1616
let mockExists: jest.SpyInstance;
17-
let mockExistsAsync: jest.SpyInstance;
1817
let writtenContent: string | undefined;
1918

2019
beforeEach(() => {
@@ -31,15 +30,23 @@ describe(PnpmWorkspaceFile.name, () => {
3130
// Mock FileSystem.readFile to return the written content
3231
mockReadFile = jest.spyOn(FileSystem, 'readFile').mockImplementation(() => {
3332
if (writtenContent === undefined) {
34-
throw Object.assign(new Error('ENOENT: no such file or directory'), { code: 'ENOENT', errno: -2, syscall: 'open' });
33+
throw Object.assign(new Error('ENOENT: no such file or directory'), {
34+
code: 'ENOENT',
35+
errno: -2,
36+
syscall: 'open'
37+
});
3538
}
3639
return writtenContent;
3740
});
3841

3942
// Mock async version for loadCatalogsFromFileAsync
4043
mockReadFileAsync = jest.spyOn(FileSystem, 'readFileAsync').mockImplementation(async () => {
4144
if (writtenContent === undefined) {
42-
throw Object.assign(new Error('ENOENT: no such file or directory'), { code: 'ENOENT', errno: -2, syscall: 'open' });
45+
throw Object.assign(new Error('ENOENT: no such file or directory'), {
46+
code: 'ENOENT',
47+
errno: -2,
48+
syscall: 'open'
49+
});
4350
}
4451
return writtenContent;
4552
});
@@ -48,19 +55,13 @@ describe(PnpmWorkspaceFile.name, () => {
4855
mockExists = jest.spyOn(FileSystem, 'exists').mockImplementation(() => {
4956
return writtenContent !== undefined;
5057
});
51-
52-
// Mock async version for loadCatalogsFromFileAsync
53-
mockExistsAsync = jest.spyOn(FileSystem, 'existsAsync').mockImplementation(async () => {
54-
return writtenContent !== undefined;
55-
});
5658
});
5759

5860
afterEach(() => {
5961
mockWriteFile.mockRestore();
6062
mockReadFile.mockRestore();
6163
mockReadFileAsync.mockRestore();
6264
mockExists.mockRestore();
63-
mockExistsAsync.mockRestore();
6465
});
6566

6667
describe('basic functionality', () => {

0 commit comments

Comments
 (0)