Correctly recognize whether the cookiecutter command exists

Signed-off-by: Dominik Henneke <dominik.henneke@sda-se.com>
This commit is contained in:
Dominik Henneke
2021-06-18 15:43:19 +02:00
parent 1d2d530979
commit c18a3c2ae0
3 changed files with 11 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Correctly recognize whether the cookiecutter command exists
@@ -35,6 +35,7 @@ describe('CookieCutter Templater', () => {
beforeEach(() => {
jest.clearAllMocks();
commandExists.mockRejectedValue(null);
});
it('should write a cookiecutter.json file with the values from the entity', async () => {
@@ -228,7 +229,7 @@ describe('CookieCutter Templater', () => {
};
jest.spyOn(fs, 'readdir').mockResolvedValueOnce(['newthing'] as any);
commandExists.mockImplementationOnce(() => () => true);
commandExists.mockResolvedValueOnce(true);
const templater = new CookieCutter({ containerRunner });
await templater.run({
@@ -70,7 +70,10 @@ export class CookieCutter implements TemplaterBase {
[intermediateDir]: '/output',
};
const cookieCutterInstalled = await commandExists('cookiecutter');
// the command-exists package returns `true` or throws an error
const cookieCutterInstalled = await commandExists('cookiecutter').catch(
() => false,
);
if (cookieCutterInstalled) {
await runCommand({
command: 'cookiecutter',