Skip to content

Commit a103c9b

Browse files
author
Kent C. Dodds
committed
move things around and add emotion + snapshots
1 parent 31c28d4 commit a103c9b

12 files changed

+68
-18
lines changed

.babelrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const isTest = String(process.env.NODE_ENV) === 'test'
2+
const isProd = String(process.env.NODE_ENV) === 'production'
23

34
module.exports = {
45
presets: [
@@ -9,6 +10,15 @@ module.exports = {
910
'babel-plugin-syntax-dynamic-import',
1011
'@babel/plugin-proposal-class-properties',
1112
'@babel/plugin-proposal-object-rest-spread',
13+
[
14+
'babel-plugin-emotion',
15+
{
16+
hoist: isProd,
17+
sourceMap: !isProd,
18+
autoLabel: !isProd,
19+
labelFormat: '[filename]--[local]',
20+
},
21+
],
1222
'react-loadable/babel',
1323
isTest ? 'babel-plugin-dynamic-import-node' : null,
1424
].filter(Boolean),

jest.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
...require('./other/jest-common.js'),
2+
...require('./test/jest-common'),
33
collectCoverageFrom: ['**/src/**/*.js'],
44
coverageThreshold: {
55
global: {
@@ -16,8 +16,8 @@ module.exports = {
1616
},
1717
},
1818
projects: [
19-
'./other/jest.lint.js',
20-
'./other/jest.client.js',
21-
'./other/jest.server.js',
19+
'./test/jest.lint.js',
20+
'./test/jest.client.js',
21+
'./test/jest.server.js',
2222
],
2323
}

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
"babel-core": "7.0.0-bridge.0",
3838
"babel-loader": "^7.1.4",
3939
"babel-plugin-dynamic-import-node": "^1.2.0",
40+
"babel-plugin-emotion": "^9.2.4",
4041
"css-loader": "^0.28.11",
4142
"cypress": "^3.0.1",
4243
"cypress-testing-library": "^2.2.0",
44+
"emotion": "^9.2.4",
4345
"eslint": "^5.0.1",
4446
"eslint-config-kentcdodds": "^14.0.0",
4547
"file-loader": "^1.1.11",
@@ -48,11 +50,13 @@
4850
"is-ci-cli": "^1.1.1",
4951
"jest": "^23.1.0",
5052
"jest-dom": "^1.3.1",
53+
"jest-emotion": "^9.2.4",
5154
"jest-runner-eslint": "^0.6.0",
5255
"jest-watch-select-projects": "0.0.1",
5356
"jest-watch-typeahead": "^0.1.0",
5457
"lint-staged": "^7.2.0",
5558
"prop-types": "^15.6.2",
59+
"react-emotion": "^9.2.4",
5660
"react-testing-library": "^4.0.2",
5761
"serve": "^9.1.0",
5862
"start-server-and-test": "^1.4.1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`mounts 1`] = `
4+
.emotion-0 {
5+
color: white;
6+
background: #1c191c;
7+
line-height: 130px;
8+
font-size: 6em;
9+
-webkit-flex: 1;
10+
-ms-flex: 1;
11+
flex: 1;
12+
}
13+
14+
<div
15+
class="emotion-0"
16+
>
17+
<div
18+
class="autoScalingText"
19+
style="transform: scale(1,1);"
20+
>
21+
0
22+
</div>
23+
</div>
24+
`;

src/__tests__/calculator-display.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react'
2+
import {render} from 'react-testing-library'
3+
import CalculatorDisplay from '../calculator-display'
4+
5+
test('mounts', () => {
6+
const {container} = render(<CalculatorDisplay value="0" />)
7+
expect(container.firstChild).toMatchSnapshot()
8+
})

src/calculator-display.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import AutoScalingText from './auto-scaling-text'
4-
import styles from './calculator-display.module.css'
54
import {getFormattedValue} from './utils'
65

76
class CalculatorDisplay extends React.Component {
@@ -16,7 +15,16 @@ class CalculatorDisplay extends React.Component {
1615
)
1716

1817
return (
19-
<div {...props} className={styles.calculatorDisplay}>
18+
<div
19+
{...props}
20+
css={{
21+
color: 'white',
22+
background: '#1c191c',
23+
lineHeight: '130px',
24+
fontSize: '6em',
25+
flex: '1',
26+
}}
27+
>
2028
<AutoScalingText>{formattedValue}</AutoScalingText>
2129
</div>
2230
)

src/calculator-display.module.css

-8
This file was deleted.

other/jest-common.js renamed to test/jest-common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
moduleNameMapper: {
99
// module must come first
1010
'\\.module\\.css$': 'identity-obj-proxy',
11-
'\\.css$': require.resolve('../test/style-mock.js'),
11+
'\\.css$': require.resolve('./style-mock.js'),
1212
// can also map files that are loaded by webpack with the file-loader
1313
},
1414
coveragePathIgnorePatterns: [

other/jest.client.js renamed to test/jest.client.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ module.exports = {
22
...require('./jest-common'),
33
displayName: 'dom',
44
testEnvironment: 'jest-environment-jsdom',
5-
setupTestFrameworkScriptFile: require.resolve(
6-
'../test/setup-test-framework.js',
7-
),
5+
setupTestFrameworkScriptFile: require.resolve('./setup-test-framework.js'),
86
}
File renamed without changes.
File renamed without changes.

test/setup-test-framework.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ import 'react-testing-library/cleanup-after-each'
44

55
// this adds jest-dom's custom assertions
66
import 'jest-dom/extend-expect'
7+
8+
// add jest-emotion serializer
9+
import {createSerializer} from 'jest-emotion'
10+
import * as emotion from 'emotion'
11+
12+
expect.addSnapshotSerializer(createSerializer(emotion))

0 commit comments

Comments
 (0)