Skip to content

fix(expect): fix custom equality test case #4286

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

Merged
merged 12 commits into from
Mar 5, 2024

Conversation

eryue0220
Copy link
Contributor

This pr is to support iterable object test check and fix expect custom equality test case.


Background: #4255 (comment)

@eryue0220 eryue0220 requested a review from kt3k as a code owner February 8, 2024 01:51
@github-actions github-actions bot added the expect label Feb 8, 2024
@kt3k
Copy link
Member

kt3k commented Feb 10, 2024

@eryue0220
Thanks for the PR, but this seems including too much code for fixing that specific test case. Can you try minimize the code introduced?

@eryue0220
Copy link
Contributor Author

Thanks for the PR, but this seems including too much code for fixing that specific test case. Can you try minimize the code introduced?

Ok, I'll try for this.

@eryue0220 eryue0220 marked this pull request as draft February 25, 2024 03:59
…0/deno_std into fix/expect-custom-equality-case

* 'fix/expect-custom-equality-case' of github.com:eryue0220/deno_std: (63 commits)
  docs: link to `assertThrows()` and `assertRejects()` (denoland#4395)
  chore(log): sync `level` and `levelName` in BaseHandler (denoland#4393)
  docs: ignore bad snippet examples (denoland#4388)
  chore(media_types): format test names (denoland#4380)
  docs: clarify underscore guidance in README (denoland#4385)
  feat(collections): add `pick` and `omit` (denoland#4218)
  chore(msgpack): format test names (denoland#4381)
  refactor(encoding): prepare for `noUncheckedIndexedAccess` (denoland#4275)
  refactor(streams): prepare for `noUncheckedIndexedAccess` (denoland#4377)
  chore: fix .editorconfig syntax (denoland#4376)
  chore(semver): remove legacy `Range.ranges` object definition (denoland#4374)
  chore(semver): move breaking versions (denoland#4372)
  refactor(semver): rename `comparatorFormat()` to `formatComparator()` (denoland#4373)
  test(semver): add test for parse_range (denoland#4345)
  chore: use 'release' event for triggering jsr publish (denoland#4370)
  chore(http): fix spawned tests after migration script (denoland#4368)
  chore(crypto): move test scripts to own files (denoland#4367)
  0.217.0 (denoland#4369)
  build: update _ to - in workspace converter script (denoland#4357)
  chore(media_types): move `extensions` utility (denoland#4358)
  ...
@eryue0220
Copy link
Contributor Author

@kt3k

Sorry for the late response,

I've check the api and its usage again, and I restructure the codebase. But the codebase is not just for the specific case, it's also a public api in jest, which is exported from jest/expect-utils.

And other expect apis, such as arrayContaining and stringContaining will depend on this method.

@eryue0220 eryue0220 marked this pull request as ready for review February 28, 2024 04:12
Comment on lines +23 to +27
const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
const IS_LIST_SENTINEL = "@@__IMMUTABLE_LIST__@@";
const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@";
Copy link
Member

Choose a reason for hiding this comment

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

Checks for these sentinel keys/values don't make much sense to me because nothing seems setting these keys.

I guess we can just remove these constants and checks related to these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For internal codebase, it is yes. But as for the apps which uses immutable.js, they will rely on these keys/value to test it, such as the following:

import { OrderedMap } from "npm:[email protected]";
import { expect, iterableEquality } from "https://deno.land/std@$STD_VERSION/expect/mod.ts";

Deno.test("immutable test", () => {
    const a = OrderedMap().set("saving", true);
    const b = OrderedMap().merge({saving: true});
    expect(iterableEquality(a, b)).toBe(true);
});

Copy link
Member

Choose a reason for hiding this comment

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

Does jest support such cases natively?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the iterableEquality is exported from expect-utils, and the test codebase is here

expect/mod.ts Outdated
@@ -85,3 +85,4 @@
*/
export { expect } from "./expect.ts";
export { fn } from "./fn.ts";
export { iterableEquality } from "./iterable_equality.ts";
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's good idea to expose iterableEquality from here.

iterableEquality is exported from @jest/expect-utils, but the README of @jest/expect-utils seems discouraging importing things directly from it. ref. https://www.npmjs.com/package/@jest/expect-utils

I'll make iterableEquality private API in std/expect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree in some degree, because it doesn't indeed belong to expect module. But if it's private, how to use in public?

Copy link
Member

Choose a reason for hiding this comment

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

I suggest we shouldn't provide direct import of iterableEquality. The purpose of std/expect is compatiblity to jest's expect, but jest doesn't document iterableEquality in their docs. Supporting iterableEquality is out of scope here in my view.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution!

@kt3k
Copy link
Member

kt3k commented Mar 5, 2024

I'm landing this PR at this point.

Let's discuss in another issue if you have further questions about the scope of std/expect

@kt3k kt3k merged commit cec0c68 into denoland:main Mar 5, 2024
@eryue0220 eryue0220 deleted the fix/expect-custom-equality-case branch March 5, 2024 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants