Skip to content

Commit

Permalink
✨ Stop repeating the error twice in reports
Browse files Browse the repository at this point in the history
While the change could have been considered as a bug fix, I prefer including it as a fresh new feature to avoid risks of breaking people relying on this bug.

Fixes #3634
  • Loading branch information
dubzzz committed Feb 19, 2023
1 parent 165fe6a commit f24f79f
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class AsyncProperty<Ts> implements IAsyncPropertyWithHooks<Ts> {
if (PreconditionFailure.isFailure(err)) return err;
// exception as PropertyFailure in case of real failure
if (err instanceof Error && err.stack) {
return { error: err, errorMessage: `${err}\n\nStack trace: ${err.stack}` };
return { error: err, errorMessage: err.stack }; // stack includes the message
}
return { error: err, errorMessage: String(err) };
} finally {
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/src/check/property/Property.generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Property<Ts> implements IProperty<Ts>, IPropertyWithHooks<Ts> {
if (PreconditionFailure.isFailure(err)) return err;
// exception as PropertyFailure in case of real failure
if (err instanceof Error && err.stack) {
return { error: err, errorMessage: `${err}\n\nStack trace: ${err.stack}` };
return { error: err, errorMessage: err.stack }; // stack includes the message
}
return { error: err, errorMessage: String(err) };
} finally {
Expand Down
10 changes: 10 additions & 0 deletions packages/fast-check/test/e2e/NoRegression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const testFunc = (value: unknown) => {
const settings = { seed: 42, verbose: 2 };

describe(`NoRegression`, () => {
it('expect', () => {
expect(() =>
fc.assert(
fc.property(fc.nat(), (v) => {
expect(testFunc(v)).toBe(true);
}),
settings
)
).toThrowErrorMatchingSnapshot();
});
it('.filter', () => {
expect(() =>
fc.assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,76 @@ Execution summary:
. . . . . . . . × ["a@a.aa"]"
`;
exports[`NoRegression expect 1`] = `
"Property failed after 2 tests
{ seed: 42, path: "1:2:4:3:1:1:0:1:6:0:2", endOnFailure: true }
Counterexample: [854975880]
Shrunk 10 time(s)
Got error: Error: expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
at /workspaces/fast-check/packages/fast-check/test/e2e/NoRegression.spec.ts:34:31
at Property.predicate (/workspaces/fast-check/packages/fast-check/src/check/property/Property.ts:23:56)
at Property.predicate [as run] (/workspaces/fast-check/packages/fast-check/src/check/property/Property.generic.ts:133:27)
at run (/workspaces/fast-check/packages/fast-check/src/check/runner/Runner.ts:37:26)
at runIt (/workspaces/fast-check/packages/fast-check/src/check/runner/Runner.ts:154:7)
at Object.check (/workspaces/fast-check/packages/fast-check/src/check/runner/Runner.ts:206:15)
at /workspaces/fast-check/packages/fast-check/test/e2e/NoRegression.spec.ts:32:10
at _toThrowErrorMatchingSnapshot (/workspaces/fast-check/node_modules/jest-snapshot/build/index.js:561:7)
at Object.toThrowErrorMatchingSnapshot (/workspaces/fast-check/node_modules/jest-snapshot/build/index.js:461:10)
at __EXTERNAL_MATCHER_TRAP__ (/workspaces/fast-check/node_modules/expect/build/index.js:317:30)
at Object.throwingMatcher [as toThrowErrorMatchingSnapshot] (/workspaces/fast-check/node_modules/expect/build/index.js:318:15)
at Object.<anonymous> (/workspaces/fast-check/packages/fast-check/test/e2e/NoRegression.spec.ts:38:7)
at Promise.then.completed (/workspaces/fast-check/node_modules/jest-circus/build/utils.js:293:28)
at new Promise (<anonymous>)
at callAsyncCircusFn (/workspaces/fast-check/node_modules/jest-circus/build/utils.js:226:10)
at _callCircusTest (/workspaces/fast-check/node_modules/jest-circus/build/run.js:248:40)
at _runTest (/workspaces/fast-check/node_modules/jest-circus/build/run.js:184:3)
at _runTestsForDescribeBlock (/workspaces/fast-check/node_modules/jest-circus/build/run.js:86:9)
at _runTestsForDescribeBlock (/workspaces/fast-check/node_modules/jest-circus/build/run.js:81:9)
at run (/workspaces/fast-check/node_modules/jest-circus/build/run.js:26:3)
at runAndTransformResultsToJestFormat (/workspaces/fast-check/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:120:21)
at jestAdapter (/workspaces/fast-check/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
at runTestInternal (/workspaces/fast-check/node_modules/jest-runner/build/runTest.js:367:16)
at runTest (/workspaces/fast-check/node_modules/jest-runner/build/runTest.js:444:34)
Execution summary:
√ [2147483626]
× [1152992794]
. √ [0]
. √ [576496397]
. × [864744596]
. . √ [720620497]
. . √ [792682547]
. . √ [828713572]
. . √ [846729084]
. . × [855736840]
. . . √ [851232962]
. . . √ [853484901]
. . . √ [854610871]
. . . × [855173856]
. . . . √ [854892364]
. . . . × [855033110]
. . . . . √ [854962737]
. . . . . × [854997924]
. . . . . . × [854980331]
. . . . . . . √ [854971534]
. . . . . . . × [854975933]
. . . . . . . . √ [854973734]
. . . . . . . . √ [854974834]
. . . . . . . . √ [854975384]
. . . . . . . . √ [854975659]
. . . . . . . . √ [854975796]
. . . . . . . . √ [854975865]
. . . . . . . . × [854975899]
. . . . . . . . . × [854975882]
. . . . . . . . . . √ [854975874]
. . . . . . . . . . √ [854975878]
. . . . . . . . . . × [854975880]
. . . . . . . . . . . √ [854975879]"
`;
exports[`NoRegression float 1`] = `
"Property failed after 1 tests
{ seed: 42, path: "0:1:0:1", endOnFailure: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe.each([[true], [false]])('AsyncProperty (dontRunHook: %p)', (dontRunHook

// Assert
expect((out as PropertyFailure).errorMessage).toContain('predicate throws');
expect((out as PropertyFailure).errorMessage).toContain('\n\nStack trace:');
expect((out as PropertyFailure).errorMessage).toContain('at ');
expect((out as PropertyFailure).error).toBe(originalError);
});
it('Should fail if predicate throws a raw string', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe.each([[true], [false]])('Property (dontRunHook: %p)', (dontRunHook) =>

// Assert
expect((out as PropertyFailure).errorMessage).toContain('predicate throws');
expect((out as PropertyFailure).errorMessage).toContain('\n\nStack trace:');
expect((out as PropertyFailure).errorMessage).toContain('at ');
expect((out as PropertyFailure).error).toBe(originalError);
});
it('Should fail if predicate throws a raw string', () => {
Expand Down

0 comments on commit f24f79f

Please sign in to comment.