From 6f279f9b8eebf4cea506baea2c6bca733de290c6 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 16 Nov 2021 01:52:56 +0100 Subject: [PATCH] cli: fix failing create tests on windows Signed-off-by: Patrik Oldsberg --- .../src/lib/create/factories/backendPlugin.test.ts | 9 +++++---- .../src/lib/create/factories/common/tasks.test.ts | 5 +++-- .../cli/src/lib/create/factories/common/tasks.ts | 4 ++-- .../src/lib/create/factories/frontendPlugin.test.ts | 13 +++++++------ .../src/lib/create/factories/pluginCommon.test.ts | 9 +++++---- .../lib/create/factories/scaffolderModule.test.ts | 9 +++++---- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/cli/src/lib/create/factories/backendPlugin.test.ts b/packages/cli/src/lib/create/factories/backendPlugin.test.ts index 916ba7187c..6f4a73c02d 100644 --- a/packages/cli/src/lib/create/factories/backendPlugin.test.ts +++ b/packages/cli/src/lib/create/factories/backendPlugin.test.ts @@ -16,6 +16,7 @@ import fs from 'fs-extra'; import mockFs from 'mock-fs'; +import { sep, resolve as resolvePath } from 'path'; import { paths } from '../../paths'; import { Task } from '../../tasks'; import { FactoryRegistry } from '../FactoryRegistry'; @@ -75,7 +76,7 @@ describe('backendPlugin factory', () => { '', 'Creating backend plugin backstage-plugin-test-backend', 'Checking Prerequisites:', - 'availability plugins/test-backend', + `availability plugins${sep}test-backend`, 'creating temp dir', 'Executing Template:', 'copying .eslintrc.js', @@ -89,7 +90,7 @@ describe('backendPlugin factory', () => { 'copying router.ts', 'templating standaloneServer.ts.hbs', 'Installing:', - 'moving plugins/test-backend', + `moving plugins${sep}test-backend`, 'backend adding dependency', ]); @@ -103,11 +104,11 @@ describe('backendPlugin factory', () => { expect(Task.forCommand).toHaveBeenCalledTimes(2); expect(Task.forCommand).toHaveBeenCalledWith('yarn install', { - cwd: '/root/plugins/test-backend', + cwd: resolvePath('/root/plugins/test-backend'), optional: true, }); expect(Task.forCommand).toHaveBeenCalledWith('yarn lint --fix', { - cwd: '/root/plugins/test-backend', + cwd: resolvePath('/root/plugins/test-backend'), optional: true, }); }); diff --git a/packages/cli/src/lib/create/factories/common/tasks.test.ts b/packages/cli/src/lib/create/factories/common/tasks.test.ts index 0892322e61..49381676e7 100644 --- a/packages/cli/src/lib/create/factories/common/tasks.test.ts +++ b/packages/cli/src/lib/create/factories/common/tasks.test.ts @@ -16,6 +16,7 @@ import fs from 'fs-extra'; import mockFs from 'mock-fs'; +import { sep } from 'path'; import { createMockOutputStream, mockPaths } from './testUtils'; import { CreateContext } from '../../types'; import { executePluginPackageTemplate } from './tasks'; @@ -88,14 +89,14 @@ some-package@^1.1.0: expect(modified).toBe(true); expect(output).toEqual([ 'Checking Prerequisites:', - 'availability /target', + `availability ..${sep}target`, 'creating temp dir', 'Executing Template:', 'templating package.json.hbs', 'copying not-templated.txt', 'templating templated.txt.hbs', 'Installing:', - 'moving /target', + `moving ..${sep}target`, ]); await expect(fs.readFile('/target/package.json', 'utf8')).resolves.toBe(`{ "name": "my-testing-plugin", diff --git a/packages/cli/src/lib/create/factories/common/tasks.ts b/packages/cli/src/lib/create/factories/common/tasks.ts index fd3bd4d930..93af1e2b00 100644 --- a/packages/cli/src/lib/create/factories/common/tasks.ts +++ b/packages/cli/src/lib/create/factories/common/tasks.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import chalk from 'chalk'; -import { resolve as resolvePath } from 'path'; +import { resolve as resolvePath, relative as relativePath } from 'path'; import { paths } from '../../../paths'; import { Task, templatingTask } from '../../../tasks'; import { Lockfile } from '../../../versioning'; @@ -41,7 +41,7 @@ export async function executePluginPackageTemplate( } Task.section('Checking Prerequisites'); - const shortPluginDir = targetDir.replace(`${paths.targetRoot}/`, ''); + const shortPluginDir = relativePath(paths.targetRoot, targetDir); await Task.forItem('availability', shortPluginDir, async () => { if (await fs.pathExists(targetDir)) { throw new Error( diff --git a/packages/cli/src/lib/create/factories/frontendPlugin.test.ts b/packages/cli/src/lib/create/factories/frontendPlugin.test.ts index 439b134478..27ee14ea2c 100644 --- a/packages/cli/src/lib/create/factories/frontendPlugin.test.ts +++ b/packages/cli/src/lib/create/factories/frontendPlugin.test.ts @@ -16,6 +16,7 @@ import fs from 'fs-extra'; import mockFs from 'mock-fs'; +import { sep, resolve as resolvePath } from 'path'; import { paths } from '../../paths'; import { Task } from '../../tasks'; import { FactoryRegistry } from '../FactoryRegistry'; @@ -88,7 +89,7 @@ describe('frontendPlugin factory', () => { '', 'Creating backend plugin backstage-plugin-test', 'Checking Prerequisites:', - 'availability plugins/test', + `availability plugins${sep}test`, 'creating temp dir', 'Executing Template:', 'copying .eslintrc.js', @@ -108,7 +109,7 @@ describe('frontendPlugin factory', () => { 'templating ExampleFetchComponent.tsx.hbs', 'copying index.ts', 'Installing:', - 'moving plugins/test', + `moving plugins${sep}test`, 'app adding dependency', 'app adding import', ]); @@ -136,11 +137,11 @@ const router = ( expect(Task.forCommand).toHaveBeenCalledTimes(2); expect(Task.forCommand).toHaveBeenCalledWith('yarn install', { - cwd: '/root/plugins/test', + cwd: resolvePath('/root/plugins/test'), optional: true, }); expect(Task.forCommand).toHaveBeenCalledWith('yarn lint --fix', { - cwd: '/root/plugins/test', + cwd: resolvePath('/root/plugins/test'), optional: true, }); }); @@ -205,11 +206,11 @@ const router = ( expect(Task.forCommand).toHaveBeenCalledTimes(2); expect(Task.forCommand).toHaveBeenCalledWith('yarn install', { - cwd: '/root/plugins/test', + cwd: resolvePath('/root/plugins/test'), optional: true, }); expect(Task.forCommand).toHaveBeenCalledWith('yarn lint --fix', { - cwd: '/root/plugins/test', + cwd: resolvePath('/root/plugins/test'), optional: true, }); }); diff --git a/packages/cli/src/lib/create/factories/pluginCommon.test.ts b/packages/cli/src/lib/create/factories/pluginCommon.test.ts index 3124df6b1d..602fce7bbd 100644 --- a/packages/cli/src/lib/create/factories/pluginCommon.test.ts +++ b/packages/cli/src/lib/create/factories/pluginCommon.test.ts @@ -16,6 +16,7 @@ import fs from 'fs-extra'; import mockFs from 'mock-fs'; +import { sep, resolve as resolvePath } from 'path'; import { paths } from '../../paths'; import { Task } from '../../tasks'; import { FactoryRegistry } from '../FactoryRegistry'; @@ -70,7 +71,7 @@ describe('pluginCommon factory', () => { '', 'Creating backend plugin backstage-plugin-test-common', 'Checking Prerequisites:', - 'availability plugins/test-common', + `availability plugins${sep}test-common`, 'creating temp dir', 'Executing Template:', 'copying .eslintrc.js', @@ -80,7 +81,7 @@ describe('pluginCommon factory', () => { 'templating index.ts.hbs', 'copying setupTests.ts', 'Installing:', - 'moving plugins/test-common', + `moving plugins${sep}test-common`, ]); await expect( @@ -96,11 +97,11 @@ describe('pluginCommon factory', () => { expect(Task.forCommand).toHaveBeenCalledTimes(2); expect(Task.forCommand).toHaveBeenCalledWith('yarn install', { - cwd: '/root/plugins/test-common', + cwd: resolvePath('/root/plugins/test-common'), optional: true, }); expect(Task.forCommand).toHaveBeenCalledWith('yarn lint --fix', { - cwd: '/root/plugins/test-common', + cwd: resolvePath('/root/plugins/test-common'), optional: true, }); }); diff --git a/packages/cli/src/lib/create/factories/scaffolderModule.test.ts b/packages/cli/src/lib/create/factories/scaffolderModule.test.ts index a5f1f8e63a..c60c58e619 100644 --- a/packages/cli/src/lib/create/factories/scaffolderModule.test.ts +++ b/packages/cli/src/lib/create/factories/scaffolderModule.test.ts @@ -16,6 +16,7 @@ import fs from 'fs-extra'; import mockFs from 'mock-fs'; +import { sep, resolve as resolvePath } from 'path'; import { paths } from '../../paths'; import { Task } from '../../tasks'; import { FactoryRegistry } from '../FactoryRegistry'; @@ -70,7 +71,7 @@ describe('scaffolderModule factory', () => { '', 'Creating module backstage-plugin-scaffolder-backend-module-test', 'Checking Prerequisites:', - 'availability plugins/scaffolder-backend-module-test', + `availability plugins${sep}scaffolder-backend-module-test`, 'creating temp dir', 'Executing Template:', 'copying .eslintrc.js', @@ -83,7 +84,7 @@ describe('scaffolderModule factory', () => { 'copying example.ts', 'copying index.ts', 'Installing:', - 'moving plugins/scaffolder-backend-module-test', + `moving plugins${sep}scaffolder-backend-module-test`, ]); await expect( @@ -99,11 +100,11 @@ describe('scaffolderModule factory', () => { expect(Task.forCommand).toHaveBeenCalledTimes(2); expect(Task.forCommand).toHaveBeenCalledWith('yarn install', { - cwd: '/root/plugins/scaffolder-backend-module-test', + cwd: resolvePath('/root/plugins/scaffolder-backend-module-test'), optional: true, }); expect(Task.forCommand).toHaveBeenCalledWith('yarn lint --fix', { - cwd: '/root/plugins/scaffolder-backend-module-test', + cwd: resolvePath('/root/plugins/scaffolder-backend-module-test'), optional: true, }); });