Skip to content

Commit f963b86

Browse files
author
Kent C. Dodds
committed
update based on egghead lessons
1 parent 1ea31a3 commit f963b86

11 files changed

+263
-22
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ coverage
22
node_modules
33
public
44
dist
5+
other

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage
22
node_modules
33
dist
4+
other

other/utils.coverage.js

+230
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
// npx -p @babel/cli -p @babel/core -c "babel --plugins babel-plugin-istanbul --preset ./.babelrc.js src/shared/utils.js"
2+
var cov_2e1x39rbgn = function () {
3+
var path = "/Users/kdodds/Developer/jest-cypress-react-babel-webpack/src/utils.js",
4+
hash = "11d29cc5894ffec96585bad5b940d9b13baa3ea3",
5+
Function = function () {}.constructor,
6+
global = new Function('return this')(),
7+
gcv = "__coverage__",
8+
coverageData = {
9+
path: "/Users/kdodds/Developer/jest-cypress-react-babel-webpack/src/utils.js",
10+
statementMap: {
11+
"0": {
12+
start: {
13+
line: 2,
14+
column: 23
15+
},
16+
end: {
17+
line: 5,
18+
column: 4
19+
}
20+
},
21+
"1": {
22+
start: {
23+
line: 8,
24+
column: 16
25+
},
26+
end: {
27+
line: 8,
28+
column: 42
29+
}
30+
},
31+
"2": {
32+
start: {
33+
line: 10,
34+
column: 2
35+
},
36+
end: {
37+
line: 12,
38+
column: 3
39+
}
40+
},
41+
"3": {
42+
start: {
43+
line: 11,
44+
column: 4
45+
},
46+
end: {
47+
line: 11,
48+
column: 66
49+
}
50+
},
51+
"4": {
52+
start: {
53+
line: 13,
54+
column: 2
55+
},
56+
end: {
57+
line: 13,
58+
column: 23
59+
}
60+
}
61+
},
62+
fnMap: {
63+
"0": {
64+
name: "getFormattedValue",
65+
decl: {
66+
start: {
67+
line: 1,
68+
column: 9
69+
},
70+
end: {
71+
line: 1,
72+
column: 26
73+
}
74+
},
75+
loc: {
76+
start: {
77+
line: 1,
78+
column: 54
79+
},
80+
end: {
81+
line: 14,
82+
column: 1
83+
}
84+
},
85+
line: 1
86+
}
87+
},
88+
branchMap: {
89+
"0": {
90+
loc: {
91+
start: {
92+
line: 1,
93+
column: 34
94+
},
95+
end: {
96+
line: 1,
97+
column: 52
98+
}
99+
},
100+
type: "default-arg",
101+
locations: [{
102+
start: {
103+
line: 1,
104+
column: 45
105+
},
106+
end: {
107+
line: 1,
108+
column: 52
109+
}
110+
}],
111+
line: 1
112+
},
113+
"1": {
114+
loc: {
115+
start: {
116+
line: 10,
117+
column: 2
118+
},
119+
end: {
120+
line: 12,
121+
column: 3
122+
}
123+
},
124+
type: "if",
125+
locations: [{
126+
start: {
127+
line: 10,
128+
column: 2
129+
},
130+
end: {
131+
line: 12,
132+
column: 3
133+
}
134+
}, {
135+
start: {
136+
line: 10,
137+
column: 2
138+
},
139+
end: {
140+
line: 12,
141+
column: 3
142+
}
143+
}],
144+
line: 10
145+
},
146+
"2": {
147+
loc: {
148+
start: {
149+
line: 11,
150+
column: 22
151+
},
152+
end: {
153+
line: 11,
154+
column: 66
155+
}
156+
},
157+
type: "cond-expr",
158+
locations: [{
159+
start: {
160+
line: 11,
161+
column: 47
162+
},
163+
end: {
164+
line: 11,
165+
column: 55
166+
}
167+
}, {
168+
start: {
169+
line: 11,
170+
column: 58
171+
},
172+
end: {
173+
line: 11,
174+
column: 66
175+
}
176+
}],
177+
line: 11
178+
}
179+
},
180+
s: {
181+
"0": 0,
182+
"1": 0,
183+
"2": 0,
184+
"3": 0,
185+
"4": 0
186+
},
187+
f: {
188+
"0": 0
189+
},
190+
b: {
191+
"0": [0],
192+
"1": [0, 0],
193+
"2": [0, 0]
194+
},
195+
_coverageSchema: "332fd63041d2c1bcb487cc26dd0d5f7d97098a6c"
196+
},
197+
coverage = global[gcv] || (global[gcv] = {});
198+
199+
if (coverage[path] && coverage[path].hash === hash) {
200+
return coverage[path];
201+
}
202+
203+
coverageData.hash = hash;
204+
return coverage[path] = coverageData;
205+
}();
206+
207+
function getFormattedValue(value) {
208+
var language = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (cov_2e1x39rbgn.b[0][0]++, 'en-US');
209+
cov_2e1x39rbgn.f[0]++;
210+
var formattedValue = (cov_2e1x39rbgn.s[0]++, parseFloat(value).toLocaleString(language, {
211+
useGrouping: true,
212+
maximumFractionDigits: 6
213+
})); // Add back missing .0 in e.g. 12.0
214+
215+
var match = (cov_2e1x39rbgn.s[1]++, value.match(/\.\d*?(0*)$/));
216+
cov_2e1x39rbgn.s[2]++;
217+
218+
if (match) {
219+
cov_2e1x39rbgn.b[1][0]++;
220+
cov_2e1x39rbgn.s[3]++;
221+
formattedValue += /[1-9]/.test(match[0]) ? (cov_2e1x39rbgn.b[2][0]++, match[1]) : (cov_2e1x39rbgn.b[2][1]++, match[0]);
222+
} else {
223+
cov_2e1x39rbgn.b[1][1]++;
224+
}
225+
226+
cov_2e1x39rbgn.s[4]++;
227+
return formattedValue;
228+
}
229+
230+
export { getFormattedValue };

