-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Stop repeating the error twice in reports (#3638)
* ✨ Stop repeating the error twice in reports 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 * Drop Error: from report * versions * unfify stacks cross os * safer poisoned * format * Update packages/fast-check/test/e2e/NoRegressionStack.spec.ts * Update packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap * Update packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap * Update packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap * Update packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap * Update packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap * fix no reg * fix unit
- Loading branch information
Showing
10 changed files
with
133 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
releases: | ||
fast-check: minor | ||
|
||
declined: | ||
- "@fast-check/ava" | ||
- "@fast-check/jest" | ||
- "@fast-check/vitest" | ||
- "@fast-check/worker" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import fc from '../../src/fast-check'; | ||
|
||
const settings = { seed: 42, verbose: 0 }; | ||
|
||
describe(`NoRegressionStack`, () => { | ||
it('throw', () => { | ||
expect( | ||
sanitize(() => | ||
fc.assert( | ||
fc.property(fc.nat(), fc.nat(), (a, b) => { | ||
if (a < b) { | ||
throw new Error('a must be >= b'); | ||
} | ||
}), | ||
settings | ||
) | ||
) | ||
).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
it('not a function', () => { | ||
expect( | ||
sanitize(() => | ||
fc.assert( | ||
fc.property(fc.nat(), (v) => { | ||
(v as any)(); | ||
}), | ||
settings | ||
) | ||
) | ||
).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
// Helpers | ||
|
||
function sanitize(run: () => void) { | ||
return () => { | ||
try { | ||
run(); | ||
} catch (err) { | ||
const initialMessage = (err as Error).message; | ||
const lines = initialMessage | ||
.replace(/\\/g, '/') | ||
.replace(/at [^(]*fast-check\/(packages|node_modules)(.*)/g, 'at $1$2') | ||
.replace(/at (.*) \(.*fast-check\/(packages|node_modules)(.*)\)/g, 'at $1 ($2$3)') | ||
.replace(/at (.*) \((node_modules\/.*):\d+:\d+\)/g, 'at $1 ($2:?:?)') // reducing risks of changes on bumps | ||
.split('\n'); | ||
throw new Error( | ||
lines | ||
.slice( | ||
0, | ||
// internals of jest, subject to regular changes | ||
// and OS dependent | ||
lines.findIndex((line) => line.includes('node_modules/jest-circus')) | ||
) | ||
.join('\n') | ||
); | ||
} | ||
}; | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NoRegressionStack not a function 1`] = ` | ||
"Property failed after 1 tests | ||
{ seed: 42, path: "0:0", endOnFailure: true } | ||
Counterexample: [0] | ||
Shrunk 1 time(s) | ||
Got TypeError: v is not a function | ||
at packages/fast-check/test/e2e/NoRegressionStack.spec.ts:26:14 | ||
at Property.predicate (packages/fast-check/src/check/property/Property.ts:23:56) | ||
at Property.predicate [as run] (packages/fast-check/src/check/property/Property.generic.ts:133:27) | ||
at run (packages/fast-check/src/check/runner/Runner.ts:37:26) | ||
at runIt (packages/fast-check/src/check/runner/Runner.ts:154:7) | ||
at Object.check (packages/fast-check/src/check/runner/Runner.ts:206:15) | ||
at packages/fast-check/test/e2e/NoRegressionStack.spec.ts:40:7 | ||
at _toThrowErrorMatchingSnapshot (node_modules/jest-snapshot/build/index.js:?:?) | ||
at Object.toThrowErrorMatchingSnapshot (node_modules/jest-snapshot/build/index.js:?:?) | ||
at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:?:?) | ||
at Object.throwingMatcher [as toThrowErrorMatchingSnapshot] (node_modules/expect/build/index.js:?:?) | ||
at Object.<anonymous> (packages/fast-check/test/e2e/NoRegressionStack.spec.ts:31:7)" | ||
`; | ||
exports[`NoRegressionStack throw 1`] = ` | ||
"Property failed after 2 tests | ||
{ seed: 42, path: "1:0:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0", endOnFailure: true } | ||
Counterexample: [0,1] | ||
Shrunk 32 time(s) | ||
Got error: a must be >= b | ||
at packages/fast-check/test/e2e/NoRegressionStack.spec.ts:12:21 | ||
at Property.predicate (packages/fast-check/src/check/property/Property.ts:23:56) | ||
at Property.predicate [as run] (packages/fast-check/src/check/property/Property.generic.ts:133:27) | ||
at run (packages/fast-check/src/check/runner/Runner.ts:37:26) | ||
at runIt (packages/fast-check/src/check/runner/Runner.ts:154:7) | ||
at Object.check (packages/fast-check/src/check/runner/Runner.ts:206:15) | ||
at packages/fast-check/test/e2e/NoRegressionStack.spec.ts:40:7 | ||
at _toThrowErrorMatchingSnapshot (node_modules/jest-snapshot/build/index.js:?:?) | ||
at Object.toThrowErrorMatchingSnapshot (node_modules/jest-snapshot/build/index.js:?:?) | ||
at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:?:?) | ||
at Object.throwingMatcher [as toThrowErrorMatchingSnapshot] (node_modules/expect/build/index.js:?:?) | ||
at Object.<anonymous> (packages/fast-check/test/e2e/NoRegressionStack.spec.ts:18:7)" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters