Skip to content

Commit

Permalink
Fix bug where browserslist target didn't work outside of tuple syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed May 1, 2020
1 parent 6aef917 commit f5c0e30
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions __tests__/targetMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,43 @@ test('plugins can request the target for a specific plugin key', () => {
})

test('browserslist target is translated to a target preset', () => {
return runInTempDirectory(() => {
fs.writeFileSync(
path.resolve('./.browserslistrc'),
`
last 2 versions
IE 11
`
)
const { utilities } = processPlugins(
[
function({ addUtilities, target }) {
addUtilities({
'.test': {
target: target('testPlugin'),
},
})
},
],
{
...config,
target: 'browserslist',
}
)

expect(css(utilities)).toMatchCss(`
@variants {
.test {
target: ie11
}
}
`)

return Promise.resolve()
})
})

test('browserslist target is translated to a target preset with overrides', () => {
return runInTempDirectory(() => {
fs.writeFileSync(
path.resolve('./.browserslistrc'),
Expand Down
2 changes: 1 addition & 1 deletion src/util/processPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function(plugins, config) {
},
target: path => {
if (_.isString(config.target)) {
return config.target
return config.target === 'browserslist' ? browserslistTarget : config.target
}

const [defaultTarget, targetOverrides] = getConfigValue('target')
Expand Down

0 comments on commit f5c0e30

Please sign in to comment.