From 39144538500c7e9ead26e0660edc5e13a25a0362 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Sun, 14 Feb 2021 19:46:59 +0100 Subject: [PATCH] chore: TechDocs publisher does not work well with Windows paths --- packages/techdocs-common/__mocks__/aws-sdk.ts | 6 +----- .../src/stages/publish/awsS3.test.ts | 18 +++++++----------- .../src/stages/publish/awsS3.ts | 16 ++++++++-------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/packages/techdocs-common/__mocks__/aws-sdk.ts b/packages/techdocs-common/__mocks__/aws-sdk.ts index 987b3d2800..f0fb13c642 100644 --- a/packages/techdocs-common/__mocks__/aws-sdk.ts +++ b/packages/techdocs-common/__mocks__/aws-sdk.ts @@ -71,11 +71,7 @@ export class S3 { return { promise: () => new Promise((resolve, reject) => { - if (!fs.existsSync(Key)) { - reject(''); - } else { - resolve(''); - } + resolve(''); }), }; } diff --git a/packages/techdocs-common/src/stages/publish/awsS3.test.ts b/packages/techdocs-common/src/stages/publish/awsS3.test.ts index 813f6b8554..f8450a07a0 100644 --- a/packages/techdocs-common/src/stages/publish/awsS3.test.ts +++ b/packages/techdocs-common/src/stages/publish/awsS3.test.ts @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import type { Entity, EntityName } from '@backstage/catalog-model'; +import { ConfigReader } from '@backstage/config'; import mockFs from 'mock-fs'; import path from 'path'; import * as winston from 'winston'; -import { ConfigReader } from '@backstage/config'; import { AwsS3Publish } from './awsS3'; import { PublisherBase, TechDocsMetadata } from './types'; -import type { Entity, EntityName } from '@backstage/catalog-model'; const createMockEntity = (annotations = {}): Entity => { return { @@ -127,9 +127,9 @@ describe('AwsS3Publish', () => { directory: wrongPathToGeneratedDirectory, }) .catch(error => - expect(error).toEqual( - new Error( - `Unable to upload file(s) to AWS S3. Error Failed to read template directory: ENOENT, no such file or directory '${wrongPathToGeneratedDirectory}'`, + expect(error.message).toEqual( + expect.stringContaining( + 'Unable to upload file(s) to AWS S3. Error Failed to read template directory: ENOENT, no such file or directory', ), ), ); @@ -205,16 +205,12 @@ describe('AwsS3Publish', () => { it('should return an error if the techdocs_metadata.json file is not present', async () => { const entityNameMock = createMockEntityName(); - const entity = createMockEntity(); - const entityRootDir = getEntityRootDir(entity); await publisher .fetchTechDocsMetadata(entityNameMock) .catch(error => - expect(error).toEqual( - new Error( - `TechDocs metadata fetch failed, The file ${entityRootDir}/techdocs_metadata.json doest not exist !`, - ), + expect(error.message).toEqual( + expect.stringContaining('TechDocs metadata fetch'), ), ); }); diff --git a/packages/techdocs-common/src/stages/publish/awsS3.ts b/packages/techdocs-common/src/stages/publish/awsS3.ts index 8eaf03eb2f..6c0cadcfae 100644 --- a/packages/techdocs-common/src/stages/publish/awsS3.ts +++ b/packages/techdocs-common/src/stages/publish/awsS3.ts @@ -13,19 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import path from 'path'; -import express from 'express'; -import aws from 'aws-sdk'; -import { ManagedUpload } from 'aws-sdk/clients/s3'; -import { Logger } from 'winston'; import { Entity, EntityName } from '@backstage/catalog-model'; import { Config } from '@backstage/config'; -import { getHeadersForFileExtension, getFileTreeRecursively } from './helpers'; -import { PublisherBase, PublishRequest, TechDocsMetadata } from './types'; +import aws from 'aws-sdk'; +import { ManagedUpload } from 'aws-sdk/clients/s3'; +import express from 'express'; import fs from 'fs-extra'; -import { Readable } from 'stream'; import JSON5 from 'json5'; import createLimiter from 'p-limit'; +import path from 'path'; +import { Readable } from 'stream'; +import { Logger } from 'winston'; +import { getFileTreeRecursively, getHeadersForFileExtension } from './helpers'; +import { PublisherBase, PublishRequest, TechDocsMetadata } from './types'; const streamToBuffer = (stream: Readable): Promise => { return new Promise((resolve, reject) => {