Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#13 loader.query is not defined in webpack.config.js, cause error (Cannot convert undefined or null to object) #14

Merged
merged 1 commit into from Dec 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
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
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
Expand Up @@ -15,8 +15,7 @@ module.exports = {
loaders: [
{
test: /\.tag$/,
loader: 'riot-tag-loader',
query: {}
loader: 'riot-tag-loader'
}
]
},
Expand Down