diff --git a/packages/cli/src/commands/create-plugin/createPlugin.test.ts b/packages/cli/src/commands/create-plugin/createPlugin.test.ts index 012dc2be13..aa59f94fb4 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.test.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.test.ts @@ -22,7 +22,7 @@ import { movePlugin } from './createPlugin'; const id = 'testPluginMock'; describe('createPlugin', () => { - afterAll(() => { + afterEach(() => { mockFs.restore(); }); diff --git a/packages/cli/src/commands/versions/bump.test.ts b/packages/cli/src/commands/versions/bump.test.ts index e1b06877de..9e5288677d 100644 --- a/packages/cli/src/commands/versions/bump.test.ts +++ b/packages/cli/src/commands/versions/bump.test.ts @@ -122,10 +122,12 @@ describe('bump', () => { }, })); }); + afterEach(() => { mockFs.restore(); jest.resetAllMocks(); }); + const worker = setupServer(); setupRequestMockHandlers(worker); diff --git a/packages/create-app/src/createApp.test.ts b/packages/create-app/src/createApp.test.ts index f4c94d337a..f455efa6e6 100644 --- a/packages/create-app/src/createApp.test.ts +++ b/packages/create-app/src/createApp.test.ts @@ -42,7 +42,7 @@ const moveAppMock = jest.spyOn(tasks, 'moveAppTask'); const buildAppMock = jest.spyOn(tasks, 'buildAppTask'); describe('command entrypoint', () => { - beforeAll(() => { + beforeEach(() => { mockFs({ [`${__dirname}/package.json`]: '', // required by `findPaths(__dirname)` 'templates/': mockFs.load(path.resolve(__dirname, '../templates/')), 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 7121d8a06f..6139b5b782 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 @@ -87,7 +87,8 @@ describe('buildApiReports', () => { mockFs.restore(); jest.clearAllMocks(); }); - it('should run whitout any options', async () => { + + it('should run without any options', async () => { const opts = {}; const paths: string[] = []; diff --git a/plugins/app-backend/src/service/appPlugin.test.ts b/plugins/app-backend/src/service/appPlugin.test.ts index 8583726287..14921622c9 100644 --- a/plugins/app-backend/src/service/appPlugin.test.ts +++ b/plugins/app-backend/src/service/appPlugin.test.ts @@ -30,7 +30,7 @@ import { ConfigReader } from '@backstage/config'; import getPort from 'get-port'; describe('appPlugin', () => { - beforeAll(() => { + beforeEach(() => { mockFs({ [resolvePath(process.cwd(), 'node_modules/app')]: { 'package.json': '{}', @@ -42,7 +42,7 @@ describe('appPlugin', () => { }); }); - afterAll(() => { + afterEach(() => { mockFs.restore(); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts index 544784acb5..c53caff018 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/debug/log.test.ts @@ -15,7 +15,7 @@ */ import { getVoidLogger } from '@backstage/backend-common'; -import mock from 'mock-fs'; +import mockFs from 'mock-fs'; import os from 'os'; import { Writable } from 'stream'; import { createDebugLogAction } from './log'; @@ -40,7 +40,7 @@ describe('debug:log', () => { const action = createDebugLogAction(); beforeEach(() => { - mock({ + mockFs({ [`${mockContext.workspacePath}/README.md`]: '', [`${mockContext.workspacePath}/a-directory/index.md`]: '', }); @@ -48,7 +48,7 @@ describe('debug:log', () => { }); afterEach(() => { - mock.restore(); + mockFs.restore(); }); it('should do nothing', async () => { diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index b98a219eac..e894b0602e 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -89,6 +89,10 @@ const rootDir = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir'; const scmIntegrations = ScmIntegrations.fromConfig(new ConfigReader({})); describe('helpers', () => { + afterEach(() => { + mockFs.restore(); + }); + describe('getGeneratorKey', () => { it('should return techdocs as the only generator key', () => { const key = getGeneratorKey(mockEntity); @@ -189,10 +193,6 @@ describe('helpers', () => { }); }); - afterEach(() => { - mockFs.restore(); - }); - it('should add edit_uri to mkdocs.yml', async () => { const parsedLocationAnnotation: ParsedLocationAnnotation = { type: 'url', @@ -375,7 +375,6 @@ describe('helpers', () => { 'index.md content', ); expect(warn).not.toHaveBeenCalledWith(); - mockFs.restore(); }); it("should use docs/README.md if docs/index.md doesn't exists", async () => { @@ -392,7 +391,6 @@ describe('helpers', () => { expect(warn.mock.calls).toEqual([ [`${path.normalize('docs/index.md')} not found.`], ]); - mockFs.restore(); }); it('should use README.md if neither docs/index.md or docs/README.md exist', async () => { @@ -410,7 +408,6 @@ describe('helpers', () => { [`${path.normalize('docs/README.md')} not found.`], [`${path.normalize('docs/readme.md')} not found.`], ]); - mockFs.restore(); }); it('should not use any file as index.md if no one matches the requirements', async () => { @@ -434,7 +431,6 @@ describe('helpers', () => { .join(' ')} exists.`, ], ]); - mockFs.restore(); }); }); @@ -445,16 +441,11 @@ describe('helpers', () => { }; beforeEach(() => { - mockFs.restore(); mockFs({ [rootDir]: mockFiles, }); }); - afterEach(() => { - mockFs.restore(); - }); - it('should create the file if it does not exist', async () => { const filePath = path.join(rootDir, 'wrong_techdocs_metadata.json'); await createOrUpdateMetadata(filePath, mockLogger); @@ -495,7 +486,6 @@ describe('helpers', () => { describe('storeEtagMetadata', () => { beforeEach(() => { - mockFs.restore(); mockFs({ [rootDir]: { 'invalid_techdocs_metadata.json': 'dsds', @@ -504,10 +494,6 @@ describe('helpers', () => { }); }); - afterEach(() => { - mockFs.restore(); - }); - it('should throw error when the JSON is invalid', async () => { const filePath = path.join(rootDir, 'invalid_techdocs_metadata.json'); @@ -527,10 +513,6 @@ describe('helpers', () => { }); describe('getMkdocsYml', () => { - afterEach(() => { - mockFs.restore(); - }); - const inputDir = resolvePath(__filename, '../__fixtures__/'); it('returns expected contents when .yml file is present', async () => { diff --git a/plugins/techdocs-node/src/stages/publish/azureBlobStorage.test.ts b/plugins/techdocs-node/src/stages/publish/azureBlobStorage.test.ts index 6d5848b0d8..a392d3c172 100644 --- a/plugins/techdocs-node/src/stages/publish/azureBlobStorage.test.ts +++ b/plugins/techdocs-node/src/stages/publish/azureBlobStorage.test.ts @@ -530,10 +530,6 @@ describe('AzureBlobStoragePublish', () => { app = express().use(publisher.docsRouter()); }); - afterEach(() => { - mockFs.restore(); - }); - it('should pass expected object path to bucket', async () => { // Ensures leading slash is trimmed and encoded path is decoded. const pngResponse = await request(app).get( diff --git a/plugins/techdocs-node/src/stages/publish/local.test.ts b/plugins/techdocs-node/src/stages/publish/local.test.ts index f2f2b1e526..c1a5f02d67 100644 --- a/plugins/techdocs-node/src/stages/publish/local.test.ts +++ b/plugins/techdocs-node/src/stages/publish/local.test.ts @@ -85,8 +85,6 @@ describe('local publisher', () => { // Lower/upper should be treated the same. expect(await publisher.hasDocsBeenGenerated(lowerMockEntity)).toBe(true); - - mockFs.restore(); }); it('should respect legacy casing', async () => { @@ -110,8 +108,6 @@ describe('local publisher', () => { // Lower/upper should be treated differently. expect(await publisher.hasDocsBeenGenerated(lowerMockEntity)).toBe(false); - - mockFs.restore(); }); it('should throw with unsafe triplet', async () => { @@ -169,8 +165,6 @@ describe('local publisher', () => { beforeEach(() => { app = express().use(publisher.docsRouter()); - - mockFs.restore(); mockFs({ [resolvedDir]: { 'unsafe.html': '', diff --git a/plugins/techdocs-node/src/stages/publish/openStackSwift.test.ts b/plugins/techdocs-node/src/stages/publish/openStackSwift.test.ts index b183065230..49e68080df 100644 --- a/plugins/techdocs-node/src/stages/publish/openStackSwift.test.ts +++ b/plugins/techdocs-node/src/stages/publish/openStackSwift.test.ts @@ -173,7 +173,6 @@ const logger = getVoidLogger(); let publisher: PublisherBase; beforeEach(() => { - mockFs.restore(); const mockConfig = new ConfigReader({ techdocs: { publisher: { @@ -194,6 +193,10 @@ beforeEach(() => { publisher = OpenStackSwiftPublish.fromConfig(mockConfig, logger); }); +afterEach(() => { + mockFs.restore(); +}); + describe('OpenStackSwiftPublish', () => { describe('getReadiness', () => { it('should validate correct config', async () => { @@ -247,10 +250,6 @@ describe('OpenStackSwiftPublish', () => { }); }); - afterEach(() => { - mockFs.restore(); - }); - it('should publish a directory', async () => { const entity = createMockEntity(); const entityRootDir = getEntityRootDir(entity); @@ -301,8 +300,6 @@ describe('OpenStackSwiftPublish', () => { await expect(fails).rejects.toMatchObject({ message: expect.stringContaining(wrongPathToGeneratedDirectory), }); - - mockFs.restore(); }); }); @@ -318,7 +315,6 @@ describe('OpenStackSwiftPublish', () => { }); expect(await publisher.hasDocsBeenGenerated(entity)).toBe(true); - mockFs.restore(); }); it('should return false if docs has not been generated', async () => { @@ -350,7 +346,6 @@ describe('OpenStackSwiftPublish', () => { expect( await publisher.fetchTechDocsMetadata(entityNameMock), ).toStrictEqual(expectedMetadata); - mockFs.restore(); }); it('should return tech docs metadata when json encoded with single quotes', async () => { @@ -373,7 +368,6 @@ describe('OpenStackSwiftPublish', () => { expect( await publisher.fetchTechDocsMetadata(entityNameMock), ).toStrictEqual(expectedMetadata); - mockFs.restore(); }); it('should return an error if the techdocs_metadata.json file is not present', async () => { @@ -399,8 +393,6 @@ describe('OpenStackSwiftPublish', () => { beforeEach(() => { app = express().use(publisher.docsRouter()); - - mockFs.restore(); mockFs({ [entityRootDir]: { html: { @@ -417,10 +409,6 @@ describe('OpenStackSwiftPublish', () => { }); }); - afterEach(() => { - mockFs.restore(); - }); - it('should pass expected object path to bucket', async () => { const { kind,