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

Simplify matcher setup and fix bug related to negated matchers #27

Merged
merged 3 commits into from
May 30, 2023

Conversation

jo-sm
Copy link
Contributor

@jo-sm jo-sm commented May 12, 2023

This PR simplifies the way matchers are defined by creating the macro defmatcher, which creates a function with metadata that can be analyzed at compile time to know if the defined function is a matcher. This has benefits both related to simplicity, as all of the expect related code now lives in cljest.core/is and related internal macros, as well as allowing external users to define their own matchers without needing to commit them to the main repo.

Additionally, support for aliases is added to that Jest will correctly use them when calling clojure -Spath to get the class path.

TODOs

  • Add docs about creating custom matchers
  • Add spec for internal resolved-info map
  • Simplify is macro to not use non-macro code internally (use expect directly)

@jo-sm jo-sm marked this pull request as ready for review May 12, 2023 17:34
@jo-sm jo-sm marked this pull request as draft May 12, 2023 17:34
By moving more of the logic into the compile stage, it's possible to
simplify a lot of the internals related to matchers. Specifically,
instead of setting the dynamic `*inside-is?` and `*is-body-negated?`
bindings inside of `cljest.core/is` and reading these values inside
of `cljest.matchers/make-matcher` and `make-optional/matcher`, which
created an implicit contract between the two, we have a `defmatcher`
macro which generates a function that has explicit `:jest-matcher`
metadata which is analyzed at compile time. This lets all of the
`expect` code exist within `is`, making it easier to reason about
how things work at the expense of more things moving to compile time.

Additionally, the previous implementation did not correctly support
negated matchers, and was only discovered after some manual testing
and exploration. This change fixes this bug.

- Support alises when running cljest

Previously, if you had an alias such as `test` which you were starting
`clj` with, while the code would correctly compile, but Jest wouldn't
find any extra paths that alias added.
@jo-sm jo-sm force-pushed the simplified-matchers branch from a7a96f3 to 325bd84 Compare May 26, 2023 12:04
@jo-sm jo-sm marked this pull request as ready for review May 26, 2023 12:04
jo-sm added 2 commits May 26, 2023 14:07
- Use `cljest__is` matcher directly rather than `cljest.core/is-matcher` in `is` macro
- Update changelog (including previous missing `setup-mocks` fix)
@jo-sm jo-sm force-pushed the simplified-matchers branch from 325bd84 to e668d83 Compare May 26, 2023 12:07
@jo-sm jo-sm merged commit 6093b64 into master May 30, 2023
@jo-sm jo-sm deleted the simplified-matchers branch May 30, 2023 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants