Skip to content

Commit

Permalink
Merge pull request #169 from electron/more-enoent-logging
Browse files Browse the repository at this point in the history
fix: Add some detailed templates logging
  • Loading branch information
felixrieseberg committed Jan 27, 2019
2 parents 89cede2 + 8e8eec3 commit f7a19b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/renderer/templates.ts
Expand Up @@ -15,8 +15,8 @@ import { fancyImport } from '../utils/import';
export async function getTemplateValues(name: string): Promise<EditorValues> {
const path = await fancyImport<typeof pathType>('path');
const fs = await fancyImport<typeof fsExtraType>('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 {
Expand All @@ -25,7 +25,15 @@ export async function getTemplateValues(name: string): Promise<EditorValues> {

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 '';
}
};
Expand Down
11 changes: 11 additions & 0 deletions tests/renderer/templates-spec.ts
Expand Up @@ -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);
});
});
});

0 comments on commit f7a19b9

Please sign in to comment.