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

Vitest prop testing #3703

Open
wants to merge 15 commits into
base: next-minor
Choose a base branch
from

Conversation

jessekelly881
Copy link
Contributor

@jessekelly881 jessekelly881 commented Sep 30, 2024

Adds property testing.

https://www.npmjs.com/package/@fast-check/vitest

import { Schema } from "effect"
import { it } from "@effect/vitest"

const realNumber = Schema.Finite.pipe(Schema.nonNaN())

it.prop("symmetry", [realNumber, realNumber], ([a, b]) => a + b === b + a)

it.effect.prop("symmetry", [realNumber, realNumber], ([a, b]) =>
  Effect.gen(function* () {
    yield* Effect.void
    return a + b === b + a
  })
)

it.scoped.prop(
  "should detect the substring",
  { a: Schema.String, b: Schema.String, c: Schema.String },
  ({ a, b, c }) =>
    Effect.gen(function* () {
      yield* Effect.scope
      return (a + b + c).includes(b)
    })
)

Copy link

changeset-bot bot commented Sep 30, 2024

🦋 Changeset detected

Latest commit: 72e0fc2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/vitest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jessekelly881 jessekelly881 marked this pull request as ready for review September 30, 2024 08:27
@mikearnaldi
Copy link
Member

why not the following?

it.effect.prop("should detect the substring", { a: Schema.String, b: Schema.String, c: Schema.String }, ({ a, b, c }) =>
    Effect.gen(function*() {
      return (a + b + c).includes(b)
    })
)

@jessekelly881
Copy link
Contributor Author

jessekelly881 commented Oct 1, 2024

Yeah, I actually like that more. Updated.

@jessekelly881
Copy link
Contributor Author

@mikearnaldi Mind having another look when you get the chance?

@mikearnaldi
Copy link
Member

Looks good to me! I'll let @tim-smart and @gcanti comment / review

@tim-smart
Copy link
Member

Whoops wrong PR. I'll review this one shortly.

@tim-smart
Copy link
Member

Hmm we can't depend on /schema as it isn't part of the core package at this stage.

You can add it to a separate module however.

@jessekelly881
Copy link
Contributor Author

Not even as a devDependency(for every other package besides /vitest)?

@tim-smart
Copy link
Member

tim-smart commented Oct 9, 2024

Not even as a devDependency(for every other package besides /vitest)?

It just can't be used in the /vitest/index.ts module, as /effect dogfoods it.

So you can add it as /vitest/PropertyTesting, but will lose out on the chainable api.

Or maybe it can extend the /index.ts apis in some way.

@jessekelly881
Copy link
Contributor Author

jessekelly881 commented Oct 10, 2024

I moved it to /Schema and went with prop.effect, prop.scoped, etc. for now. Hopefully that should do it.

@mikearnaldi
Copy link
Member

Then I would say let's hold off until we merge schema

@jessekelly881
Copy link
Contributor Author

jessekelly881 commented Oct 10, 2024

Hmm. Well this is awkward.. jaja. I've updated it to hopefully fix the issue. Still think we should wait? What's the timeline for merging schema? If it's w/ 4.0 maybe it's worth merging this version and then updating the api once schema is merged?

@mikearnaldi
Copy link
Member

Hmm. Well this is awkward.. jaja. I've updated it to hopefully fix the issue. Still think we should wait? What's the timeline for merging schema? If it's w/ 4.0 maybe it's worth merging this version and then updating the api once schema is merged?

Merging schema is not a breaking change for effect so most likely a matter or weeks

@jessekelly881
Copy link
Contributor Author

Gotcha. Makes sense to revert to the original version and wait then. I'll ping this again when Schema gets merged.

@jessekelly881
Copy link
Contributor Author

@tim-smart @mikearnaldi I rebased this against next-minor w/ schema merged into effect. Mind having another look?

@github-actions github-actions bot force-pushed the next-minor branch 2 times, most recently from ae8526c to 8410a20 Compare October 17, 2024 17:22
/**
* @since 1.0.0
*/
export type SchemaObj<A, E, R> = Array<Schema.Schema<A, E, R>> | { [K in string]: Schema.Schema<A, E, R> }
Copy link
Member

Choose a reason for hiding this comment

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

Don't think you need any generics here. Also I don't think you can assign Schema.Never to this.

Copy link
Contributor Author

@jessekelly881 jessekelly881 Oct 19, 2024

Choose a reason for hiding this comment

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

Arbitrary doesn't support Schema.Never so I think not being able to assign Schema.Never to it is fine. But, yeah, this can be Schema.Any w/o the generics

case "NeverKeyword":
return () => {
throw new Error(errors_.getArbitraryUnsupportedErrorMessage(path, ast))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Discussion Ongoing
Development

Successfully merging this pull request may close these issues.

5 participants