Merge pull request #20650 from anicke/cookiecutter-mockfs
Scaffolder/cookiecutter: Remove usage of mock-fs
This commit is contained in:
@@ -41,11 +41,10 @@
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@types/command-exists": "^1.2.0",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/mock-fs": "^4.13.0",
|
||||
"mock-fs": "^5.2.0",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
+8
-19
@@ -22,8 +22,7 @@ import {
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import mockFs from 'mock-fs';
|
||||
import os from 'os';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createFetchCookiecutterAction } from './cookiecutter';
|
||||
import { join } from 'path';
|
||||
@@ -47,6 +46,7 @@ jest.mock(
|
||||
);
|
||||
|
||||
describe('fetch:cookiecutter', () => {
|
||||
const mockDir = createMockDirectory({ mockOsTmpDir: true });
|
||||
const integrations = ScmIntegrations.fromConfig(
|
||||
new ConfigReader({
|
||||
integrations: {
|
||||
@@ -58,7 +58,7 @@ describe('fetch:cookiecutter', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const mockTmpDir = os.tmpdir();
|
||||
const mockTmpDir = mockDir.path;
|
||||
|
||||
let mockContext: ActionContext<{
|
||||
url: string;
|
||||
@@ -106,36 +106,25 @@ describe('fetch:cookiecutter', () => {
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn().mockResolvedValue(mockTmpDir),
|
||||
};
|
||||
|
||||
// mock the temp directory
|
||||
mockFs({ [mockTmpDir]: {} });
|
||||
mockFs({ [`${join(mockTmpDir, 'template')}`]: {} });
|
||||
mockDir.setContent({ template: {} });
|
||||
|
||||
commandExists.mockResolvedValue(null);
|
||||
|
||||
// Mock when run container is called it creates some new files in the mock filesystem
|
||||
containerRunner.runContainer.mockImplementation(async () => {
|
||||
mockFs({
|
||||
[`${join(mockTmpDir, 'intermediate')}`]: {
|
||||
'testfile.json': '{}',
|
||||
},
|
||||
mockDir.setContent({
|
||||
'intermediate/testfile.json': '{}',
|
||||
});
|
||||
});
|
||||
|
||||
// Mock when executeShellCommand is called it creates some new files in the mock filesystem
|
||||
executeShellCommand.mockImplementation(async () => {
|
||||
mockFs({
|
||||
[`${join(mockTmpDir, 'intermediate')}`]: {
|
||||
'testfile.json': '{}',
|
||||
},
|
||||
mockDir.setContent({
|
||||
'intermediate/testfile.json': '{}',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it('should throw an error when copyWithoutRender is not an array', async () => {
|
||||
(mockContext.input as any).copyWithoutRender = 'not an array';
|
||||
|
||||
|
||||
@@ -8458,6 +8458,7 @@ __metadata:
|
||||
resolution: "@backstage/plugin-scaffolder-backend-module-cookiecutter@workspace:plugins/scaffolder-backend-module-cookiecutter"
|
||||
dependencies:
|
||||
"@backstage/backend-common": "workspace:^"
|
||||
"@backstage/backend-test-utils": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/config": "workspace:^"
|
||||
"@backstage/errors": "workspace:^"
|
||||
@@ -8466,10 +8467,8 @@ __metadata:
|
||||
"@backstage/types": "workspace:^"
|
||||
"@types/command-exists": ^1.2.0
|
||||
"@types/fs-extra": ^9.0.1
|
||||
"@types/mock-fs": ^4.13.0
|
||||
command-exists: ^1.2.9
|
||||
fs-extra: 10.1.0
|
||||
mock-fs: ^5.2.0
|
||||
msw: ^1.0.0
|
||||
winston: ^3.2.1
|
||||
yn: ^4.0.0
|
||||
|
||||
Reference in New Issue
Block a user