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(expect-util): fix comparison of DataView #14408

Merged
merged 6 commits into from
Sep 20, 2023

Conversation

Dunqing
Copy link
Contributor

@Dunqing Dunqing commented Aug 14, 2023

Summary

Relate PR: vitest-dev/vitest#3703

Test plan

Added

@netlify
Copy link

netlify bot commented Aug 14, 2023

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a280fd2
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/650ab94d130ce80008676bd8
😎 Deploy Preview https://deploy-preview-14408--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 393 to 394
let dataViewA = a as DataView;
let dataViewB = b as DataView;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm.. I’m not happy to see this cast. Right now it works with the following logic, but if the logic will change TS will fail to catch any errors. Would be useful to rethink this part.

Comment on lines 393 to 402
if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer)) {
return undefined;
}
let dataViewA = a as DataView;
let dataViewB = b as DataView;

const dataViewA = new DataView(a);
const dataViewB = new DataView(b);
if (!(a instanceof DataView && b instanceof DataView)) {
if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer))
return undefined;

dataViewA = new DataView(a);
dataViewB = new DataView(b);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps simply like this (just a quick idea):

  let dataViewA: DataView;
  let dataViewB: DataView;

  if (a instanceof DataView && b instanceof DataView) {
    dataViewA = a;
    dataViewB = b;
  } else if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) {
    dataViewA = new DataView(a);
    dataViewB = new DataView(b);
  } else {
    return undefined;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I've reimplemented it. What do you think?

Comment on lines +393 to +394
let dataViewA = a;
let dataViewB = b;
Copy link
Contributor

Choose a reason for hiding this comment

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

From semantic point of view it feels wrong to name a variable dataView at the moment it is still not clear if that is a DataView instance.

Also the shape of the logic is very close to: #14408 (comment). Did I miss something in that proposal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic of your implementation is also correct, except that I wanted to reduce the logical judgments

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I follow.

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.

thanks!

@SimenB SimenB changed the title fix(expect-util): DataView comparison does not work fix(expect-util): fix comparison of DataView Sep 20, 2023
@SimenB SimenB enabled auto-merge (squash) September 20, 2023 07:21
@SimenB SimenB merged commit 4f35f1f into jestjs:main Sep 20, 2023
59 of 60 checks passed
@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 Oct 21, 2023
@SimenB
Copy link
Member

SimenB commented Oct 30, 2023

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants