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

[Flight] Basic Integration Test #17307

Merged
merged 8 commits into from
Nov 9, 2019
Merged

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Nov 7, 2019

This adds a basic integration test where we actually feed the model to ReactDOM components and use Suspense. The test verifies that we can stream data and reveal more content as it happens. We also verify errors work.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 7, 2019

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5e3e1e7:

Sandbox Source
peaceful-hugle-190t5 Configuration

@sizebot
Copy link

sizebot commented Nov 7, 2019

Warnings
⚠️ Base commit is broken: 182f64f

Size changes (stable)

Generated by 🚫 dangerJS against 5e3e1e7

};
}

async function waitForDOMChange(container) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda wonky but I wanted to check for next mutation specifically rather than manually wait for models. Since React itself would wait for models and I want to test it waits correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn’t this what async act is for? Why isn’t it sufficient? It’s supposed to force flush even if it suspends and wait for nested promises.

What’s missing and can we fix that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol I forgot about it. Let me try it

@sizebot
Copy link

sizebot commented Nov 7, 2019

Warnings
⚠️ Base commit is broken: 182f64f

Size changes (experimental)

Generated by 🚫 dangerJS against 5e3e1e7

@gaearon
Copy link
Collaborator Author

gaearon commented Nov 7, 2019

OK this should work. I need two of them to flush Promise ticks for both client and server.

@gaearon
Copy link
Collaborator Author

gaearon commented Nov 7, 2019

ready for another

// We can now show the sidebar.
resolvePhotosModel();
await act(async () => {
jest.runAllTimers();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no timers in any of your test helpers so you don't need these calls.

I would put resolvePhotosModel inside the act call, even though it happens to work without it:

await act(async () => {
  resolvePhotosModel();
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Node server uses setImmediate for scheduling. So I need at least one per server work request I think.

Copy link
Collaborator

@sebmarkbage sebmarkbage Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need a FlgihtServer.act(...) for that but let's run the timers for now.

@gaearon
Copy link
Collaborator Author

gaearon commented Nov 8, 2019

I pushed an update that shims setImmediate which lets us only have the necessary acts. Otherwise we'd still need two for each — because there's timers between Promises, and act can't help with that. Alternatively we could have something like this but I'd rather not.

@gaearon
Copy link
Collaborator Author

gaearon commented Nov 8, 2019

With act in CM, prod experimental build fails (?!)

@gaearon gaearon merged commit be3bfa6 into facebook:master Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants