Skip to content

Commit

Permalink
Merge pull request #14 from wata-lb/#13_cannot_convert_null_to_object
Browse files Browse the repository at this point in the history
#13 loader.query is not defined in webpack.config.js, cause error (Cannot convert undefined or null to object)
  • Loading branch information
GianlucaGuarini authored Dec 25, 2017
2 parents ca95f29 + e7005ae commit afa6ba4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = function(source) {
const tags = []

// parse the user query
const query = getOptions(this)
const query = getOptions(this) || {}

// normalise the query object in case of question marks
const opts = Object.keys(query).reduce(function(acc, key) {
Expand Down
14 changes: 11 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function readFile(file) {
return normalize(fs.readFileSync(path.join(EXPECT, file), 'utf8'))
}

function compile(opts = {}) {
function compile(opts) {
webpackConfig.module.loaders[0].query = opts
const compiler = webpack(webpackConfig)
return new Promise(resolve => {
Expand All @@ -25,8 +25,15 @@ function compile(opts = {}) {
}

describe('riot-tag-loader unit test', () => {
it('riot loader default options', (done) => {
compile().then(content => {
it('riot loader undefined options', (done) => {
compile(undefined).then(content => {
assert.equal(content, readFile('bundle-normal.js'))
done()
})
})

it('riot loader empty options', (done) => {
compile({}).then(content => {
assert.equal(content, readFile('bundle-normal.js'))
done()
})
Expand Down Expand Up @@ -54,4 +61,5 @@ describe('riot-tag-loader unit test', () => {
done()
})
})

})
3 changes: 1 addition & 2 deletions test/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = {
loaders: [
{
test: /\.tag$/,
loader: 'riot-tag-loader',
query: {}
loader: 'riot-tag-loader'
}
]
},
Expand Down

0 comments on commit afa6ba4

Please sign in to comment.