Skip to content

Commit

Permalink
✨ Add fast-check test runners integrations (#3568)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Cavin <me@sherlox.io>
  • Loading branch information
sheerlox committed Oct 19, 2023
1 parent 63fff3c commit f26ee46
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
19 changes: 12 additions & 7 deletions checks/raw/fuzzing.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,28 @@ var languageFuzzSpecs = map[clients.LanguageName]languageFuzzConfig{
// Fuzz patterns for JavaScript and TypeScript based on property-based testing.
//
// Based on the import of one of these packages:
// * https://fast-check.dev/
// * https://github.com/dubzzz/fast-check/tree/main/packages/fast-check#readme
// * https://github.com/dubzzz/fast-check/tree/main/packages/ava#readme
// * https://github.com/dubzzz/fast-check/tree/main/packages/jest#readme
// * https://github.com/dubzzz/fast-check/tree/main/packages/vitest#readme
//
// This is not an exhaustive list.
clients.JavaScript: {
filePatterns: []string{"*.js"},
// Look for direct imports of fast-check.
funcPattern: `(from\s+['"]fast-check['"]|require\(\s*['"]fast-check['"]\s*\))`,
Name: fuzzerPropertyBasedJavaScript,
// Look for direct imports of fast-check and its test runners integrations.
funcPattern: `(from\s+['"](fast-check|@fast-check/(ava|jest|vitest))['"]|` +
`require\(\s*['"](fast-check|@fast-check/(ava|jest|vitest))['"]\s*\))`,
Name: fuzzerPropertyBasedJavaScript,
Desc: asPointer(
"Property-based testing in JavaScript generates test instances randomly or exhaustively " +
"and test that specific properties are satisfied."),
},
clients.TypeScript: {
filePatterns: []string{"*.ts"},
// Look for direct imports of fast-check.
funcPattern: `(from\s+['"]fast-check['"]|require\(\s*['"]fast-check['"]\s*\))`,
Name: fuzzerPropertyBasedTypeScript,
// Look for direct imports of fast-check and its test runners integrations.
funcPattern: `(from\s+['"](fast-check|@fast-check/(ava|jest|vitest))['"]|` +
`require\(\s*['"](fast-check|@fast-check/(ava|jest|vitest))['"]\s*\))`,
Name: fuzzerPropertyBasedTypeScript,
Desc: asPointer(
"Property-based testing in TypeScript generates test instances randomly or exhaustively " +
"and test that specific properties are satisfied."),
Expand Down
48 changes: 48 additions & 0 deletions checks/raw/fuzzing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,30 @@ func Test_checkFuzzFunc(t *testing.T) {
},
fileContent: "import fc from \"fast-check\";",
},
{
name: "JavaScript fast-check scoped via require",
want: true,
fileName: []string{"main.spec.js"},
langs: []clients.Language{
{
Name: clients.JavaScript,
NumLines: 50,
},
},
fileContent: "const { fc, testProp } = require('@fast-check/ava');",
},
{
name: "JavaScript fast-check scoped via import",
want: true,
fileName: []string{"main.spec.js"},
langs: []clients.Language{
{
Name: clients.JavaScript,
NumLines: 50,
},
},
fileContent: "import { fc, test } from \"@fast-check/jest\";",
},
{
name: "JavaScript with no property-based testing",
want: false,
Expand Down Expand Up @@ -477,6 +501,30 @@ func Test_checkFuzzFunc(t *testing.T) {
},
fileContent: "import fc from \"fast-check\";",
},
{
name: "TypeScript fast-check scoped via require",
want: true,
fileName: []string{"main.spec.ts"},
langs: []clients.Language{
{
Name: clients.TypeScript,
NumLines: 50,
},
},
fileContent: "const { fc, testProp } = require('@fast-check/ava');",
},
{
name: "TypeScript fast-check scoped via import",
want: true,
fileName: []string{"main.spec.ts"},
langs: []clients.Language{
{
Name: clients.TypeScript,
NumLines: 50,
},
},
fileContent: "import { fc, test } from \"@fast-check/vitest\";",
},
{
name: "TypeScript with no property-based testing",
want: false,
Expand Down

0 comments on commit f26ee46

Please sign in to comment.