Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using the wrong renderer's act() should warn #15399

Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c35e37a
mark react-events as private so we publish script skips it for now
Apr 3, 2019
dc605c1
Merge remote-tracking branch 'upstream/master'
Apr 3, 2019
a09bd0f
Merge remote-tracking branch 'upstream/master'
Apr 3, 2019
48ffcee
Merge remote-tracking branch 'upstream/master'
Apr 12, 2019
f0c3493
warn when using the wrong act() around create/updates
Apr 12, 2019
c1e2986
Merge remote-tracking branch 'upstream/master' into renderer-specific…
Apr 12, 2019
bd31fed
make a proper fixture for act()
Apr 14, 2019
b417644
cleanup fixtures/dom/.gitignore
Apr 14, 2019
6812f6e
verify that it 'works' with art+dom
Apr 14, 2019
190f656
verify that it 'works' with art+test
Apr 14, 2019
7caa1b2
augh prettier
Apr 14, 2019
4fc4c39
tweak warning messages
Apr 15, 2019
91c5d79
Stop tracking bundle sizes (#15404)
acdlite Apr 12, 2019
46a4237
React events: ignore device buttons that aren't for primary interacti…
necolas Apr 12, 2019
e4d93a7
warn when using the wrong act() around create/updates
Apr 12, 2019
da0e642
Merge branch 'renderer-specific-act-warning' of github.com:threepoint…
Apr 15, 2019
d008007
Merge remote-tracking branch 'upstream/master' into renderer-specific…
Apr 15, 2019
0aebde1
lose ReactActingUpdatesSigil.js, use flushPassiveEffects as the actin…
Apr 15, 2019
7f3fd8f
copy nit
Apr 15, 2019
b0391d7
Update ReactShouldWarnActingUpdates.js
Apr 16, 2019
29e2cc7
rename ReactShouldWarnActingUpdates to ReactActingRendererSigi, merge…
Apr 18, 2019
cd695e6
augh prettier
Apr 18, 2019
d00d827
move the check to updatecontainer, run the act fixtures in ci
Apr 23, 2019
82124cc
s/console.error/spy
Apr 23, 2019
c2a52f5
run yarn before dom-fixture tests
Apr 23, 2019
381d292
Merge branch 'master' into renderer-specific-act-warning
threepointone May 17, 2019
275d47c
Merge branch 'master' into renderer-specific-act-warning
threepointone May 17, 2019
26ce8b4
Merge branch 'master' into renderer-specific-act-warning
threepointone May 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fixtures/act/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
23 changes: 23 additions & 0 deletions fixtures/act/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
6 changes: 6 additions & 0 deletions fixtures/act/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
act() fixtures
---

- `yarn`
- `yarn start` - follow instructions on the page
- `yarn test` - all green
27 changes: 27 additions & 0 deletions fixtures/act/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
threepointone marked this conversation as resolved.
Show resolved Hide resolved
"name": "act",
"version": "0.1.0",
"private": true,
"dependencies": {
"art": "^0.10.3",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "2.1.8"
},
"scripts": {
"prestart": "cp -a ../../build/node_modules/. node_modules",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Binary file added fixtures/act/public/favicon.ico
Binary file not shown.
42 changes: 42 additions & 0 deletions fixtures/act/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
this page tests whether act runs properly in a browser. your console should say "5", a warning about not using the right act(), and some act() errors
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions fixtures/act/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
114 changes: 114 additions & 0 deletions fixtures/act/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import ReactTestRenderer from 'react-test-renderer';

import ReactART from 'react-art';
import ARTSVGMode from 'art/modes/svg';
import ARTCurrentMode from 'art/modes/current';

const {Shape, Surface} = ReactART;

window.jest = {}; // to enable warnings
function App() {
let [state, setState] = React.useState(0);
async function ticker() {
await null;
setState(x => x + 1);
}
React.useEffect(
() => {
ticker();
},
[Math.min(state, 4)]
);
return state;
}

async function testDOMAsynAct() {
// from ReactTestUtilsAct-test.js

const el = document.createElement('div');
await ReactTestUtils.act(async () => {
ReactDOM.render(React.createElement(App), el);
});
// all 5 ticks present and accounted for
console.log(el.innerHTML);
}

async function testMixRenderers() {
await ReactTestUtils.act(async () => {
ReactTestRenderer.create(React.createElement(App));
});
}

async function testARTDOM() {
ARTCurrentMode.setCurrent(ARTSVGMode);
let setState;
function TestComponent(props) {
// eslint-disable-next-line no-unused-vars
const [state, _setState] = React.useState(0);
setState = _setState;

return (
<Surface width={150} height={200}>
<Shape
fill="#3C5A99"
key="b"
scale={0.5}
x={50}
y={50}
title="This is an F"
cursor="pointer">
M64.564,38.583H54l0.008-5.834c0-3.035,0.293-4.666,4.657-4.666
h5.833V16.429h-9.33c-11.213,0-15.159,5.654-15.159,15.16v6.994
h-6.99v11.652h6.99v33.815H54V50.235h9.331L64.564,38.583z
</Shape>
</Surface>
);
}
ReactDOM.render(<TestComponent />, window.root);
ReactTestUtils.act(() => {
setState(2);
});
}

async function testARTTest() {
ARTCurrentMode.setCurrent(ARTSVGMode);
let setState;
function TestComponent(props) {
// eslint-disable-next-line no-unused-vars
const [state, _setState] = React.useState(0);
setState = _setState;

return (
<Surface width={150} height={200}>
<Shape
fill="#3C5A99"
key="b"
scale={0.5}
x={50}
y={50}
title="This is an F"
cursor="pointer">
M64.564,38.583H54l0.008-5.834c0-3.035,0.293-4.666,4.657-4.666
h5.833V16.429h-9.33c-11.213,0-15.159,5.654-15.159,15.16v6.994
h-6.99v11.652h6.99v33.815H54V50.235h9.331L64.564,38.583z
</Shape>
</Surface>
);
}
ReactTestRenderer.create(<TestComponent />);
ReactTestRenderer.act(() => {
setState(2);
});
}

async function run() {
await testDOMAsynAct();
await testMixRenderers();
await testARTDOM();
await testARTTest();
}

run();
78 changes: 78 additions & 0 deletions fixtures/act/src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';
import TestRenderer from 'react-test-renderer';
threepointone marked this conversation as resolved.
Show resolved Hide resolved

let spy;
beforeEach(() => {
spy = jest.spyOn(global.console, 'error');
});

function confirmWarning() {
expect(spy).toHaveBeenCalledWith(
expect.stringContaining(
"It looks like you're using the wrong act() around your test interactions."
),
''
);
}

function App(props) {
return 'hello world';
}

it("doesn't warn when you use the right act + renderer: dom", () => {
TestUtils.act(() => {
TestUtils.renderIntoDocument(<App />);
});
expect(spy).not.toHaveBeenCalled();
});

it("doesn't warn when you use the right act + renderer: test", () => {
TestRenderer.act(() => {
TestRenderer.create(<App />);
});
expect(spy).not.toHaveBeenCalled();
});

it('warns when using the wrong act version - test + dom: render', () => {
TestRenderer.act(() => {
TestUtils.renderIntoDocument(<App />);
});
confirmWarning();
});

it('warns when using the wrong act version - test + dom: updates', () => {
let setCtr;
function Counter(props) {
const [ctr, _setCtr] = React.useState(0);
setCtr = _setCtr;
return ctr;
}
TestUtils.renderIntoDocument(<Counter />);
TestRenderer.act(() => {
setCtr(1);
});
confirmWarning();
});

it('warns when using the wrong act version - dom + test: render', () => {
TestUtils.act(() => {
TestRenderer.create(<App />);
});
confirmWarning();
});

it('warns when using the wrong act version - dom + test: updates', () => {
let setCtr;
function Counter(props) {
const [ctr, _setCtr] = React.useState(0);
setCtr = _setCtr;
return ctr;
}
const root = TestRenderer.create(<Counter />);
TestUtils.act(() => {
setCtr(1);
});
confirmWarning();
});
Loading