scaffolder-backend: refactor rename action example tests to avoid mock-fs

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-05 17:27:45 +02:00
parent 0fca639626
commit b95b05baeb
@@ -14,8 +14,6 @@
* limitations under the License.
*/
import * as os from 'os';
import mockFs from 'mock-fs';
import { resolve as resolvePath } from 'path';
import { createFilesystemRenameAction } from './rename';
import { getVoidLogger } from '@backstage/backend-common';
@@ -23,15 +21,16 @@ import { PassThrough } from 'stream';
import fs from 'fs-extra';
import yaml from 'yaml';
import { examples } from './rename.examples';
const root = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir';
const workspacePath = resolvePath(root, 'my-workspace');
import { createMockDirectory } from '@backstage/backend-test-utils';
describe('fs:rename examples', () => {
const action = createFilesystemRenameAction();
const files: { from: string; to: string }[] = yaml.parse(examples[0].example)
.steps[0].input.files;
const mockDir = createMockDirectory();
const workspacePath = resolvePath(mockDir.path, 'workspace');
const mockContext = {
input: {
files: files,
@@ -46,7 +45,7 @@ describe('fs:rename examples', () => {
beforeEach(() => {
jest.restoreAllMocks();
mockFs({
mockDir.setContent({
[workspacePath]: {
[files[0].from]: 'hello',
[files[1].from]: 'world',
@@ -59,10 +58,6 @@ describe('fs:rename examples', () => {
});
});
afterEach(() => {
mockFs.restore();
});
it('should call fs.move with the correct values', async () => {
mockContext.input.files.forEach(file => {
const filePath = resolvePath(workspacePath, file.from);