Skip to content

Commit

Permalink
fix: don't generate styled-jsx randomized classes in jest snapshots (#…
Browse files Browse the repository at this point in the history
…332)

In test environments we should:

Use styled-jsx/babel-test instead of styled-jsx/babel
Mock the styled-jsx/css function as a no-op
This results in clean snapshot output without randomly-generated jsx-##### which change whenever any css changes. See the styled-jsx README
  • Loading branch information
amcgee committed Mar 25, 2020
1 parent 8d6f501 commit eaafbab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cli/config/app.babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@ module.exports = {

// Automatically include a React import when JSX is present
require('babel-plugin-react-require'),

// Always build in "production" mode even when styled-jsx runtime may select "development"
[require('styled-jsx/babel'), { optimizeForSpeed: true }],
],
env: {
production: {
plugins: [
[require('styled-jsx/babel'), { optimizeForSpeed: true }],
]
},
development: {
plugins: [
[require('styled-jsx/babel'), { optimizeForSpeed: true }],
]
},
test: {
plugins: [
require('styled-jsx/babel-test')
]
}
}
}
1 change: 1 addition & 0 deletions cli/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': require.resolve(
'./jest.file.mock.js'
),
'^styled-jsx/(css|macro)$': require.resolve('./jest.styled-jsx-css.mock.js')
},
}
5 changes: 5 additions & 0 deletions cli/config/jest.styled-jsx-css.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const css = () => ''
css.global = () => ''
css.resolve = () => ''

module.exports = css

0 comments on commit eaafbab

Please sign in to comment.