diff --git a/packages/repo-tools/package.json b/packages/repo-tools/package.json index 987bfb9260..0e9da31e27 100644 --- a/packages/repo-tools/package.json +++ b/packages/repo-tools/package.json @@ -63,13 +63,12 @@ "yaml-diff-patch": "^2.0.0" }, "devDependencies": { + "@backstage/backend-test-utils": "workspace:^", "@backstage/cli": "workspace:^", "@backstage/types": "workspace:^", "@types/is-glob": "^4.0.2", - "@types/mock-fs": "^4.13.0", "@types/node": "^18.17.8", - "@types/prettier": "^2.0.0", - "mock-fs": "^5.2.0" + "@types/prettier": "^2.0.0" }, "peerDependencies": { "@microsoft/api-extractor-model": "*", diff --git a/packages/repo-tools/src/commands/api-reports/api-reports.test.ts b/packages/repo-tools/src/commands/api-reports/api-reports.test.ts index 0ffd8c5342..d1f7a3836c 100644 --- a/packages/repo-tools/src/commands/api-reports/api-reports.test.ts +++ b/packages/repo-tools/src/commands/api-reports/api-reports.test.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import mockFs from 'mock-fs'; -import { normalize, resolve as resolvePath } from 'path'; +import { createMockDirectory } from '@backstage/backend-test-utils'; +import { normalize } from 'path'; import * as pathsLib from '../../lib/paths'; import { @@ -47,38 +47,38 @@ jest.mock('./api-extractor', () => ({ const projectPaths = pathsLib.paths; +const mockDir = createMockDirectory(); + +jest.spyOn(projectPaths, 'targetRoot', 'get').mockReturnValue(mockDir.path); jest - .spyOn(projectPaths, 'targetRoot', 'get') - .mockReturnValue(normalize('/root')); -jest.spyOn(projectPaths, 'resolveTargetRoot').mockImplementation((...path) => { - return resolvePath(normalize('/root'), ...path); -}); + .spyOn(projectPaths, 'resolveTargetRoot') + .mockImplementation((...path) => mockDir.resolve(...path)); jest.spyOn(PackageGraph, 'listTargetPackages').mockResolvedValue([ { - dir: '/root/packages/package-a', + dir: normalize(mockDir.resolve('packages/package-a')), packageJson: { name: 'package-a', version: '0.0.0' }, }, { - dir: '/root/packages/package-b', + dir: normalize(mockDir.resolve('packages/package-b')), packageJson: { name: 'package-b', version: '0.0.0' }, }, { - dir: '/root/plugins/plugin-a', + dir: normalize(mockDir.resolve('plugins/plugin-a')), packageJson: { name: 'plugin-a', version: '0.0.0' }, }, { - dir: '/root/plugins/plugin-b', + dir: normalize(mockDir.resolve('plugins/plugin-b')), packageJson: { name: 'plugin-b', version: '0.0.0' }, }, { - dir: '/root/plugins/plugin-c', + dir: normalize(mockDir.resolve('plugins/plugin-c')), packageJson: { name: 'plugin-c', version: '0.0.0' }, }, ]); describe('buildApiReports', () => { beforeEach(() => { - mockFs({ + mockDir.setContent({ [projectPaths.targetRoot]: { 'package.json': JSON.stringify({ workspaces: { packages: ['packages/*', 'plugins/*'] }, @@ -109,7 +109,6 @@ describe('buildApiReports', () => { }); afterEach(() => { - mockFs.restore(); jest.clearAllMocks(); }); @@ -138,11 +137,11 @@ describe('buildApiReports', () => { normalize('plugins/plugin-b'), normalize('plugins/plugin-c'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); expect(runCliExtraction).toHaveBeenCalledWith({ packageDirs: [ @@ -171,11 +170,11 @@ describe('buildApiReports', () => { expect(runApiExtraction).toHaveBeenCalledWith({ packageDirs: [normalize('packages/package-a')], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); expect(runCliExtraction).toHaveBeenCalledWith({ packageDirs: [normalize('packages/package-a')], @@ -200,11 +199,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); expect(runCliExtraction).toHaveBeenCalledWith({ packageDirs: [ @@ -232,11 +231,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); expect(runCliExtraction).toHaveBeenCalledWith({ packageDirs: [ @@ -267,11 +266,11 @@ describe('buildApiReports', () => { normalize('packages/package-b'), normalize('plugins/plugin-a'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); expect(runCliExtraction).toHaveBeenCalledWith({ packageDirs: [ @@ -305,11 +304,11 @@ describe('buildApiReports', () => { normalize('plugins/plugin-b'), normalize('plugins/plugin-c'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); expect(runCliExtraction).toHaveBeenCalledWith({ packageDirs: [ @@ -338,11 +337,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: ['packages/package-a'], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); }); @@ -359,11 +358,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: ['packages/package-a', 'packages/package-b'], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); }); @@ -380,11 +379,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: ['packages/package-a', 'packages/package-b'], omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); }); }); @@ -402,11 +401,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: true, omitMessages: [], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); }); }); @@ -424,11 +423,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: ['ae-missing-release-tag'], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); }); @@ -445,11 +444,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: ['ae-missing-release-tag', 'ae-missing-annotations'], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); }); @@ -466,11 +465,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: ['ae-missing-release-tag', 'ae-missing-annotations'], isLocalBuild: true, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); }); }); @@ -488,11 +487,11 @@ describe('buildApiReports', () => { normalize('packages/package-a'), normalize('packages/package-b'), ], - tsconfigFilePath: resolvePath('/root/tsconfig.json'), + tsconfigFilePath: mockDir.resolve('tsconfig.json'), allowWarnings: [], omitMessages: [], isLocalBuild: false, - outputDir: resolvePath('/root/node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('node_modules/.cache/api-extractor'), }); expect(runCliExtraction).toHaveBeenCalledWith({ packageDirs: [ @@ -513,8 +512,8 @@ describe('buildApiReports', () => { await buildApiReports(paths, opts); expect(buildDocs).toHaveBeenCalledWith({ - inputDir: resolvePath('/root/node_modules/.cache/api-extractor'), - outputDir: resolvePath('/root/docs/reference'), + inputDir: mockDir.resolve('node_modules/.cache/api-extractor'), + outputDir: mockDir.resolve('docs/reference'), }); }); }); diff --git a/yarn.lock b/yarn.lock index ead69670d5..9e17153fd0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9589,6 +9589,7 @@ __metadata: "@apidevtools/swagger-parser": ^10.1.0 "@apisyouwonthate/style-guide": ^1.4.0 "@backstage/backend-common": "workspace:^" + "@backstage/backend-test-utils": "workspace:^" "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/cli-common": "workspace:^" @@ -9607,7 +9608,6 @@ __metadata: "@stoplight/spectral-runtime": ^1.1.2 "@stoplight/types": ^14.0.0 "@types/is-glob": ^4.0.2 - "@types/mock-fs": ^4.13.0 "@types/node": ^18.17.8 "@types/prettier": ^2.0.0 chalk: ^4.0.0 @@ -9619,7 +9619,6 @@ __metadata: js-yaml: ^4.1.0 lodash: ^4.17.21 minimatch: ^5.1.1 - mock-fs: ^5.2.0 p-limit: ^3.0.2 portfinder: ^1.0.32 ts-node: ^10.0.0 @@ -18320,7 +18319,7 @@ __metadata: languageName: node linkType: hard -"@types/mock-fs@npm:^4.10.0, @types/mock-fs@npm:^4.13.0": +"@types/mock-fs@npm:^4.10.0": version: 4.13.4 resolution: "@types/mock-fs@npm:4.13.4" dependencies: