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

refactor(@jest-reporters): move helpers from utils.ts into separate files #12782

Merged
merged 2 commits into from
Apr 30, 2022
Merged

refactor(@jest-reporters): move helpers from utils.ts into separate files #12782

merged 2 commits into from
Apr 30, 2022

Conversation

mrazauskas
Copy link
Contributor

Fixes #12772
Closes #12773

Summary

Several @jest-reporters helper utils currently live in separate files (like getResultHeader or getSnapshotStatus), some are exported from utils.ts. That’s all fine, only tsc gets somewhat confused and emits index.d.ts like this:

export declare const utils: {
    formatTestPath: (config: import("@jest/types/build/Config").GlobalConfig | import("@jest/types/build/Config").ProjectConfig, testPath: string) => string;
    getResultHeader: typeof getResultHeader;
    getSnapshotStatus: typeof getSnapshotStatus;
    printDisplayName: (config: import("@jest/types/build/Config").ProjectConfig) => string;
    // ...

Note the difference between getResultHeader (lives in separate file) and formatTestPath (imported from utils.ts). Reaching into build is one of the reasons causing the issue reported in #12772 and possibly could break something else in the future.

I found two possible solutions:

The latter one seemed somewhat nicer. If it doesn’t create too many files?

Test plan

Type tests for utils are added. Some of the tests are failing on main, but are passing on this branch.

@@ -33,11 +33,13 @@
"jest-worker": "^28.0.2",
"slash": "^3.0.0",
"string-length": "^4.0.1",
"strip-ansi": "^6.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SimenB
Copy link
Member

SimenB commented Apr 30, 2022

Yeah, I prefer this 👍 I do think it's a bug in the bundler, tho. Or is it tsc that emits the deep imports?

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

nice 👍

(changelog?)

@mrazauskas
Copy link
Contributor Author

Or is it tsc that emits the deep imports?

tsc is emitting the deep imports. Looks like this is causes by star imports inside @jest/types. Probably tsc cannot digest them, because exporting namespaces explicitly eliminates the problem (proved in #12773 as well). That helps tsc, but bundler still does not work correctly. It needs the change from this PR.

@mrazauskas
Copy link
Contributor Author

By the way, I was also checking if other .d.ts files do not include some deep imports. Can’t find any. Seems like this was only an issue with @jest-reporters.

@SimenB
Copy link
Member

SimenB commented Apr 30, 2022

By the way, I was also checking if other .d.ts files do not include some deep imports. Can’t find any. Seems like this was only an issue with @jest-reporters.

Awesome! Could we maybe add a check that there is no /build in the d.ts files? Kinda like we do in https://github.com/facebook/jest/blob/c8c32d3704469557ecfc3d4a9e81002f11e2075d/scripts/buildTs.mjs#L171-L173

@mrazauskas
Copy link
Contributor Author

Sure. I look a look at validation logic. Might be better to run it after bundling, or? Perhaps I will open a separate PR and we can figure out there?

@SimenB
Copy link
Member

SimenB commented Apr 30, 2022

Sure. I look a look at validation logic. Might be better to run it after bundling, or? Perhaps I will open a separate PR and we can figure out there?

Yep and yep 👍

@SimenB SimenB merged commit ded5bb4 into jestjs:main Apr 30, 2022
@mrazauskas mrazauskas deleted the refactor-reporters-utils branch April 30, 2022 09:47
F3n67u pushed a commit to F3n67u/jest that referenced this pull request May 2, 2022
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: @jest/reporters@28.0.3 fails TypeScript type checking
3 participants