import path instead of resolve

This commit is contained in:
Johan Haals
2021-01-29 13:51:46 +01:00
parent 0cb0715700
commit adaba84f3f
5 changed files with 23 additions and 24 deletions
@@ -16,7 +16,7 @@
import fs from 'fs-extra';
import os from 'os';
import { resolve } from 'path';
import path from 'path';
import { AzurePreparer } from './azure';
import { getVoidLogger, Git } from '@backstage/backend-common';
@@ -37,8 +37,8 @@ describe('AzurePreparer', () => {
});
const workspacePath = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
const checkoutPath = resolve(workspacePath, 'checkout');
const templatePath = resolve(workspacePath, 'template');
const checkoutPath = path.resolve(workspacePath, 'checkout');
const templatePath = path.resolve(workspacePath, 'template');
const prepareOptions = {
url:
'https://dev.azure.com/backstage-org/backstage-project/_git/template-repo',
@@ -54,7 +54,7 @@ describe('AzurePreparer', () => {
username: 'notempty',
});
expect(fs.move).toHaveBeenCalledWith(checkoutPath, templatePath);
expect(fs.rmdir).toHaveBeenCalledWith(resolve(templatePath, '.git'));
expect(fs.rmdir).toHaveBeenCalledWith(path.resolve(templatePath, '.git'));
});
it('calls the clone command with the correct arguments for a repository', async () => {
@@ -100,17 +100,16 @@ describe('AzurePreparer', () => {
});
it('moves the template from path if it is specified', async () => {
const path = './subdir';
await preparer.prepare({
url: `https://dev.azure.com/backstage-org/backstage-project/_git/template-repo?path=${encodeURIComponent(
path,
'./subdir',
)}`,
logger,
workspacePath,
});
expect(fs.move).toHaveBeenCalledWith(
resolve(checkoutPath, 'subdir'),
path.resolve(checkoutPath, 'subdir'),
templatePath,
);
});
@@ -17,7 +17,7 @@
import fs from 'fs-extra';
import { BitbucketPreparer } from './bitbucket';
import { getVoidLogger, Git } from '@backstage/backend-common';
import { resolve } from 'path';
import path from 'path';
import os from 'os';
jest.mock('fs-extra');
@@ -41,8 +41,8 @@ describe('BitbucketPreparer', () => {
});
const workspacePath = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
const checkoutPath = resolve(workspacePath, 'checkout');
const templatePath = resolve(workspacePath, 'template');
const checkoutPath = path.resolve(workspacePath, 'checkout');
const templatePath = path.resolve(workspacePath, 'template');
const prepareOptions = {
url: 'https://bitbucket.org/backstage-project/backstage-repo',
@@ -58,7 +58,7 @@ describe('BitbucketPreparer', () => {
ref: expect.any(String),
});
expect(fs.move).toHaveBeenCalledWith(checkoutPath, templatePath);
expect(fs.rmdir).toHaveBeenCalledWith(resolve(templatePath, '.git'));
expect(fs.rmdir).toHaveBeenCalledWith(path.resolve(templatePath, '.git'));
});
it('calls the clone command with the correct arguments if an app password is provided for a repository', async () => {
@@ -92,7 +92,7 @@ describe('BitbucketPreparer', () => {
workspacePath,
});
expect(fs.move).toHaveBeenCalledWith(
resolve(checkoutPath, '1', '2', '3'),
path.resolve(checkoutPath, '1', '2', '3'),
templatePath,
);
});
@@ -18,7 +18,7 @@ import { getVoidLogger } from '@backstage/backend-common';
import fs from 'fs-extra';
import { FilePreparer } from './file';
import os from 'os';
import path, { resolve } from 'path';
import path from 'path';
jest.mock('fs-extra');
@@ -27,7 +27,7 @@ describe('File preparer', () => {
const logger = getVoidLogger();
const preparer = new FilePreparer();
const workspacePath = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
const checkoutPath = resolve(workspacePath, 'checkout');
const checkoutPath = path.resolve(workspacePath, 'checkout');
await preparer.prepare({
url: 'file:///path/to/template',
@@ -16,7 +16,7 @@
import fs from 'fs-extra';
import os from 'os';
import { resolve } from 'path';
import path from 'path';
import { GithubPreparer } from './github';
import { getVoidLogger, Git } from '@backstage/backend-common';
@@ -24,8 +24,8 @@ jest.mock('fs-extra');
describe('GitHubPreparer', () => {
const workspacePath = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
const checkoutPath = resolve(workspacePath, 'checkout');
const templatePath = resolve(workspacePath, 'template');
const checkoutPath = path.resolve(workspacePath, 'checkout');
const templatePath = path.resolve(workspacePath, 'template');
const mockGitClient = {
clone: jest.fn(),
@@ -57,7 +57,7 @@ describe('GitHubPreparer', () => {
ref: expect.any(String),
});
expect(fs.move).toHaveBeenCalledWith(
resolve(checkoutPath, 'templates', 'graphql-starter', 'template'),
path.resolve(checkoutPath, 'templates', 'graphql-starter', 'template'),
templatePath,
);
expect(fs.rmdir).toHaveBeenCalledWith('/tmp/template/.git');
@@ -77,7 +77,7 @@ describe('GitHubPreparer', () => {
ref: 'master',
});
expect(fs.move).toHaveBeenCalledWith(checkoutPath, templatePath);
expect(fs.rmdir).toHaveBeenCalledWith(resolve(templatePath, '.git'));
expect(fs.rmdir).toHaveBeenCalledWith(path.resolve(templatePath, '.git'));
});
it('calls the clone command with token', async () => {
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import os from 'os';
import { resolve } from 'path';
import path from 'path';
import { GitlabPreparer } from './gitlab';
import { getVoidLogger, Git } from '@backstage/backend-common';
@@ -23,8 +23,8 @@ jest.mock('fs-extra');
describe('GitLabPreparer', () => {
const workspacePath = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
const checkoutPath = resolve(workspacePath, 'checkout');
const templatePath = resolve(workspacePath, 'template');
const checkoutPath = path.resolve(workspacePath, 'checkout');
const templatePath = path.resolve(workspacePath, 'template');
const mockGitClient = {
clone: jest.fn(),
@@ -62,7 +62,7 @@ describe('GitLabPreparer', () => {
});
expect(fs.move).toHaveBeenCalledWith(checkoutPath, templatePath);
expect(fs.rmdir).toHaveBeenCalledWith(resolve(templatePath, '.git'));
expect(fs.rmdir).toHaveBeenCalledWith(path.resolve(templatePath, '.git'));
});
it(`clones the template from a sub directory if specified`, async () => {
@@ -73,7 +73,7 @@ describe('GitLabPreparer', () => {
workspacePath,
});
expect(fs.move).toHaveBeenCalledWith(
resolve(checkoutPath, '1', '2', '3'),
path.resolve(checkoutPath, '1', '2', '3'),
templatePath,
);
});