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

fix(jest-environment-puppeteer): Class & Exports #37647

Merged
merged 3 commits into from Aug 19, 2019
Merged

fix(jest-environment-puppeteer): Class & Exports #37647

merged 3 commits into from Aug 19, 2019

Conversation

favna
Copy link
Contributor

@favna favna commented Aug 15, 2019

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

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:

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)
@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick performance metrics against master and your PR. This is still an experiment, so don’t panic if I say something crazy! I’m still learning how to interpret these metrics.

Let’s review the numbers, shall we?

master #37647 diff
Batch compilation
Memory usage (MiB) 99.3 111.1 +11.8%
Type count 17326 20628 +19.1%
Assignability cache size 36856 37528 +1.8%
Subtype cache size 0 0
Identity cache size 4 4 0.0%
Language service
Samples taken 17 52 +205.9%
Identifiers in tests 17 52 +205.9%
getCompletionsAtPosition
    Mean duration (ms) 684.3 700.3 +2.3%
    Median duration (ms) 684.3 697.3 +1.9%
    Mean CV 7.9% 10.4% +32.0%
    Worst duration (ms) 753.0 809.8 +7.5%
    Worst identifier browser Config
getQuickInfoAtPosition
    Mean duration (ms) 584.7 636.9 +8.9%
    Median duration (ms) 584.3 628.8 +7.6%
    Mean CV 6.3% 10.3% +64.3%
    Worst duration (ms) 619.4 758.8 +22.5% 🔸
    Worst identifier context BrowserContext

Looks like there were a couple significant differences—take a look at worst-case duration for getting quick info at a position to make sure everything looks ok.


If you have any questions or comments about me, you can ping @andrewbranch. Have a nice day!

@typescript-bot
Copy link
Contributor

typescript-bot commented Aug 15, 2019

@favna Thank you for submitting this PR!

🔔 @JoshuaKGoldberg @ifiokjr - 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.

// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
// TypeScript Version: 3.4
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the version change? This would be a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this would be a breaking change

Hardly, if this extremely small set of breaking changes made by TS v3.0 is an issue then you should update your code base rather than resist upgrading.

But to answer your question, before I bumped it the tests failed, something to do with the imports the new tests and typings have to use.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not always reasonable to ask consumers to upgrade TypeScript versions for their projects especially if it's not necessary. In the case of this PR I think the esModuleInterop, which is only used for the tests, is causing the requirement for a higher version. Please remove this flag and use import JestEnvironmentPuppeteer = require('jest-environment-puppeteer') instead.

Copy link
Contributor Author

@favna favna Aug 16, 2019

Choose a reason for hiding this comment

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

@PranavSenthilnathan I tried bumping it back down to 2.8 and removing esModuleInterop and I got the errors again, it comes from the jest-mock library. Here is the error it throws:

1> jest-environment-puppeteer failing:
1> Error: Errors in typescript@next for external dependencies:
1> node_modules/@jest/environment/build/index.d.ts(11,8): error TS1259: Module '"E:/dev/DefinitelyTyped/types/jest-environment-puppeteer/node_modules/jest-mock/build/index"' can only be default-imported using the 'esModuleInterop' flag
1> node_modules/@jest/source-map/build/getCallsite.d.ts(8,100): error TS2503: Cannot find namespace 'callsites'.
1>
1>     at E:\dev\DefinitelyTyped\node_modules\dtslint\bin\index.js:190:19
1>     at Generator.next (<anonymous>)
1>     at fulfilled (E:\dev\DefinitelyTyped\node_modules\dtslint\bin\index.js:5:58)

Going back to either 3.0 or 3.4 without esModuleInterop still has it fail, so instead I tried version 2.8 with esModuleInterop and I ended up with another error, once again due to external dependencies, this is a long one so I dumped it on gist: https://gist.github.com/Favna/fb37f696dcc390fa593cedcf8050751b.

Next thing I tried was TypeScript v3.0 with esModuleInterop which again threw an error:

=== ERRORS ===
Error in jest-environment-puppeteer
Error: Errors in typescript@3.0 for external dependencies:
node_modules/jest-mock/build/index.d.ts(125,162): error TS2304: Cannot find name 'Parameters'.

    at E:\dev\DefinitelyTyped\node_modules\dtslint\bin\index.js:190:19
    at Generator.next (<anonymous>)
    at fulfilled (E:\dev\DefinitelyTyped\node_modules\dtslint\bin\index.js:5:58)
Error: The following packages had errors: jest-environment-puppeteer
    at doRunTests (E:\dev\DefinitelyTyped\node_modules\types-publisher\src\tester\test-runner.ts:235:11)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)
error Command failed with exit code 1.

Ultimately I ended up going for TypeScript version 3.4 in 53b225a after all and with esModuleInterop, but I maintained the requested export = and import .. = require('...'). I also added a few extra ExpectType tests because the latter means you cannot directly import the interfaces and I'm told I can't have other export statements when usin export =.

Copy link
Contributor

Choose a reason for hiding this comment

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

Its unfortunate that the packages you are depending on are using features from typescript 3+.

@typescript-bot typescript-bot moved this from Waiting for Reviewers to Check and Merge in Pull Request Status Board Aug 15, 2019
@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Merge:Express and removed Awaiting reviewer feedback labels Aug 15, 2019
@typescript-bot
Copy link
Contributor

A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped!

types/jest-environment-puppeteer/index.d.ts Outdated Show resolved Hide resolved
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
// TypeScript Version: 3.4
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not always reasonable to ask consumers to upgrade TypeScript versions for their projects especially if it's not necessary. In the case of this PR I think the esModuleInterop, which is only used for the tests, is causing the requirement for a higher version. Please remove this flag and use import JestEnvironmentPuppeteer = require('jest-environment-puppeteer') instead.

@typescript-bot typescript-bot moved this from Check and Merge to Needs Author Attention in Pull Request Status Board Aug 16, 2019
@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Merge:Express labels Aug 16, 2019
@typescript-bot
Copy link
Contributor

@favna 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. Thank you!

Co-Authored-By: Pranav Senthilnathan <pranav.senthilnathan@live.com>
@typescript-bot
Copy link
Contributor

Updated numbers for you here from 5ac3547:

Comparison details 📊
master #37647 diff
Batch compilation
Memory usage (MiB) 99.8 110.0 +10.2%
Type count 17326 20660 +19.2%
Assignability cache size 36856 37531 +1.8%
Subtype cache size 0 0
Identity cache size 4 4 0.0%
Language service
Samples taken 17 52 +205.9%
Identifiers in tests 17 52 +205.9%
getCompletionsAtPosition
    Mean duration (ms) 675.8 684.6 +1.3%
    Median duration (ms) 681.8 679.0 -0.4%
    Mean CV 8.3% 9.6% +16.9%
    Worst duration (ms) 775.1 766.7 -1.1%
    Worst identifier browser Page
getQuickInfoAtPosition
    Mean duration (ms) 599.9 626.6 +4.5%
    Median duration (ms) 602.8 611.9 +1.5%
    Mean CV 8.0% 11.2% +39.3%
    Worst duration (ms) 641.0 785.9 +22.6% 🔸
    Worst identifier Browser Config

Looks like there were a couple significant differences—take a look at worst-case duration for getting quick info at a position to make sure everything looks ok.

@typescript-bot
Copy link
Contributor

Updated numbers for you here from 5ac3547:

Comparison details 📊
master #37647 diff
Batch compilation
Memory usage (MiB) 106.1 110.9 +4.6%
Type count 17326 20660 +19.2%
Assignability cache size 36856 37531 +1.8%
Subtype cache size 0 0
Identity cache size 4 4 0.0%
Language service
Samples taken 17 52 +205.9%
Identifiers in tests 17 52 +205.9%
getCompletionsAtPosition
    Mean duration (ms) 684.2 684.0 0.0%
    Median duration (ms) 689.5 675.5 -2.0%
    Mean CV 9.3% 10.2% +9.9%
    Worst duration (ms) 745.9 788.3 +5.7%
    Worst identifier jestPuppeteer BrowserContext
getQuickInfoAtPosition
    Mean duration (ms) 630.2 628.1 -0.3%
    Median duration (ms) 629.6 621.1 -1.4%
    Mean CV 10.8% 10.6% -1.8%
    Worst duration (ms) 680.9 722.6 +6.1%
    Worst identifier browser ProjectConfig

It looks like nothing changed too much. I’m pretty lenient since I’m still an experiment, so take a look anyways and make sure nothing looks out of place.

@typescript-bot
Copy link
Contributor

Updated numbers for you here from 9bb675f:

Comparison details 📊
master #37647 diff
Batch compilation
Memory usage (MiB) 104.7 111.0 +6.0%
Type count 17326 20659 +19.2%
Assignability cache size 36856 37531 +1.8%
Subtype cache size 0 0
Identity cache size 4 4 0.0%
Language service
Samples taken 17 58 +241.2%
Identifiers in tests 17 58 +241.2%
getCompletionsAtPosition
    Mean duration (ms) 696.9 708.7 +1.7%
    Median duration (ms) 706.9 717.8 +1.5%
    Mean CV 8.0% 9.6% +20.1%
    Worst duration (ms) 797.5 798.2 +0.1%
    Worst identifier browser waitFor
getQuickInfoAtPosition
    Mean duration (ms) 633.6 641.8 +1.3%
    Median duration (ms) 633.3 632.4 -0.1%
    Mean CV 6.8% 10.4% +54.0%
    Worst duration (ms) 686.1 764.7 +11.5%
    Worst identifier Browser global

It looks like nothing changed too much. I’m pretty lenient since I’m still an experiment, so take a look anyways and make sure nothing looks out of place.

@typescript-bot
Copy link
Contributor

🔔 @PranavSenthilnathan - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate?

@sheetalkamat sheetalkamat merged commit bbe8520 into DefinitelyTyped:master Aug 19, 2019
Pull Request Status Board automation moved this from Needs Author Attention to Done Aug 19, 2019
@typescript-bot
Copy link
Contributor

I just published @types/jest-environment-puppeteer@4.3.1 to npm.

@favna favna deleted the upgrades/jest-environment-puppeteer branch August 20, 2019 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Owner Approved A listed owner of this package signed off on the pull request. Revision needed This PR needs code changes before it can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants