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

Jest: Add setSystemTime and getRealSystemTime fn types #45496

Merged
merged 3 commits into from
Jun 24, 2020

Conversation

liamfd
Copy link
Contributor

@liamfd liamfd commented Jun 15, 2020

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes:
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the header.
    • Not sure if I'll need to make a change here - these types are valid and work at runtime for the current version of jest. The PR I have open for essentially just updates jest's internal types and docs to reflect that, so I'm not sure if it would be better to update the version reference, given that it should be compatible with both. Regardless, the current header says 26.0 and if my jest PR is accepted I would assume it would be a patch release.
  • Include tests for your changes
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }. If for reason the any rule need to be disabled, disable it for that line using // tslint:disable-next-line [ruleName] and not for whole package so that the need for disabling can be reviewed.

@typescript-bot typescript-bot added Where is GH Actions? GH Actions didn't give a response to this PR Critical package labels Jun 15, 2020
@typescript-bot
Copy link
Contributor

typescript-bot commented Jun 15, 2020

@liamfd Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — keep an eye on this comment as I'll be updating it with information as things progress.

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ❌ Most recent commit is approved by DT maintainers

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 45496,
  "author": "liamfd",
  "owners": [
    "NoHomey",
    "jwbay",
    "asvetliakov",
    "alexjoverm",
    "epicallan",
    "ikatyang",
    "wsmd",
    "JamieMason",
    "douglasduteil",
    "ahnpnl",
    "joshuakgoldberg",
    "UselessPickles",
    "r3nya",
    "hotell",
    "sebald",
    "andys8",
    "antoinebrault",
    "favna",
    "gstamac",
    "ExE-Boss",
    "quassnoi",
    "Belco90",
    "tonyhallett",
    "ycmjason",
    "devanshj",
    "pawfa",
    "regevbr",
    "mskelton"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "725c00d",
  "headCommitOid": "725c00d5da5651ae54f3b98679d54d28f8279751",
  "mergeIsRequested": false,
  "stalenessInDays": 7,
  "lastCommitDate": "2020-06-16T12:56:12.000Z",
  "lastCommentDate": "2020-06-16T12:56:42.000Z",
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45496/files",
  "hasMergeConflict": false,
  "authorIsOwner": false,
  "isFirstContribution": true,
  "popularityLevel": "Critical",
  "anyPackageIsNew": false,
  "packages": [
    "jest"
  ],
  "files": [
    {
      "filePath": "types/jest/index.d.ts",
      "kind": "definition",
      "package": "jest"
    },
    {
      "filePath": "types/jest/jest-tests.ts",
      "kind": "test",
      "package": "jest"
    }
  ],
  "hasDismissedReview": false,
  "ciResult": "pass",
  "lastReviewDate": "2020-06-17T15:24:58.000Z",
  "reviewersWithStaleReviews": [],
  "approvalFlags": 2,
  "isChangesRequested": false
}

@typescript-bot
Copy link
Contributor

@typescript-bot typescript-bot removed the Where is GH Actions? GH Actions didn't give a response to this PR label Jun 15, 2020
Comment on lines +134 to +143
/**
* Set the current system time used by fake timers. Simulates a user
* changing the system clock while your program is running. It affects the
* current time but it does not in itself cause e.g. timers to fire; they
* will fire exactly as they would have done without the call to
* jest.setSystemTime().
*
* > Note: This function is only available when using modern fake timers
* > implementation
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to follow the comment patterns I observed elsewhere in this file, I just copy pasted this comment and the one below straight out of jest's docs.

* > Note: This function is only available when using modern fake timers
* > implementation
*/
function setSystemTime(now?: number | Date): void;
Copy link
Contributor Author

@liamfd liamfd Jun 15, 2020

Choose a reason for hiding this comment

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

As mentioned in the PR description, jest currently types this as:

    function setSystemTime(now?: number): void;

I have a PR open to expand it to support Date, given that under the hood setSystemTime is calling a function that accepts both. If they do not want to support Date, I will remove it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can hold off on adding support for Date until the other PR is merged to keep things consistent and work as intended? Once that other PR is merged and a newer version of Jest is released with the Date support, we can then update the types here to reflect that latest changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me

Copy link
Contributor

@wsmd wsmd left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @liamfd! This looks good overall. I left one comment suggesting that we hold off on adding support for Date for now.

* > Note: This function is only available when using modern fake timers
* > implementation
*/
function setSystemTime(now?: number | Date): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can hold off on adding support for Date until the other PR is merged to keep things consistent and work as intended? Once that other PR is merged and a newer version of Jest is released with the Date support, we can then update the types here to reflect that latest changes?

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jun 15, 2020
@typescript-bot
Copy link
Contributor

@liamfd One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. If you disagree with the reviewer's comments, you can "dismiss" the review using GitHub's review UI. Thank you!

@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

Comparison details 📊
master #45496 diff
Batch compilation
Memory usage (MiB) 83.4 81.8 -1.9%
Type count 14710 14712 0%
Assignability cache size 4812 4814 0%
Language service
Samples taken 2563 2578 +1%
Identifiers in tests 2563 2578 +1%
getCompletionsAtPosition
    Mean duration (ms) 345.4 349.0 +1.0%
    Mean CV 8.3% 8.2%
    Worst duration (ms) 438.8 476.9 +8.7%
    Worst identifier each toHaveProperty
getQuickInfoAtPosition
    Mean duration (ms) 347.1 350.1 +0.9%
    Mean CV 8.7% 8.6% -1.2%
    Worst duration (ms) 461.4 466.3 +1.1%
    Worst identifier fn each

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Jun 15, 2020
@liamfd liamfd force-pushed the feat/add-new-jest-time-fns branch from 8d9e2d8 to 725c00d Compare June 16, 2020 12:56
@typescript-bot typescript-bot removed the Revision needed This PR needs code changes before it can be merged. label Jun 16, 2020
@typescript-bot
Copy link
Contributor

@wsmd Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

Copy link
Contributor

@wsmd wsmd left a comment

Choose a reason for hiding this comment

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

Thanks @liamfd!

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Jun 17, 2020
@elibarzilay elibarzilay merged commit c98e50d into DefinitelyTyped:master Jun 24, 2020
@typescript-bot
Copy link
Contributor

I just published @types/[email protected] to npm.

ngbrown pushed a commit to ngbrown-forks/DefinitelyTyped that referenced this pull request Jul 11, 2020
…ed#45496)

* feat: add setSystemTime and getRealSystemTime to jest types

* test: jest setSystemTime and getRealSystemTime

* feat: remove Date from setSystemTime types while not yet officially supported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical package Owner Approved A listed owner of this package signed off on the pull request. Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants