Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(jest-snapshot): Fix a potential bug when using babel and improve performance#14036

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SimenB merged 3 commits intojestjs:mainfromliuxingbaoyu:fix-retainLines
Mar 31, 2023

Conversation

liuxingbaoyu
Copy link
Contributor

@liuxingbaoyuliuxingbaoyu commentedMar 29, 2023
edited
Loading

Summary

While I was fixing a babel issue, I discovered that jest was expecting buggy behavior.

retainLines will try to keep the original code and the new code on the same line.

expect(a).toMatchInlineSnapshot(`123456`)

When we replace123\n456 with the single-line content123456.
The previous babel would ignore the position of) and generate this.

expect(a).toMatchInlineSnapshot(`123456`)

And new babel will generate

expect(a).toMatchInlineSnapshot(`123456`)

jest was relying on the previous behavior, the PR fixes this.
Ref:babel/babel#15515

In addition, I also found that@babel/traverse is being used in the current code to traverse the AST generated by other than@babel/parser, which is a bit unexpected.
But since it's been that long, it seems like it's good enough for this simple usage.
I just replaced it withtraverse from@babel/types, which has very simple functionality and is much faster.(Maybe 10x)

Test plan

CI green

) {
throw new Error('Jest: no snapshot insert location found');
}

// A hack to prevent unexpected line breaks in the generated code
node.loc!.end.line = node.loc!.start.line;
Copy link
ContributorAuthor

@liuxingbaoyuliuxingbaoyuMar 29, 2023
edited
Loading

Choose a reason for hiding this comment

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

Actually only this line is the fix, the rest are refactorings.😃

Copy link
Member

@SimenBSimenB left a comment

Choose a reason for hiding this comment

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

Awesome, thanks! 👍

@SimenBSimenB merged commit257f250 intojestjs:mainMar 31, 2023
@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 usingStackOverflow or ourdiscord channel for questions.

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsMay 1, 2023
@SimenB
Copy link
Member

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@SimenBSimenBSimenB approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@liuxingbaoyu@SimenB@facebook-github-bot

[8]ページ先頭

©2009-2025 Movatter.jp