Skip to content

Commit 239ca5d

Browse files
committed
fix(react-hot-loader): fix missing export
1 parent bed0bb2 commit 239ca5d

File tree

3 files changed

+169
-158
lines changed

3 files changed

+169
-158
lines changed

Diff for: packages/react-hot-loader/src/patch.dev.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ import React from 'react'
22
import reactHotLoader from './reactHotLoader'
33

44
reactHotLoader.patch(React)
5+
6+
export default reactHotLoader

Diff for: packages/react-hot-loader/test/patch.dev.test.js

+11-158
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,16 @@
11
/* eslint-env jest */
2-
32
import React from 'react'
4-
import '../lib/patch.dev'
5-
import RHL from '../lib/reactHotLoader'
6-
7-
RHL.disableComponentProxy = true
8-
9-
function A1() {}
10-
function A2() {}
11-
function A3() {}
12-
function B1() {}
13-
function B2() {}
14-
15-
function runAllTests(useWeakMap) {
16-
describe('patch', () => {
17-
beforeEach(() => {
18-
RHL.reset(useWeakMap)
19-
})
20-
21-
it('is identity for unrecognized types', () => {
22-
expect(<div />.type).toBe('div')
23-
expect(<A1 />.type).toBe(A1)
24-
})
25-
26-
it('report proxy named duplicates', () => {
27-
const createUniqueComponent = variable => () => <div>123{variable}</div>
28-
const f1 = createUniqueComponent(1)
29-
const f2 = createUniqueComponent(2)
30-
f2.displayName = 'another'
31-
32-
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
33-
34-
try {
35-
RHL.register(createUniqueComponent, 'f1', '/wow/test.js')
36-
React.createElement(f1)
37-
React.createElement(f1)
38-
expect(console.warn.mock.calls.length).toBe(0)
39-
RHL.register(createUniqueComponent, 'f1', '/wow/test.js')
40-
React.createElement(f2)
41-
expect(console.warn.mock.calls.length).toBe(0)
42-
} finally {
43-
spy.mockRestore()
44-
}
45-
})
46-
47-
it('resolves registered types by their last ID', () => {
48-
RHL.register(A1, 'a', 'test.js')
49-
const A = <A1 />.type
50-
expect(A).not.toBe(A1)
51-
expect(A).toBeInstanceOf(Function)
52-
expect(<A />.type).toBe(A)
53-
54-
RHL.register(A2, 'a', 'test.js')
55-
expect(<A1 />.type).toBe(A)
56-
expect(<A2 />.type).toBe(A)
57-
expect(<A />.type).toBe(A)
3+
import reactHotLoader from '../src/reactHotLoader'
4+
import patchExport from '../src/patch.dev'
585

59-
RHL.register(A3, 'a', 'test.js')
60-
expect(<A1 />.type).toBe(A)
61-
expect(<A2 />.type).toBe(A)
62-
expect(<A3 />.type).toBe(A)
63-
expect(<A />.type).toBe(A)
64-
65-
RHL.register(B1, 'b', 'test.js')
66-
const B = <B1 />.type
67-
expect(<A1 />.type).toBe(A)
68-
expect(<A2 />.type).toBe(A)
69-
expect(<A3 />.type).toBe(A)
70-
expect(<A />.type).toBe(A)
71-
expect(<B1 />.type).toBe(B)
72-
expect(<B />.type).toBe(B)
73-
74-
RHL.register(B2, 'b', 'test.js')
75-
expect(<A1 />.type).toBe(A)
76-
expect(<A2 />.type).toBe(A)
77-
expect(<A3 />.type).toBe(A)
78-
expect(<A />.type).toBe(A)
79-
expect(<B1 />.type).toBe(B)
80-
expect(<B2 />.type).toBe(B)
81-
expect(<B />.type).toBe(B)
82-
})
83-
84-
it('works with reexported types', () => {
85-
RHL.register(A1, 'a', 'test.js')
86-
RHL.register(A1, 'x', 'test2.js')
87-
88-
const A = <A1 />.type
89-
expect(A.type).not.toBe(A1)
90-
expect(A).toBeInstanceOf(Function)
91-
expect(<A />.type).toBe(A)
92-
93-
RHL.register(A2, 'a', 'test.js')
94-
RHL.register(A2, 'x', 'test2.js')
95-
expect(<A1 />.type).toBe(A)
96-
expect(<A2 />.type).toBe(A)
97-
expect(<A />.type).toBe(A)
98-
})
99-
100-
it('passes props through', () => {
101-
expect(<div x={42} y="lol" />.props).toEqual({
102-
x: 42,
103-
y: 'lol',
104-
})
105-
expect(<A1 x={42} y="lol" />.props).toEqual({
106-
x: 42,
107-
y: 'lol',
108-
})
109-
110-
RHL.register(B1, 'b', 'test.js')
111-
expect(<B1 x={42} y="lol" />.props).toEqual({
112-
x: 42,
113-
y: 'lol',
114-
})
115-
RHL.register(B2, 'b', 'test.js')
116-
expect(<B2 x={42} y="lol" />.props).toEqual({
117-
x: 42,
118-
y: 'lol',
119-
})
120-
})
121-
122-
it('passes children through', () => {
123-
expect(
124-
(
125-
<div>
126-
{'Hi'}
127-
{'Bye'}
128-
</div>
129-
).props.children,
130-
).toEqual(['Hi', 'Bye'])
131-
expect(
132-
(
133-
<A1>
134-
{'Hi'}
135-
{'Bye'}
136-
</A1>
137-
).props.children,
138-
).toEqual(['Hi', 'Bye'])
139-
140-
RHL.register(B1, 'b', 'test.js')
141-
expect(
142-
(
143-
<B1>
144-
{'Hi'}
145-
{'Bye'}
146-
</B1>
147-
).props.children,
148-
).toEqual(['Hi', 'Bye'])
149-
RHL.register(B2, 'b', 'test.js')
150-
expect(
151-
(
152-
<B2>
153-
{'Hi'}
154-
{'Bye'}
155-
</B2>
156-
).props.children,
157-
).toEqual(['Hi', 'Bye'])
158-
})
6+
describe('patch', () => {
7+
it('should export reactHotLoader', () => {
8+
expect(patchExport).toBe(reactHotLoader)
1599
})
160-
}
16110

162-
runAllTests(true)
163-
runAllTests(false)
11+
it('should patch React methods', () => {
12+
expect(React.createElement.isPatchedByReactHotLoader).toBe(true)
13+
expect(React.createFactory.isPatchedByReactHotLoader).toBe(true)
14+
expect(React.Children.only.isPatchedByReactHotLoader).toBe(true)
15+
})
16+
})
+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/* eslint-env jest */
2+
3+
import React from 'react'
4+
import '../lib/patch.dev'
5+
import RHL from '../lib/reactHotLoader'
6+
7+
RHL.disableComponentProxy = true
8+
9+
function A1() {}
10+
function A2() {}
11+
function A3() {}
12+
function B1() {}
13+
function B2() {}
14+
15+
describe('reactHotLoader', () => {
16+
beforeEach(() => RHL.reset())
17+
18+
it('is identity for unrecognized types', () => {
19+
expect(<div />.type).toBe('div')
20+
expect(<A1 />.type).toBe(A1)
21+
})
22+
23+
it('report proxy named duplicates', () => {
24+
const createUniqueComponent = variable => () => <div>123{variable}</div>
25+
const f1 = createUniqueComponent(1)
26+
const f2 = createUniqueComponent(2)
27+
f2.displayName = 'another'
28+
29+
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
30+
31+
try {
32+
RHL.register(createUniqueComponent, 'f1', '/wow/test.js')
33+
React.createElement(f1)
34+
React.createElement(f1)
35+
expect(console.warn.mock.calls.length).toBe(0)
36+
RHL.register(createUniqueComponent, 'f1', '/wow/test.js')
37+
React.createElement(f2)
38+
expect(console.warn.mock.calls.length).toBe(0)
39+
} finally {
40+
spy.mockRestore()
41+
}
42+
})
43+
44+
it('resolves registered types by their last ID', () => {
45+
RHL.register(A1, 'a', 'test.js')
46+
const A = <A1 />.type
47+
expect(A).not.toBe(A1)
48+
expect(A).toBeInstanceOf(Function)
49+
expect(<A />.type).toBe(A)
50+
51+
RHL.register(A2, 'a', 'test.js')
52+
expect(<A1 />.type).toBe(A)
53+
expect(<A2 />.type).toBe(A)
54+
expect(<A />.type).toBe(A)
55+
56+
RHL.register(A3, 'a', 'test.js')
57+
expect(<A1 />.type).toBe(A)
58+
expect(<A2 />.type).toBe(A)
59+
expect(<A3 />.type).toBe(A)
60+
expect(<A />.type).toBe(A)
61+
62+
RHL.register(B1, 'b', 'test.js')
63+
const B = <B1 />.type
64+
expect(<A1 />.type).toBe(A)
65+
expect(<A2 />.type).toBe(A)
66+
expect(<A3 />.type).toBe(A)
67+
expect(<A />.type).toBe(A)
68+
expect(<B1 />.type).toBe(B)
69+
expect(<B />.type).toBe(B)
70+
71+
RHL.register(B2, 'b', 'test.js')
72+
expect(<A1 />.type).toBe(A)
73+
expect(<A2 />.type).toBe(A)
74+
expect(<A3 />.type).toBe(A)
75+
expect(<A />.type).toBe(A)
76+
expect(<B1 />.type).toBe(B)
77+
expect(<B2 />.type).toBe(B)
78+
expect(<B />.type).toBe(B)
79+
})
80+
81+
it('works with reexported types', () => {
82+
RHL.register(A1, 'a', 'test.js')
83+
RHL.register(A1, 'x', 'test2.js')
84+
85+
const A = <A1 />.type
86+
expect(A.type).not.toBe(A1)
87+
expect(A).toBeInstanceOf(Function)
88+
expect(<A />.type).toBe(A)
89+
90+
RHL.register(A2, 'a', 'test.js')
91+
RHL.register(A2, 'x', 'test2.js')
92+
expect(<A1 />.type).toBe(A)
93+
expect(<A2 />.type).toBe(A)
94+
expect(<A />.type).toBe(A)
95+
})
96+
97+
it('passes props through', () => {
98+
expect(<div x={42} y="lol" />.props).toEqual({
99+
x: 42,
100+
y: 'lol',
101+
})
102+
expect(<A1 x={42} y="lol" />.props).toEqual({
103+
x: 42,
104+
y: 'lol',
105+
})
106+
107+
RHL.register(B1, 'b', 'test.js')
108+
expect(<B1 x={42} y="lol" />.props).toEqual({
109+
x: 42,
110+
y: 'lol',
111+
})
112+
RHL.register(B2, 'b', 'test.js')
113+
expect(<B2 x={42} y="lol" />.props).toEqual({
114+
x: 42,
115+
y: 'lol',
116+
})
117+
})
118+
119+
it('passes children through', () => {
120+
expect(
121+
(
122+
<div>
123+
{'Hi'}
124+
{'Bye'}
125+
</div>
126+
).props.children,
127+
).toEqual(['Hi', 'Bye'])
128+
expect(
129+
(
130+
<A1>
131+
{'Hi'}
132+
{'Bye'}
133+
</A1>
134+
).props.children,
135+
).toEqual(['Hi', 'Bye'])
136+
137+
RHL.register(B1, 'b', 'test.js')
138+
expect(
139+
(
140+
<B1>
141+
{'Hi'}
142+
{'Bye'}
143+
</B1>
144+
).props.children,
145+
).toEqual(['Hi', 'Bye'])
146+
RHL.register(B2, 'b', 'test.js')
147+
expect(
148+
(
149+
<B2>
150+
{'Hi'}
151+
{'Bye'}
152+
</B2>
153+
).props.children,
154+
).toEqual(['Hi', 'Bye'])
155+
})
156+
})

0 commit comments

Comments
 (0)