Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Moreau committed Jan 30, 2025
1 parent 1e4135f commit ec96007
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 3 additions & 5 deletions packages/forest-cloud/src/services/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ export default async function bootstrap(
const error = e as Error;
const potentialErrorMessage = await tryToClearBootstrap(paths);

if (error instanceof BusinessError) {
throw new BusinessError(`Bootstrap failed: ${error.message}. ${potentialErrorMessage || ''}`);
} else {
throw error;
}
throw new BusinessError(
`Bootstrap failed: ${error.message}. ${potentialErrorMessage || ''}${error.stack}`,
);
}
}
16 changes: 7 additions & 9 deletions packages/forest-cloud/test/services/bootstrap.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,27 @@ describe('bootstrap', () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
const httpServer = new HttpServer('', '', '');
const path = new BootstrapPathManager('', '');
HttpServer.downloadCloudCustomizerTemplate = jest
.fn()
.mockRejectedValue(new Error('Failed'));
const error = new Error('Failed');
HttpServer.downloadCloudCustomizerTemplate = jest.fn().mockRejectedValue(error);

await expect(
bootstrap(
{ FOREST_ENV_SECRET: 'abc' } as unknown as EnvironmentVariables,
httpServer,
path,
),
).rejects.toEqual(new BusinessError('Bootstrap failed: Failed.'));
).rejects.toEqual(new BusinessError(`Bootstrap failed: Failed. ${error.stack}`));
});

describe('If there is an error when trying to clear the bootstrap', () => {
it('should notify the client to clear the "forest-cloud" folder', async () => {
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
const httpServer = new HttpServer('', '', '');
const path = new BootstrapPathManager('', '');
HttpServer.downloadCloudCustomizerTemplate = jest
.fn()
.mockRejectedValue(new Error('Failed'));
const error = new Error('Failed');
HttpServer.downloadCloudCustomizerTemplate = jest.fn().mockRejectedValue(error);
// throw error when trying to clear
jest.spyOn(fsP, 'rm').mockRejectedValue(new Error('Failed'));
jest.spyOn(fsP, 'rm').mockRejectedValue(new Error('Cannot remove file'));

await expect(
bootstrap(
Expand All @@ -104,7 +102,7 @@ describe('bootstrap', () => {
),
).rejects.toEqual(
new BusinessError(
'Bootstrap failed: Failed.\nPlease remove "forest-cloud" folder and re-run bootstrap command.',
`Bootstrap failed: Failed. \nPlease remove "forest-cloud" folder and re-run bootstrap command.${error.stack}`,
),
);
});
Expand Down

0 comments on commit ec96007

Please sign in to comment.