diff --git a/src/renderer/templates.ts b/src/renderer/templates.ts index 1d08c01699..a3e8b37da2 100644 --- a/src/renderer/templates.ts +++ b/src/renderer/templates.ts @@ -15,8 +15,8 @@ import { fancyImport } from '../utils/import'; export async function getTemplateValues(name: string): Promise { const path = await fancyImport('path'); const fs = await fancyImport('fs-extra'); - - const templatePath = path.join(__dirname, '../../static/templates', name.toLowerCase()); + const templatesPath = path.join(__dirname, '../../static/templates'); + const templatePath = path.join(templatesPath, name.toLowerCase()); const getFile = async (fileName: string) => { try { @@ -25,7 +25,15 @@ export async function getTemplateValues(name: string): Promise { return content; } catch (error) { - console.warn(`Could not get template file:`, error); + console.warn(`getTemplateValues(): Could not get template file:`, error); + + if (fs.existsSync(templatesPath)) { + const contents = fs.readdirSync(templatesPath); + console.log(`getTemplateValues(): ${templatesPath} contents:`, contents); + } else { + console.log(`getTemplateValues(): ${templatesPath} does not exist`); + } + return ''; } }; diff --git a/tests/renderer/templates-spec.ts b/tests/renderer/templates-spec.ts index 71cd521d77..aa8d2959c8 100644 --- a/tests/renderer/templates-spec.ts +++ b/tests/renderer/templates-spec.ts @@ -36,5 +36,16 @@ describe('templates', () => { expect(values.main).toBe(''); expect(values.renderer).toBe(''); }); + + it('handles errors and reports the templates content', async () => { + const fs = require('fs-extra'); + + fs.readFile.mockReturnValue(Promise.reject('bwap')); + fs.existsSync.mockReturnValue(true); + + await getTemplateValues('test'); + expect(fs.existsSync).toHaveBeenCalledTimes(3); + expect(fs.readdirSync).toHaveBeenCalledTimes(3); + }); }); });