Skip to content

Commit

Permalink
fix(lib/options): handle {Object} return (options.plugins)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Oct 14, 2017
1 parent 58e9996 commit 817680d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function parseOptions (params) {

if (typeof params.plugins === 'undefined') plugins = []
else if (Array.isArray(params.plugins)) plugins = params.plugins
else plugins = params.plugins
else plugins = [ params.plugins ]

const options = {}

Expand Down
7 changes: 7 additions & 0 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
"stringifier": {
"type": [ "string", "object" ]
},
"plugins": {
"anyOf": [
{ "type": "array" },
{ "type": "object" },
{ "instanceof": "Function" }
]
},
"sourceMap": {
"type": [ "string", "boolean" ]
}
Expand Down
6 changes: 5 additions & 1 deletion test/options/__snapshots__/plugins.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

exports[`Options Plugins - {Array} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;

exports[`Options Plugins - {Function} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;
exports[`Options Plugins - {Function} - {Array} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;

exports[`Options Plugins - {Function} - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;

exports[`Options Plugins - {Object} 1`] = `"module.exports = \\"a { color: rgba(255, 0, 0, 1.0) }\\\\n\\""`;
38 changes: 37 additions & 1 deletion test/options/plugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,25 @@ describe('Options', () => {
})
})

test('Plugins - {Function}', () => {
test('Plugins - {Object}', () => {
const config = {
loader: {
options: {
ident: 'postcss',
plugins: require('../fixtures/config/plugin')
}
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
})

test('Plugins - {Function} - {Array}', () => {
const config = {
loader: {
options: {
Expand All @@ -39,4 +57,22 @@ describe('Options', () => {
expect(src).toMatchSnapshot()
})
})

test('Plugins - {Function} - {Object}', () => {
const config = {
loader: {
options: {
ident: 'postcss',
plugins: () => require('../fixtures/config/plugin')()
}
}
}

return webpack('css/index.js', config).then((stats) => {
const src = loader(stats).src

expect(src).toEqual("module.exports = \"a { color: rgba(255, 0, 0, 1.0) }\\n\"")
expect(src).toMatchSnapshot()
})
})
})

0 comments on commit 817680d

Please sign in to comment.