Skip to content

feat(fakeAsync): allow simulating the passage of time - #1837

Merged
vicb merged 1 commit into
angular:masterfrom
vicb:0512-fakeAsync
May 19, 2015
Merged

vicb merged 1 commit into
angular:masterfrom
vicb:0512-fakeAsync

Conversation

@vicb

@vicb vicb commented May 12, 2015

Copy link
Copy Markdown
Contributor

relates to #1146

Implementation details:

  1. The test function should be wrapped in a fakeAsync(testFn)
  2. tick(millis) and flushMicrotasks() are top level functions in the fake_async module. Passing a fakeAsync instance to test function would not play well with inject().

JS specific

Based on Jasmine async mocks.
There is one bug in <2.3.3 that prevents a periodic timer from being cancelled from within its callback. It explains why 1 test is skipped with jasmine. I have opened a separate issue for this.

Warning: fakeAsync() is not usable in the CJS environment where global.zone is not available

Dart specific

Based on quiver.
It is not (yet) possible to get the number of pending timers at the end of the fakeAsync().
I have submitted an issue to quiver (link below).
@matanlurey @jbdeboer @yjbanov could you help with that ?

Due to the item 2 above, fakeAsync() is not re-entrant in Dart. I don't think this is a problem ?

/cc @mhevery @yjbanov @tbosch

TODO

@vicb
vicb force-pushed the 0512-fakeAsync branch 8 times, most recently from 4d6e683 to 99ad9c0 Compare May 12, 2015 17:59
@vicb
vicb force-pushed the 0512-fakeAsync branch 2 times, most recently from 6541eb3 to dfec3ff Compare May 12, 2015 20:20
@vicb
vicb force-pushed the 0512-fakeAsync branch 3 times, most recently from 36e1be8 to f646107 Compare May 13, 2015 13:30
@vicb vicb changed the title [WIP] Fake async Fake async May 13, 2015
@vicb
vicb force-pushed the 0512-fakeAsync branch from f646107 to 697047d Compare May 13, 2015 13:52
@vicb vicb changed the title Fake async feat(fakeAsync): allow simulating the passage of time May 13, 2015
@vicb

vicb commented May 13, 2015

Copy link
Copy Markdown
Contributor Author

@matanlurey @yjbanov could one of you please review the PR ?

@vicb vicb added feature Label used to distinguish feature request from other issues area: testing Issues related to Angular testing features, such as TestBed labels May 13, 2015
@vicb
vicb force-pushed the 0512-fakeAsync branch from 697047d to 31e0b18 Compare May 13, 2015 14:12
@vicb

vicb commented May 13, 2015

Copy link
Copy Markdown
Contributor Author

@tbosch

tbosch commented May 13, 2015

Copy link
Copy Markdown
Contributor

They are probably missing a "library" statement at their top
On Wed, May 13, 2015 at 7:15 AM Victor Berchet notifications@github.com
wrote:

There is an error in Dart: The imported libraries 'fake_async.dart' and
'lang_utils.dart' cannot both be unnamed
(/home/travis/build/angular/angular/dist/dart/angular2/_analyzer.dart, line
169, col 1) https://travis-ci.org/angular/angular/jobs/62401155#L1125

Any idea what could go wrong ?

/cc @kevmoo https://github.com/kevmoo

—
Reply to this email directly or view it on GitHub
#1837 (comment).

@vicb

vicb commented May 13, 2015

Copy link
Copy Markdown
Contributor Author

@tbosch very good catch, thanks !

@vicb
vicb force-pushed the 0512-fakeAsync branch 3 times, most recently from 3a8f336 to c756896 Compare May 13, 2015 14:57
Comment thread modules/angular2/pubspec.yaml Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if quiver should be a regular dependency not a dev dependency; dev dependencies are for dependencies that are only needed when developing this package. The key difference in how they are handled is how they propagate to users of this package; dev dependencies won't be installed if someone is just using angular, which means that if someone adds angular as a dep without also adding quiver as a dep, then the fake_async library will be broken.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I was unsure when I added it.

There are actually 2 pubspec modified by this release:

  1. modules/angular2/pubspec.yaml,
  2. /pubspec.yaml

Is 1 used by the generated angular2 pub pkg and need to have quiver as a dependency ?
Is 2 used internally by angluar2 test and can have quiver as a dev*dependency ?

/cc @yjbanov

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For 2, is something there actually directly using quiver (it doesn't look like it to me, but I don't fully understand what is going on here)? If not then, it should just be removed from 2.

@seaneagan

Copy link
Copy Markdown

Regarding the last checkbox, you can't use Zones to "monkey patch" arbitrary statics like new Date.now() or new Stopwatch() in dart, so you have to introduce another abstraction. I've done that in the the clock package, and integrated it into the fake_async package.

@vicb

vicb commented May 13, 2015

Copy link
Copy Markdown
Contributor Author

@seaneagan thanks for the info. I'll probably handle this as a separate PR. I'll make sure to your comment into account.

@vicb
vicb force-pushed the 0512-fakeAsync branch from 55623f4 to 2396d87 Compare May 14, 2015 17:03
@vicb

vicb commented May 14, 2015

Copy link
Copy Markdown
Contributor Author

rebased and updated the internal pubspec.yaml to list quiver in dependencies

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use 80-character line length in Dart files

@yjbanov

yjbanov commented May 18, 2015

Copy link
Copy Markdown
Contributor

Some code style nits. LGTM otherwise.

@yjbanov yjbanov added the @lgtm label May 18, 2015
@vicb

vicb commented May 19, 2015

Copy link
Copy Markdown
Contributor Author

@yjbanov could you please udpdate https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-coding-rules with wathever convetion we should use for Dart (ie Dart style guide plus emphasis the 80 ch limit as we use 100 for JS)

@vicb
vicb force-pushed the 0512-fakeAsync branch 3 times, most recently from 9dcf9bb to 4bb6d7a Compare May 19, 2015 04:22
@vicb

vicb commented May 19, 2015

Copy link
Copy Markdown
Contributor Author

@yjbanov any update on the release of quiver ?

@vicb
vicb force-pushed the 0512-fakeAsync branch from 4bb6d7a to 0f002a5 Compare May 19, 2015 04:51
@vicb
vicb merged commit 0f002a5 into angular:master May 19, 2015
@vicb vicb removed the in progress label May 19, 2015
@vicb
vicb deleted the 0512-fakeAsync branch May 19, 2015 06:35
@yjbanov

yjbanov commented May 19, 2015

Copy link
Copy Markdown
Contributor

@cbracken what's the status of quiver 0.21.4 release?

@vicb

vicb commented May 27, 2015

Copy link
Copy Markdown
Contributor Author

@cbracken what's the status of quiver 0.21.4 release?

@cbracken

Copy link
Copy Markdown

@vicb We're good to release any time. Is there anything left to be merged on this PR before we release?

@vicb

vicb commented May 27, 2015

Copy link
Copy Markdown
Contributor Author

nothing more on my side, thanks

@cbracken

Copy link
Copy Markdown

Published!

@vicb

vicb commented May 27, 2015

Copy link
Copy Markdown
Contributor Author

Thanks @cbracken

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: testing Issues related to Angular testing features, such as TestBed cla: yes feature Label used to distinguish feature request from other issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants