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

✨ Attach the original Error as a cause of thrown one #2965

Merged
merged 6 commits into from
Sep 20, 2022
Merged

Conversation

dubzzz
Copy link
Owner

@dubzzz dubzzz commented May 12, 2022

Category:

  • ✨ Introduce new features
  • 📝 Add or update documentation
  • ✅ Add or update tests
  • 🐛 Fix a bug
  • 🏷️ Add or update types
  • ⚡️ Improve performance
  • Other(s): ...

Potential impacts:

  • Generated values
  • Shrink values
  • Performance
  • Typings
  • Other(s): ...

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 12, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6e21c90:

Sandbox Source
Vanilla Configuration
@fast-check/examples Configuration

@codecov
Copy link

codecov bot commented May 12, 2022

Codecov Report

Merging #2965 (5307918) into main (0ab23c5) will decrease coverage by 0.09%.
The diff coverage is 66.66%.

❗ Current head 5307918 differs from pull request most recent head 6e21c90. Consider uploading reports for the commit 6e21c90 to get more accurate results

@@            Coverage Diff             @@
##             main    #2965      +/-   ##
==========================================
- Coverage   95.58%   95.48%   -0.10%     
==========================================
  Files         212      212              
  Lines        5815     5828      +13     
  Branches     1072     1075       +3     
==========================================
+ Hits         5558     5565       +7     
- Misses        257      263       +6     
Flag Coverage Δ
unit-tests 95.48% <66.66%> (-0.10%) ⬇️
unit-tests-14.x-Linux 95.45% <66.66%> (-0.10%) ⬇️
unit-tests-16.x-Linux 95.48% <66.66%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...check/src/check/runner/configuration/Parameters.ts 0.00% <ø> (ø)
...heck/src/check/runner/utils/RunDetailsFormatter.ts 63.56% <33.33%> (-0.85%) ⬇️
.../check/runner/configuration/QualifiedParameters.ts 97.56% <100.00%> (+0.06%) ⬆️
packages/fast-check/src/arbitrary/unicode.ts 94.44% <0.00%> (-5.56%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dubzzz

This comment was marked as outdated.

@dubzzz
Copy link
Owner Author

dubzzz commented Sep 1, 2022

Waiting the end of my work on 'better handling of poisoning' before reliving this PR. In order not to break the existing users, the error with cause will be provided as an opt-in option. Helpers around test runners (not any for vitest yet but will come) will probably enforce it according to how well the test runner handle them.

@jasikpark
Copy link
Contributor

jasikpark commented Sep 12, 2022

This will be nice so I can stop using:

fc.context(), (input, ctx) => {  ctx.log(`input: ${input}, output: ${functionUnderTest(input)}`); }

in my property tests

@dubzzz
Copy link
Owner Author

dubzzz commented Sep 12, 2022

Interested to now why you need this pattern? By the way, you can override the default error reporter if needed

@jasikpark
Copy link
Contributor

I have a pretty similar goal to #660 i think - I want to see the expected vs actual values on jest expect errors in vitest

@dubzzz
Copy link
Owner Author

dubzzz commented Sep 19, 2022

ava 4.3.3 🔴

image

jasmine 4.4.0 🔴

image

jest 28.1.2 🔴

image

mocha 10.0.0 🔴

image

node 16.14.0 🟢

image

vitest 0.17.0 🟢

image

@dubzzz
Copy link
Owner Author

dubzzz commented Sep 20, 2022

please deploy

@github-actions
Copy link
Contributor

Give a try to 5307918 with:

yarn add https://632a07884ff4a50bae9af377--dazzling-goodall-4f0e38.netlify.app/fast-check.tgz
npm i https://632a07884ff4a50bae9af377--dazzling-goodall-4f0e38.netlify.app/fast-check.tgz

Or have a look to the generated documentation.

@dubzzz
Copy link
Owner Author

dubzzz commented Sep 20, 2022

With the new flag against vitest:

image

image

Code snippet
import { test, expect } from "vitest";
import fc from "fast-check";

fc.configureGlobal({ errorWithCause: true });

test("error cause", () => {
  fc.assert(
    fc.property(fc.integer(), (n) => {
      return n <= 10;
    })
  );
});

test("error cause (expect)", () => {
  fc.assert(
    fc.property(fc.integer(), (n) => {
      expect(n).toBeLessThanOrEqual(10);
    })
  );
});

With the flag against node:

image
image

Code snippet 1
const fc = require("fast-check");

fc.configureGlobal({ errorWithCause: true });

fc.assert(
  fc.property(fc.integer(), (n) => {
    return n <= 10;
  })
);
Code snippet 2
const assert = require("assert");
const fc = require("fast-check");

fc.configureGlobal({ errorWithCause: true });

fc.assert(
  fc.property(fc.integer(), (n) => {
    assert(n <= 10);
  })
);

@dubzzz dubzzz merged commit b69143d into main Sep 20, 2022
@dubzzz dubzzz deleted the better-errors branch September 20, 2022 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants