scaffolder-backend: refactor delete action tests to avoid mock-fs
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
+5
-10
@@ -18,18 +18,17 @@ import { createFilesystemDeleteAction } from './delete';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import * as os from 'os';
|
||||
import mockFs from 'mock-fs';
|
||||
import fs from 'fs-extra';
|
||||
import yaml from 'yaml';
|
||||
import { examples } from './delete.examples';
|
||||
|
||||
const root = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir';
|
||||
const workspacePath = resolvePath(root, 'my-workspace');
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
|
||||
describe('fs:delete examples', () => {
|
||||
const action = createFilesystemDeleteAction();
|
||||
|
||||
const mockDir = createMockDirectory();
|
||||
const workspacePath = resolvePath(mockDir.path, 'workspace');
|
||||
|
||||
const files: string[] = yaml.parse(examples[0].example).steps[0].input.files;
|
||||
|
||||
const mockContext = {
|
||||
@@ -46,7 +45,7 @@ describe('fs:delete examples', () => {
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
|
||||
mockFs({
|
||||
mockDir.setContent({
|
||||
[workspacePath]: {
|
||||
[files[0]]: 'hello',
|
||||
[files[1]]: 'world',
|
||||
@@ -57,10 +56,6 @@ describe('fs:delete examples', () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it('should call fs.rm with the correct values', async () => {
|
||||
files.forEach(file => {
|
||||
const filePath = resolvePath(workspacePath, file);
|
||||
|
||||
+5
-10
@@ -14,20 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as os from 'os';
|
||||
import mockFs from 'mock-fs';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { createFilesystemDeleteAction } from './delete';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const root = os.platform() === 'win32' ? 'C:\\rootDir' : '/rootDir';
|
||||
const workspacePath = resolvePath(root, 'my-workspace');
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
|
||||
describe('fs:delete', () => {
|
||||
const action = createFilesystemDeleteAction();
|
||||
|
||||
const mockDir = createMockDirectory();
|
||||
const workspacePath = resolvePath(mockDir.path, 'workspace');
|
||||
|
||||
const mockContext = {
|
||||
input: {
|
||||
files: ['unit-test-a.js', 'unit-test-b.js'],
|
||||
@@ -42,7 +41,7 @@ describe('fs:delete', () => {
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
|
||||
mockFs({
|
||||
mockDir.setContent({
|
||||
[workspacePath]: {
|
||||
'unit-test-a.js': 'hello',
|
||||
'unit-test-b.js': 'world',
|
||||
@@ -53,10 +52,6 @@ describe('fs:delete', () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it('should throw an error when files is not an array', async () => {
|
||||
await expect(
|
||||
action.handler({
|
||||
|
||||
Reference in New Issue
Block a user