Skip to content

Commit

Permalink
Ad edge case checks for no template
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkudo committed Sep 16, 2018
1 parent e1ab43e commit 326e1e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions __mocks__/fs-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ fs.actions = [];
let filesystem = {};

fs.mockReset = () => {
fs.mkdtempSync.mockReturnValue('/test/tmp/' + increment++);

filesystem = JSON.parse(JSON.stringify(originalFileSystem));
increment = 0;

fs.mkdtempSync.mockImplementation(() => {
const filename ='/test/tmp/' + increment;

increment += 1;

return filename;
});

fs.ensureDirSync.mockImplementation(() => 0);
fs.removeSync.mockImplementation(() => 0);

Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,10 @@ class TranslationStaticAnalyzer {
* updating a source file.
*/
write() {
if (generateLocaleFiles.call(this)) {
const cache = this.instance.cache || {};
const template = cache.template;

if (template && generateLocaleFiles.call(this)) {
writeToTargets.call(this);
}

Expand Down
15 changes: 15 additions & 0 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ describe('TranslationStaticAnalyzer', () => {
fs.mockReset();
});

it('does nothing when write is called and there is no template', () => {
const analyzer = new TranslationStaticAnalyzer({
files: 'test files',
locales: ['existing'],
target: 'test directory targets',
});

delete analyzer.instance.cache.template;
fs.actions.length = 0;

analyzer.write();

expect(fs.actions).toEqual([]);
});

it('calls cleanup on exit', () => {
const analyzer = new TranslationStaticAnalyzer({
files: 'test files',
Expand Down

0 comments on commit 326e1e7

Please sign in to comment.