From f88581667cfd82f7c8e855b333e0c0fbbfc2d6dc Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 24 Nov 2016 17:33:16 +0000 Subject: [PATCH] Add failing tests for coroutines There are a few different issues: * Updates result in unnecessary duplicate placements because it can't find the current fiber for continuations. * When run together, coroutine update and unmounting tests appear to lock down in an infinite loop. They don't freeze in isolation. I don't have a solution for this but just leaving it for future fixes. --- .../fiber/__tests__/ReactCoroutine-test.js | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/__tests__/ReactCoroutine-test.js b/src/renderers/shared/fiber/__tests__/ReactCoroutine-test.js index a5d54c8041a..59501305ff0 100644 --- a/src/renderers/shared/fiber/__tests__/ReactCoroutine-test.js +++ b/src/renderers/shared/fiber/__tests__/ReactCoroutine-test.js @@ -23,12 +23,21 @@ describe('ReactCoroutine', () => { ReactCoroutine = require('ReactCoroutine'); }); + function div(...children) { + children = children.map(c => typeof c === 'string' ? { text: c } : c); + return { type: 'div', children, prop: undefined }; + } + + function span(prop) { + return { type: 'span', children: [], prop }; + } + it('should render a coroutine', () => { var ops = []; function Continuation({ isSame }) { ops.push(['Continuation', isSame]); - return {isSame ? 'foo==bar' : 'foo!=bar'}; + return ; } // An alternative API could mark Continuation as something that needs @@ -82,6 +91,64 @@ describe('ReactCoroutine', () => { ['Continuation', true], ['Continuation', false], ]); + expect(ReactNoop.getChildren()).toEqual([ + div( + span('foo==bar'), + span('foo!=bar'), + ), + ]); + }); + + it('should update a coroutine', () => { + function Continuation({ isSame }) { + return ; + } + + function Child({ bar }) { + return ReactCoroutine.createYield({ + bar: bar, + }, Continuation, null); + } + + function Indirection() { + return [, ]; + } + + function HandleYields(props, yields) { + return yields.map(y => + + ); + } + + function Parent(props) { + return ReactCoroutine.createCoroutine( + props.children, + HandleYields, + props + ); + } + + function App(props) { + return
; + } + + ReactNoop.render(); + ReactNoop.flush(); + expect(ReactNoop.getChildren()).toEqual([ + div( + span('foo==bar'), + span('foo!=bar'), + ), + ]); + + ReactNoop.render(); + ReactNoop.flush(); + expect(ReactNoop.getChildren()).toEqual([ + div( + span('foo!=bar'), + span('foo==bar'), + ), + ]); }); it('should unmount a composite in a coroutine', () => {