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

✨ Add support for fast-check test runners integrations #3568

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading