-
Notifications
You must be signed in to change notification settings - Fork 10
React 16 + Ref Support #106
Changes from all commits
afe1508
a828f7c
2d5979f
d7ba894
38130be
9f1ab00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
|
|
||
| export default class Refs extends React.Component { | ||
| static propTypes = { | ||
| children: PropTypes.string.isRequired, | ||
| type: PropTypes.oneOf(['string', 'function', 'createRef']).isRequired, | ||
| }; | ||
|
|
||
| ref = React.createRef(); | ||
|
|
||
| render() { | ||
| switch (this.props.type) { | ||
| case 'string': | ||
| return ( | ||
| // eslint-disable-next-line react/no-string-refs | ||
| <div ref="test"> | ||
| {this.props.children} | ||
| </div> | ||
| ); | ||
|
|
||
| case 'function': | ||
| return ( | ||
| <div | ||
| ref={el => { | ||
| this.el = el; | ||
| }} | ||
| > | ||
| {this.props.children} | ||
| </div> | ||
| ); | ||
|
|
||
| case 'createRef': | ||
| return ( | ||
| <div ref={this.ref}> | ||
| {this.props.children} | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import React from 'react'; | ||
| import Refs from '../Refs'; | ||
|
|
||
| suite('Refs', () => { | ||
| percySnapshot('components with string refs work', () => { | ||
| return <Refs type="string">This is some text</Refs>; | ||
| }); | ||
|
|
||
| percySnapshot('components with function refs work', () => { | ||
| return <Refs type="function">This is some text</Refs>; | ||
| }); | ||
|
|
||
| percySnapshot('components using createRef work', () => { | ||
| return <Refs type="createRef">This is some text</Refs>; | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| "lerna": "^2.0.0", | ||
| "lint-staged": "^3.3.1", | ||
| "prettier": "^1.5.3", | ||
| "raf": "^3.4.0", | ||
| "rimraf": "^2.5.4", | ||
| "tar.gz": "^1.0.5", | ||
| "vitruvius": "^3.0.0" | ||
|
|
@@ -44,6 +45,9 @@ | |
| "<rootDir>/integration-tests/", | ||
| "<rootDir>/packages/" | ||
| ], | ||
| "setupFiles": [ | ||
| "raf/polyfill" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. React 16 requires a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like Jest
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing, I’ll toss up a separate PR for that next week. I’m off on vacation till then :) |
||
| ], | ||
| "testPathIgnorePatterns": [ | ||
| "/node_modules/", | ||
| "<rootDir>/integration-tests/create-react-app", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,9 +25,15 @@ export default async function run(percyConfig, percyToken) { | |
| const assets = await compile(percyConfig); | ||
|
|
||
| const environment = new Environment(); | ||
| const runtimeEntry = findEntryPath(assets, EntryNames.runtime); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The runtime entry contains a manifest webpack uses to make sure imports work correctly across entries now that we're splitting some dependencies out into the vendor bundle. The vendor bundle contains |
||
| const vendorEntry = findEntryPath(assets, EntryNames.vendor); | ||
| const snapshotsEntry = findEntryPath(assets, EntryNames.snapshots); | ||
| debug('executing snapshots script'); | ||
| environment.runScript(assets[snapshotsEntry]); | ||
| debug('executing scripts'); | ||
| environment.runScript(` | ||
| ${assets[runtimeEntry]} | ||
| ${assets[vendorEntry]} | ||
| ${assets[snapshotsEntry]} | ||
| `); | ||
|
|
||
| debug('getting snapshots'); | ||
| const snapshots = environment.getSnapshotDefinitions(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,16 +15,16 @@ | |
| "lib" | ||
| ], | ||
| "peerDependencies": { | ||
| "react": "^15.4.0", | ||
| "react-dom": "^15.4.0" | ||
| "react": "^15.4.0 || ^16.0.0", | ||
| "react-dom": "^15.4.0 || ^16.0.0" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows users to have either React 15 or React 16 in their projects without getting any peer dependency warnings. |
||
| }, | ||
| "dependencies": { | ||
| "babel-runtime": "^6.26.0", | ||
| "redbox-react": "^1.5.0" | ||
| "redbox-react": "^1.6.0" | ||
| }, | ||
| "devDependencies": { | ||
| "react": "^15.6.1", | ||
| "react-dom": "^15.6.1" | ||
| "react": "^16.5.2", | ||
| "react-dom": "^16.5.2" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`renders error message into the DOM element when rendering fails 1`] = `"<div data-reactroot=\\"\\">Cannot read property 'format' of undefined</div>"`; | ||
| exports[`renders error message into the DOM element when rendering fails 1`] = `"<div>Cannot read property 'format' of undefined</div>"`; | ||
|
|
||
| exports[`renders the specified React markup into the DOM element 1`] = `"<div data-reactroot=\\"\\">some markup</div>"`; | ||
| exports[`renders the specified React markup into the DOM element 1`] = `"<div>some markup</div>"`; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,9 @@ jest.mock('redbox-react', () => ({ error }) => | |
| ); | ||
| /* eslint-enable react/display-name, react/prop-types */ | ||
|
|
||
| // eslint-disable-next-line no-console | ||
| console.error = jest.fn(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test purposefully causes an error to get thrown so we can verify it's getting rendered. React 16 has a new mechanism for catching errors and prints a console error here, but it's not really useful in the context of this test. |
||
|
|
||
| let el; | ||
|
|
||
| beforeEach(() => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A while back we discussed adding better integration test coverage of multiple React versions. Might be worth a separate PR that adds coverage for both React 15 and 16 and both create-react-app 1 and 2.