Skip to content

Commit

Permalink
Ensure options are always an object
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Mar 6, 2017
1 parent b9209e7 commit e8aa302
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module.exports = function(source, inputSourceMap) {
const filename = webpackRemainingChain[webpackRemainingChain.length - 1];

// Handle options
const loaderOptions = loaderUtils.getOptions(this);
const loaderOptions = loaderUtils.getOptions(this) || {};
const defaultOptions = {
metadataSubscribers: [],
inputSourceMap: inputSourceMap,
Expand Down
26 changes: 26 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,29 @@ test.cb("should use correct env", (t) => {
t.end();
});
});

test.cb("should not throw without config", (t) => {
const config = {
entry: path.join(__dirname, "fixtures/basic.js"),
output: {
path: t.context.directory,
},
module: {
loaders: [
{
test: /\.jsx?/,
loader: babelLoader,
exclude: /node_modules/,
},
],
},
};

webpack(config, (err, stats) => {
t.is(err, null);

t.true(stats.compilation.errors.length === 0);

t.end();
});
});

0 comments on commit e8aa302

Please sign in to comment.