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

feat: support schedulers within run #5619

Merged
merged 10 commits into from
Aug 4, 2020

Conversation

cartant
Copy link
Collaborator

@cartant cartant commented Aug 1, 2020

Description:

In #5607, an animate function was added to the run helpers to enable the testing of the animationFrames observable.

IMO, if we are going to extend the TestScheduler to facilitate the testing of animationFrames, we might as well extend it so that the animateFrameScheduler is testable, too. And if that's done, we might as well make the asapScheduler testable.

This PR adds providers and delegates for set/clearImmediate and set/clearInterval so that schedulers can be supported within TestScheduler#run in a manner similar to the animationFrames observable.

The AsyncScheduler.delegate has been removed, as all delegation now happens via the providers.

This test demonstrates the behaviour of the delegated implementation with the TestScheduler:

it('should support animationFrame, async and asap schedulers', () => {
  const testScheduler = new TestScheduler(assertDeepEquals);
  testScheduler.run(({ animate, cold, expectObservable, time }) => {
    animate('            ---------x');
    const mapped = cold('--m-------');
    const tb = time('      -----|  ');
    const expected = '   --(dc)-b-a';
    const result = mapped.pipe(mergeMap(() => merge(
      of('a').pipe(delay(0, animationFrameScheduler)),
      of('b').pipe(delay(tb, asyncScheduler)),
      of('c').pipe(delay(0, asyncScheduler)),
      of('d').pipe(delay(0, asapScheduler))
    )));
    expectObservable(result).toBe(expected);
  });
});
  • asap actions are executed before any async actions on the same marble
  • animationFrame actions are executed when specified via the animate helper

A bunch of tests are added to the TestScheduler 'run mode' tests and some of the more high-level AnimationFrameScheduler, AsapScheduler and QueueScheduler tests are replaced with 'run mode'/marble tests.

Related issue (if exists): None

@cartant cartant changed the title WIP: feat: support schedulers within run feat: support schedulers within run Aug 2, 2020
@cartant cartant marked this pull request as ready for review August 2, 2020 02:18
@cartant cartant requested a review from benlesh August 2, 2020 02:18
fakeTimer.tick(25);
expect(actionHappened).to.be.true;
sandbox.restore();
testScheduler.run(({ cold, expectObservable, time }) => {
Copy link
Member

Choose a reason for hiding this comment

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

This is a nice improvement to these tests!

Copy link
Member

@benlesh benlesh left a comment

Choose a reason for hiding this comment

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

I think I'll do a follow up to kill the name setImmediate, as that's not really what this does anymore. setImmediate is a failed proposal from back when RxJS 5 was under development 6 years ago. This is really doing microtask scheduling or next tick ..

@benlesh benlesh merged commit c63de0d into ReactiveX:master Aug 4, 2020
@benlesh
Copy link
Member

benlesh commented Aug 4, 2020

Very nice work! Thanks @cartant!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants