scaffolder-backend: attempt to fix windows test errors in master
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Attempt to fix windows test errors in master
|
||||
@@ -62,7 +62,9 @@
|
||||
"@backstage/cli": "^0.5.0",
|
||||
"@backstage/test-utils": "^0.1.5",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/mock-fs": "^4.13.0",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"mock-fs": "^4.13.0",
|
||||
"supertest": "^4.0.2",
|
||||
"yaml": "^1.10.0",
|
||||
"msw": "^0.21.2"
|
||||
|
||||
@@ -13,12 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import os from 'os';
|
||||
import { JobProcessor } from './processor';
|
||||
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
import { StageInput } from './types';
|
||||
import { RequiredTemplateValues } from '../stages/templater';
|
||||
import parseGitUrl from 'git-url-parse';
|
||||
import mockFs from 'mock-fs';
|
||||
import os from 'os';
|
||||
import { RequiredTemplateValues } from '../stages/templater';
|
||||
import { makeLogStream } from './logger';
|
||||
import { JobProcessor } from './processor';
|
||||
import { StageInput } from './types';
|
||||
|
||||
describe('JobProcessor', () => {
|
||||
const mockEntity: TemplateEntityV1alpha1 = {
|
||||
@@ -32,7 +34,7 @@ describe('JobProcessor', () => {
|
||||
name: 'graphql-starter',
|
||||
title: 'GraphQL Service',
|
||||
description:
|
||||
'A GraphQL starter template for backstage to get you up and running\nthe best pracices with GraphQL\n',
|
||||
'A GraphQL starter template for backstage to get you up and running\nthe best practices with GraphQL\n',
|
||||
uid: '9cf16bad-16e0-4213-b314-c4eec773c50b',
|
||||
etag: 'ZTkxMjUxMjUtYWY3Yi00MjU2LWFkYWMtZTZjNjU5ZjJhOWM2',
|
||||
|
||||
@@ -71,6 +73,25 @@ describe('JobProcessor', () => {
|
||||
|
||||
const workingDirectory = os.platform() === 'win32' ? 'C:\\tmp' : '/tmp';
|
||||
|
||||
// NOTE(freben): Without this line, mock-fs makes winston/logform break.
|
||||
// There are a number of reported issues with logform and its use of dynamic
|
||||
// strings for imports. It confuses webpack. The basic fix is to trigger
|
||||
// those imports before mock-fs runs. I wanted to add a mock dir
|
||||
// 'node_modules': mockFs.passthrough(), but that doesn't seem to be a thing
|
||||
// in mock-fs 4.
|
||||
// Probable REAL fix: https://github.com/winstonjs/logform/pull/117
|
||||
makeLogStream({});
|
||||
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
[workingDirectory]: mockFs.directory(),
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe('create', () => {
|
||||
it('creates should create a new job with a unique id', async () => {
|
||||
const processor = new JobProcessor(workingDirectory);
|
||||
@@ -157,6 +178,7 @@ describe('JobProcessor', () => {
|
||||
expect(processor.get(job.id)).toBe(job);
|
||||
});
|
||||
});
|
||||
|
||||
describe('process', () => {
|
||||
it('throws an error when the status of the job is not in pending state', async () => {
|
||||
const processor = new JobProcessor(workingDirectory);
|
||||
|
||||
@@ -131,7 +131,7 @@ export class JobProcessor implements Processor {
|
||||
|
||||
try {
|
||||
for (const stage of job.stages) {
|
||||
// Create a logger for each stage so we can create seperate
|
||||
// Create a logger for each stage so we can create separate
|
||||
// Streams for each step.
|
||||
const { logger, log, stream } = makeLogStream({
|
||||
id: job.id,
|
||||
@@ -151,8 +151,8 @@ export class JobProcessor implements Processor {
|
||||
logStream: stream,
|
||||
});
|
||||
|
||||
// If the handler returns something, then let's merge this onto the ontext
|
||||
// For the next stage to use as it might be relevant.
|
||||
// If the handler returns something, then let's merge this onto the
|
||||
// context for the next stage to use as it might be relevant.
|
||||
if (handlerResponse) {
|
||||
job.context = {
|
||||
...job.context,
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { InputError } from '@backstage/backend-common';
|
||||
import { PreparerBase, PreparerOptions } from './types';
|
||||
|
||||
@@ -27,7 +28,7 @@ export class FilePreparer implements PreparerBase {
|
||||
const checkoutDir = path.join(workspacePath, 'checkout');
|
||||
await fs.ensureDir(checkoutDir);
|
||||
|
||||
const templatePath = url.slice('file://'.length);
|
||||
const templatePath = fileURLToPath(url);
|
||||
|
||||
await fs.copy(templatePath, checkoutDir, {
|
||||
recursive: true,
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('GitHubPreparer', () => {
|
||||
path.resolve(checkoutPath, 'templates', 'graphql-starter', 'template'),
|
||||
templatePath,
|
||||
);
|
||||
expect(fs.rmdir).toHaveBeenCalledWith('/tmp/template/.git');
|
||||
expect(fs.rmdir).toHaveBeenCalledWith(path.resolve(templatePath, '.git'));
|
||||
});
|
||||
|
||||
it('calls the clone command with the correct arguments for a repository when no path is provided', async () => {
|
||||
|
||||
@@ -227,8 +227,8 @@ describe('CookieCutter Templater', () => {
|
||||
args: expect.arrayContaining([
|
||||
'--no-input',
|
||||
'-o',
|
||||
'tempdir/intermediate',
|
||||
'tempdir/template',
|
||||
path.join('tempdir', 'intermediate'),
|
||||
path.join('tempdir', 'template'),
|
||||
'--verbose',
|
||||
]),
|
||||
logStream: stream,
|
||||
|
||||
@@ -26,7 +26,7 @@ export class CookieCutter implements TemplaterBase {
|
||||
directory: string,
|
||||
): Promise<Record<string, JsonValue>> {
|
||||
try {
|
||||
return await fs.readJSON(`${directory}/cookiecutter.json`);
|
||||
return await fs.readJSON(path.join(directory, 'cookiecutter.json'));
|
||||
} catch (ex) {
|
||||
if (ex.code !== 'ENOENT') {
|
||||
throw ex;
|
||||
@@ -54,7 +54,7 @@ export class CookieCutter implements TemplaterBase {
|
||||
...values,
|
||||
};
|
||||
|
||||
await fs.writeJSON(`${templateDir}/cookiecutter.json`, cookieInfo);
|
||||
await fs.writeJSON(path.join(templateDir, 'cookiecutter.json'), cookieInfo);
|
||||
|
||||
const cookieCutterInstalled = await commandExists('cookiecutter');
|
||||
if (cookieCutterInstalled) {
|
||||
|
||||
Reference in New Issue
Block a user