Skip to content

Commit

Permalink
Don't throw on an undefined partial
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjoelkemp committed Jan 21, 2019
1 parent 59e161f commit 07ecf37
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ function commonJSLookup({dependency, filename, directory, nodeModulesConfig}) {
if (!resolve) {
resolve = require('resolve');
}

if (!dependency) {
debug('blank dependency given. Returning early.');
return '';
}

// Need to resolve partials within the directory of the module, not filing-cabinet
const moduleLookupDir = path.join(directory, 'node_modules');

Expand Down
3 changes: 2 additions & 1 deletion test/mockedJSFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
'es6': {
'foo.js': 'import bar from "./bar";',
'foo.jsx': 'import React from "react"; export default () => { return (<div></div>); }',
'bar.js': 'export default function() {};'
'bar.js': 'export default function() {};',
'lazy.js': 'localizedModule(app, "modulename", locale => import(`modulename/locales/${locale}`));'
},
'cjs': {
'foo.js': 'module.exports = 1;',
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ describe('filing-cabinet', function() {
assert.equal(result, expected);
spy.restore();
});

describe('when given a lazy import with interpolation', function() {
it('does not throw', function() {
assert.doesNotThrow(() => {
cabinet({
partial: '`modulename/locales/${locale}`',
filename: 'js/es6/lazy.js',
directory: 'js/es6/'
});
});
});
});

describe('when given an undefined dependency', function() {
it('does not throw', function() {
assert.doesNotThrow(() => {
cabinet({
partial: undefined,
filename: 'js/es6/lazy.js',
directory: 'js/es6/'
});
});
});
});
});

describe('jsx', function() {
Expand Down

0 comments on commit 07ecf37

Please sign in to comment.