package.json

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "calculator.solution",
2+
"name": "calculator",
33
"version": "1.0.0",
44
"description": "See how to configure Jest and Cypress with React, Babel, and Webpack",
55
"main": "index.js",
@@ -20,12 +20,13 @@
2020
"postbuild": "cp ./public/index.html ./dist/index.html",
2121
"start": "serve --no-clipboard --listen 8080 dist",
2222
"format": "prettier \"**/*.js\" --write",
23+
"lint": "jest --config test/jest.lint.js",
2324
"validate": "npm run test:coverage && npm run test:e2e:run",
2425
"setup": "npm run setup && npm run validate"
2526
},
2627
"keywords": [],
2728
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
28-
"license": "GPLv3",
29+
"license": "GPL-3.0",
2930
"devDependencies": {
3031
"@babel/core": "^7.0.0-beta.51",
3132
"@babel/plugin-proposal-class-properties": "7.0.0-beta.51",
@@ -34,7 +35,7 @@
3435
"@babel/preset-env": "^7.0.0-beta.51",
3536
"@babel/preset-react": "^7.0.0-beta.51",
3637
"babel-core": "7.0.0-bridge.0",
37-
"babel-loader": "^7.1.4",
38+
"babel-loader": "^8.0.0-beta.4",
3839
"babel-plugin-dynamic-import-node": "^2.0.0",
3940
"babel-plugin-emotion": "^9.2.4",
4041
"css-loader": "^0.28.11",
@@ -71,5 +72,13 @@
7172
"react-emotion": "^9.2.4",
7273
"react-loadable": "^5.4.0",
7374
"react-point": "^3.0.1"
74-
}
75+
},
76+
"repository": {
77+
"type": "git",
78+
"url": "git+https://github.com/kentcdodds/jest-cypress-react-babel-webpack.git"
79+
},
80+
"bugs": {
81+
"url": "https://github.com/kentcdodds/jest-cypress-react-babel-webpack/issues"
82+
},
83+
"homepage": "https://github.com/kentcdodds/jest-cypress-react-babel-webpack#readme"
7584
}

src/shared/__tests__/__snapshots__/calculator-display.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`mounts 1`] = `
3+
exports[`renders 1`] = `
44
.emotion-0 {
55
color: white;
66
background: #1c191c;
@@ -12,7 +12,7 @@ exports[`mounts 1`] = `
1212
}
1313
1414
<div
15-
class="emotion-0"
15+
class="emotion-0 emotion-1"
1616
>
1717
<div
1818
class="autoScalingText"

src/shared/__tests__/auto-scaling-text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import React from 'react'
22
import {render} from 'calculator-test-utils'
33
import AutoScalingText from '../auto-scaling-text'
44

5-
test('mounts', () => {
5+
test('renders', () => {
66
render(<AutoScalingText />)
77
})

src/shared/__tests__/calculator-display.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import {render} from 'calculator-test-utils'
33
import CalculatorDisplay from '../calculator-display'
44

5-
test('mounts', () => {
5+
test('renders', () => {
66
const {container} = render(<CalculatorDisplay value="0" />)
77
expect(container.firstChild).toMatchSnapshot()
88
})

src/shared/__tests__/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {getFormattedValue} from '../utils'
22

3-
test('adds missing .0', () => {
3+
test('formats the value', () => {
44
expect(getFormattedValue('1234.0')).toBe('1,234.0')
55
})

src/shared/calculator-display.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
3+
import styled from 'react-emotion'
34
import AutoScalingText from './auto-scaling-text'
45
import {getFormattedValue} from './utils'
56

7+
const DisplayContainer = styled.div(({theme}) => ({
8+
color: theme.displayTextColor,
9+
background: theme.displayBackgroundColor,
10+
lineHeight: '130px',
11+
fontSize: '6em',
12+
flex: '1',
13+
}))
14+
615
class CalculatorDisplay extends React.Component {
716
static propTypes = {
817
value: PropTypes.string.isRequired,
@@ -15,18 +24,9 @@ class CalculatorDisplay extends React.Component {
1524
)
1625

1726
return (
18-
<div
19-
{...props}
20-
css={{
21-
color: 'white',
22-
background: '#1c191c',
23-
lineHeight: '130px',
24-
fontSize: '6em',
25-
flex: '1',
26-
}}
27-
>
27+
<DisplayContainer {...props}>
2828
<AutoScalingText>{formattedValue}</AutoScalingText>
29-
</div>
29+
</DisplayContainer>
3030
)
3131
}
3232
}

test/jest-common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
rootDir: path.join(__dirname, '..'),
77
moduleDirectories: [
88
'node_modules',
9-
path.join(__dirname, 'src'),
9+
path.join(__dirname, '../src'),
1010
'shared',
1111
__dirname,
1212
],

test/jest.lint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ module.exports = {
55
displayName: 'lint',
66
runner: 'jest-runner-eslint',
77
testMatch: ['<rootDir>/**/*.js'],
8-
testPathIgnorePatterns: ['/node_modules/', '/coverage/', '/dist/'],
8+
testPathIgnorePatterns: ['/node_modules/', '/coverage/', '/dist/', '/other/'],
99
}

0 commit comments

Comments
 (0)