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

Add fakeTimersLolex to implement JestEnvironment interface #44033

Closed
wants to merge 3 commits into from
Closed

Add fakeTimersLolex to implement JestEnvironment interface #44033

wants to merge 3 commits into from

Conversation

douglascayers
Copy link
Contributor

Opening pull request per this conversation.

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).

Select one of these and delete the others:

If changing an existing definition:

Since [jest 25.1.x](https://github.com/facebook/jest/releases/tag/v25.1.0), pull request [jest#8925](jestjs/jest#8925) added [fakeTimersLolex](jestjs/jest@0935f7c#diff-e8e69a5b9fa4b43b2e24abe1933d2855R44) property to `JestEnvironment` interface.
Since [jest 25.1.x](https://github.com/facebook/jest/releases/tag/v25.1.0), pull request [jest#8925](jestjs/jest#8925) added [fakeTimersLolex](jestjs/jest@0935f7c#diff-e8e69a5b9fa4b43b2e24abe1933d2855R44) property to `JestEnvironment` interface.
douglascayers referenced this pull request Apr 19, 2020
* fix(jest-environment-puppeteer): Class & Exports

This makes the typings actually compatible to create your own test
environment and not just as part of the bigger jest-puppeteer package.
How to do this is pretty much what the test covers. One of the reasons
to do this is to write a handler where Puppeteer takes screenshots after
each failed test, as discussed [here](argos-ci/jest-puppeteer#131)

* Change to `export =` syntax

Co-Authored-By: Pranav Senthilnathan <pranav.senthilnathan@live.com>

* Fix the last stuff requested
@douglascayers
Copy link
Contributor Author

douglascayers commented Apr 19, 2020

@typescript-bot I've reviewed the build errors, but I don't know how to resolve them.

Azure Pipelines build result:

types/jest/index.d.ts(486,51): error TS2307: Cannot find module 'jest-diff'.
types/jest/index.d.ts(540,44): error TS2307: Cannot find module 'pretty-format'.

Error: Compilation had errors
    at process.<anonymous> (/home/vsts/work/1/s/node_modules/@definitelytyped/perf/dist/measure/measureBatchCompilationWorker.js:24:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Error: Parsing failed.
    at fail (/home/vsts/work/1/s/node_modules/@definitelytyped/utils/dist/process.js:76:20)
    at ChildProcess.<anonymous> (/home/vsts/work/1/s/node_modules/@definitelytyped/utils/dist/process.js:63:21)
    at ChildProcess.emit (events.js:311:20)
    at finish (internal/child_process.js:861:14)
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

Travis CI build result:

Error: Errors in typescript@3.9 for external dependencies:
../jest/index.d.ts(486,51): error TS2307: Cannot find module 'jest-diff' or its corresponding type declarations.
../jest/index.d.ts(540,44): error TS2307: Cannot find module 'pretty-format' or its corresponding type declarations.
    at /home/travis/build/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/index.js:195:19
    at Generator.next (<anonymous>)
    at fulfilled (/home/travis/build/DefinitelyTyped/DefinitelyTyped/node_modules/dtslint/bin/index.js:6:58)
Error: The following packages had errors: jest-environment-puppeteer
    at doRunTests (/home/travis/build/DefinitelyTyped/DefinitelyTyped/node_modules/types-publisher/bin/tester/test-runner.js:220:11)
    at process._tickCallback (internal/process/next_tick.js:68:7)

@typescript-bot
Copy link
Contributor

typescript-bot commented Apr 19, 2020

@douglascayers Thank you for submitting this PR!

🔔 @JoshuaKGoldberg @ifiokjr @favna - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot
Copy link
Contributor

typescript-bot commented Apr 19, 2020

@douglascayers The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@douglascayers
Copy link
Contributor Author

douglascayers commented Apr 20, 2020

The compile errors are in a separate package, jest, and not related to my changes (as far as I can tell).

If you open https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jest/index.d.ts locally, you should see two compile errors:

  1. line 486 at import("jest-diff").DiffOptions

  2. line 540 at import('pretty-format').Plugin

I've come across this stackoverflow question but no answers.

What is the recommended next action considering the issue is due to a package I'm not trying to update??

@typescript-bot
Copy link
Contributor

@douglascayers The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@typescript-bot
Copy link
Contributor

typescript-bot commented Apr 20, 2020

@douglascayers The Travis CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Copy link
Contributor

@favna favna left a comment

Choose a reason for hiding this comment

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

LGTM. As for the failing CI, I think that including the dependencies in the package.json list of dependencies will resolve the issue but I'm not 100% sure on that. You can definitely try and run tests locally (npm run test)

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Apr 20, 2020
@douglascayers
Copy link
Contributor Author

douglascayers commented Apr 22, 2020

LGTM. As for the failing CI, I think that including the dependencies in the package.json list of dependencies will resolve the issue but I'm not 100% sure on that. You can definitely try and run tests locally (npm run test)

Unfortunately, updating the package.json file didn't resolve the build issues.

image

image

@douglascayers
Copy link
Contributor Author

douglascayers commented Apr 22, 2020

LGTM. As for the failing CI, I think that including the dependencies in the package.json list of dependencies will resolve the issue but I'm not 100% sure on that. You can definitely try and run tests locally (npm run test)

After my first attempt didn't work, I recalled that jest-diff and pretty-format are sub-packages of the jest monorepo.

So I then tried again by adding the @jest prefix to the package names:

image

This led to an interesting different error after running npm run test:

Error: In package.json: Dependency @jest/jest-diff not in whitelist.
If you are depending on another `@types` package, do *not* add it to a `package.json`. Path mapping should make the import work.
For namespaced dependencies you then have to add a `paths` mapping from `@namespace/library` to `namespace__library` in `tsconfig.json`.
If this is an external library that provides typings,  please make a pull request to types-publisher adding it to `dependenciesWhitelist.txt`.
    at checkPackageJsonDependencies (/Users/doug.ayers/Documents/workspace/DefinitelyTyped/node_modules/types-publisher/bin/lib/definition-parser.js:187:19)

Thinking that jest-diff and pretty-format were part of DefinitelyTyped, I started down the route of adding a paths mapping to tsconfig.json according to the first part of the error message:

If you are depending on another @types package, do not add it to a package.json. Path mapping should make the import work.
For namespaced dependencies you then have to add a paths mapping from @namespace/library to namespace__library in tsconfig.json.

Realizing that those packages are in fact not part of DefinitelyTyped, then they must be external. And the next part of the error message had guidance on external dependencies:

If this is an external library that provides typings, please make a pull request to types-publisher adding it to dependenciesWhitelist.txt.

Taking a peek at dependenciesWhitelist.txt, I saw that some other @jest packages were already listed.

I then verified that jest-diff and pretty-format are indeed written in typescript and provide their own typings -- meaning they're not candidates to bring in to DefinitelyTyped.

In conclusion, I've submitted microsoft/types-publisher#769 to add @jest/jest-diff and @jest/pretty-format to the dependencies whitelist. Once that pull request is merged then I'll retest and push up a new commit to update package.json.

@jablko
Copy link
Contributor

jablko commented Apr 23, 2020

Is this a bug in @jest/environment?

$ npm install @jest/environment
$ > index.ts
$ tsc --types @jest/environment index.ts
node_modules/@jest/environment/build/index.d.ts:8:23 - error TS2688: Cannot find type definition file for 'jest'.

8 /// <reference types="jest" />
                        ~~~~

@jest/environment references types="jest" without a dependency on @types/jest.

I don't know why @jest/environment/build/index.d.ts contains /// <reference types="jest" />: I suspect it's unintended. I haven't found an existing issue for this yet.

@jablko
Copy link
Contributor

jablko commented Apr 23, 2020

(You get the jest-diff and pretty-format errors in the automated tests because in that case all @types packages exist but @types/jest's dependencies aren't installed because @jest/environment references types="jest" without a dependency on @types/jest?)

@jablko
Copy link
Contributor

jablko commented Apr 23, 2020

I opened jestjs/jest#9875 to remove the /// <reference types="jest" /> from @jest/environment. If it's accepted then this PR should start passing the automated tests, because @types/jest-environment-puppeteer won't depend on jest-diff/pretty-format (via @jest/environment and @types/jest).

@douglascayers
Copy link
Contributor Author

Thanks @jablko for the help!

@douglascayers
Copy link
Contributor Author

douglascayers commented Apr 25, 2020

🙌 Good news! @jablko's pull request jestjs/jest#9875 got merged into master branch of facebook/jest.

I imagine once they cut a new release (25.4.1+) then we can retry testing this pull request (I think..)

@favna
Copy link
Contributor

favna commented Apr 25, 2020

@DouglasAntunes Tip: once that's released, other than waiting for staff to retrigger the CI processes, since PRs on this repo are squash and merged anyway you can just trigger it yourself at that time with an empty commit, in CLI: git commit --allow-empty -m "trigger ci" && git push

@typescript-bot
Copy link
Contributor

@douglascayers I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues.

@favna
Copy link
Contributor

favna commented Apr 26, 2020

@sandersn this PR is still pending work elsewhere (please read comments above) and should not be closed yet. Can you prevent @typescript-bot from doing so?

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Apr 27, 2020
@typescript-bot
Copy link
Contributor

@douglascayers To keep things tidy, we have to close PRs that aren't mergeable but don't have activity from their author. No worries, though - please open a new PR if you'd like to continue with this change. Thank you!

Pull Request Status Board automation moved this from Needs Author Attention to Done Apr 27, 2020
@douglascayers
Copy link
Contributor Author

That's unfortunate that @typescript-bot closed this in-progress pull request

@favna
Copy link
Contributor

favna commented Apr 27, 2020

@DouglasAntunes I guess just rebase your branch when Jest is updated and recreate the PR sigh

@favna favna mentioned this pull request Apr 30, 2020
10 tasks
@orta
Copy link
Collaborator

orta commented Apr 30, 2020

oops, sorry about the bot - we added support today to make sure it won't close if maintainers are still chatting DefinitelyTyped/dt-mergebot#33

@favna favna mentioned this pull request May 10, 2020
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Abandoned This PR had no activity for a long time, and is considered abandoned Owner Approved A listed owner of this package signed off on the pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants