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: properly compare TypedArrays of all types #15178

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Jul 11, 2024

Summary

This partially addresses #15176, in that it

  • makes toEqual call drop from 500ms to 100ms (due to us not using the iterator, but iterating "normally" which is 5x faster)
  • if reproduction is changed to toStrictEqual it drops to 3-4 ms, comparable to lodash implementation (without the changes in this PR, there is no difference between toEqual and toStrictEqual)

There might be a case for us to include arrayBufferEquality in the custom matchers we use in toEqual here:

const pass = equals(received, expected, [
...this.customTesters,
iterableEquality,
]);

In that case, toEqual also drops down to 3-4 ms runtime.

Test plan

Tests added

Copy link

netlify bot commented Jul 11, 2024

Deploy Preview for jestjs ready!

Name Link
🔨 Latest commit e52054e
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/668fb68101a6fd00080bc250
😎 Deploy Preview https://deploy-preview-15178--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.

@@ -670,37 +670,55 @@ describe('arrayBufferEquality', () => {
test('returns false when given non-matching buffers', () => {
const a = Uint8Array.from([2, 4]).buffer;
const b = Uint16Array.from([1, 7]).buffer;
expect(arrayBufferEquality(a, b)).not.toBeTruthy();
expect(arrayBufferEquality(a, b)).toBe(false);
Copy link
Member Author

Choose a reason for hiding this comment

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

this was a separate bug - it returned undefined, not false since Uint16Array.from([1, 7]).buffer instanceOf ArrayBuffer for some reason is `false.

@@ -413,9 +415,12 @@ export const arrayBufferEquality = (
let dataViewA = a;
let dataViewB = b;

if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) {
if (isArrayBuffer(a) && isArrayBuffer(b)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@SimenB SimenB enabled auto-merge (squash) July 11, 2024 12:05
@SimenB SimenB merged commit 19b3bcc into jestjs:main Jul 11, 2024
84 checks passed
@SimenB SimenB deleted the compare-all-dataview-properly branch July 11, 2024 12:05
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 Aug 11, 2024
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.

1 participant