From 35952103d66db80859058082d094139436558ae6 Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Thu, 18 Feb 2021 13:38:45 +0100 Subject: [PATCH] TechDocs: AWS Publisher - add tests that fail on Windows --- packages/techdocs-common/__mocks__/aws-sdk.ts | 10 +++++++--- .../src/stages/publish/awsS3.test.ts | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/techdocs-common/__mocks__/aws-sdk.ts b/packages/techdocs-common/__mocks__/aws-sdk.ts index f0fb13c642..b956b4309a 100644 --- a/packages/techdocs-common/__mocks__/aws-sdk.ts +++ b/packages/techdocs-common/__mocks__/aws-sdk.ts @@ -41,7 +41,7 @@ export class S3 { } else { emitter.emit( 'error', - new Error(`The file ${Key} doest not exist !`), + new Error(`The file ${Key} does not exist !`), ); } emitter.emit('end'); @@ -56,7 +56,7 @@ export class S3 { if (fs.existsSync(Key)) { resolve(''); } else { - reject({ message: 'The object doest not exist !' }); + reject({ message: 'The object does not exist !' }); } }); } @@ -71,7 +71,11 @@ export class S3 { return { promise: () => new Promise((resolve, reject) => { - resolve(''); + if (!fs.existsSync(Key)) { + reject(''); + } else { + resolve(''); + } }), }; } diff --git a/packages/techdocs-common/src/stages/publish/awsS3.test.ts b/packages/techdocs-common/src/stages/publish/awsS3.test.ts index f8450a07a0..9376e74e92 100644 --- a/packages/techdocs-common/src/stages/publish/awsS3.test.ts +++ b/packages/techdocs-common/src/stages/publish/awsS3.test.ts @@ -127,9 +127,9 @@ describe('AwsS3Publish', () => { directory: wrongPathToGeneratedDirectory, }) .catch(error => - 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', + 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}'`, ), ), ); @@ -205,12 +205,19 @@ 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.message).toEqual( - expect.stringContaining('TechDocs metadata fetch'), + expect(error).toEqual( + new Error( + `TechDocs metadata fetch failed, The file ${path.join( + entityRootDir, + 'techdocs_metadata.json', + )} does not exist !`, + ), ), ); });