From d278a3ff8b2863afb9ab7807e42d31f33c84eb78 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Thu, 16 May 2019 17:12:36 +0100 Subject: [PATCH] `act()` - s / flushPassiveEffects / Scheduler.unstable_flushWithoutYielding (#15591) * s/flushPassiveEffects/unstable_flushWithoutYielding a first crack at flushing the scheduler manually from inside act(). uses unstable_flushWithoutYielding(). The tests that changed, mostly replaced toFlushAndYield(...) with toHaveYielded(). For some tests that tested the state of the tree before flushing effects (but still after updates), I replaced act() with bacthedUpdates(). * ugh lint * pass build, flushPassiveEffects returns nothing now * pass test-fire * flush all work (not just effects), add a compatibility mode of note, unstable_flushWithoutYielding now returns a boolean much like flushPassiveEffects * umd build for scheduler/unstable_mock, pass the fixture with it * add a comment to Shcduler.umd.js for why we're exporting unstable_flushWithoutYielding * run testsutilsact tests in both sync/concurrent modes * augh lint * use a feature flag for the missing mock scheduler warning I also tried writing a test for it, but couldn't get the scheduler to unmock. included the failing test. * Update ReactTestUtilsAct-test.js - pass the mock scheduler warning test, - rewrite some tests to use Scheduler.yieldValue - structure concurrent/legacy suites neatly * pass failing tests in batchedmode-test * fix pretty/lint/import errors * pass test-build * nit: pull .create(null) out of the act() call --- fixtures/dom/.gitignore | 2 + fixtures/dom/package.json | 2 +- fixtures/dom/public/act-dom.html | 4 + .../ReactTestUtilsAct-test.internal.js | 28 + .../src/__tests__/ReactTestUtilsAct-test.js | 791 +++++++++--------- .../src/test-utils/ReactTestUtilsAct.js | 42 +- .../src/createReactNoop.js | 43 +- .../ReactBatchedMode-test.internal.js | 6 +- .../src/__tests__/ReactHooks-test.internal.js | 71 +- ...eactHooksWithNoopRenderer-test.internal.js | 60 +- ...eactIncrementalScheduling-test.internal.js | 6 +- .../__tests__/ReactNoopRendererAct-test.js | 9 +- .../src/ReactTestRendererAct.js | 42 +- .../src/forks/SchedulerHostConfig.mock.js | 6 +- packages/shared/ReactFeatureFlags.js | 3 + .../forks/ReactFeatureFlags.native-fb.js | 1 + .../forks/ReactFeatureFlags.native-oss.js | 1 + .../forks/ReactFeatureFlags.persistent.js | 1 + .../forks/ReactFeatureFlags.test-renderer.js | 1 + .../ReactFeatureFlags.test-renderer.www.js | 1 + .../shared/forks/ReactFeatureFlags.www.js | 2 + packages/shared/forks/Scheduler.umd.js | 5 + scripts/rollup/bundles.js | 9 +- 23 files changed, 642 insertions(+), 494 deletions(-) create mode 100644 packages/react-dom/src/__tests__/ReactTestUtilsAct-test.internal.js diff --git a/fixtures/dom/.gitignore b/fixtures/dom/.gitignore index 724d1459422c..3473f8a18efa 100644 --- a/fixtures/dom/.gitignore +++ b/fixtures/dom/.gitignore @@ -8,6 +8,8 @@ coverage # production build +public/scheduler-unstable_mock.development.js +public/scheduler-unstable_mock.production.min.js public/react.development.js public/react.production.min.js public/react-dom.development.js diff --git a/fixtures/dom/package.json b/fixtures/dom/package.json index f5f84257f7c8..3282c85fa58a 100644 --- a/fixtures/dom/package.json +++ b/fixtures/dom/package.json @@ -18,7 +18,7 @@ }, "scripts": { "start": "react-scripts start", - "prestart": "cp ../../build/node_modules/react/umd/react.development.js ../../build/node_modules/react-dom/umd/react-dom.development.js ../../build/node_modules/react/umd/react.production.min.js ../../build/node_modules/react-dom/umd/react-dom.production.min.js ../../build/node_modules/react-dom/umd/react-dom-server.browser.development.js ../../build/node_modules/react-dom/umd/react-dom-server.browser.production.min.js ../../build/node_modules/react-dom/umd/react-dom-test-utils.development.js ../../build/node_modules/react-dom/umd/react-dom-test-utils.production.min.js public/", + "prestart": "cp ../../build/node_modules/scheduler/umd/scheduler-unstable_mock.development.js ../../build/node_modules/scheduler/umd/scheduler-unstable_mock.production.min.js ../../build/node_modules/react/umd/react.development.js ../../build/node_modules/react-dom/umd/react-dom.development.js ../../build/node_modules/react/umd/react.production.min.js ../../build/node_modules/react-dom/umd/react-dom.production.min.js ../../build/node_modules/react-dom/umd/react-dom-server.browser.development.js ../../build/node_modules/react-dom/umd/react-dom-server.browser.production.min.js ../../build/node_modules/react-dom/umd/react-dom-test-utils.development.js ../../build/node_modules/react-dom/umd/react-dom-test-utils.production.min.js public/", "build": "react-scripts build && cp build/index.html build/200.html", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" diff --git a/fixtures/dom/public/act-dom.html b/fixtures/dom/public/act-dom.html index 2fb4a437721d..2100026a5ba4 100644 --- a/fixtures/dom/public/act-dom.html +++ b/fixtures/dom/public/act-dom.html @@ -7,7 +7,11 @@ this page tests whether act runs properly in a browser.
your console should say "5" + +