From bd5c699a5595d1fd84c941b9b2e47a7af65f6851 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 2 Jan 2024 16:22:53 +0000 Subject: [PATCH 01/15] =?UTF-8?q?=F0=9F=91=B7=20Move=20build=20chain=20to?= =?UTF-8?q?=20ESM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **⚠️ Minor breaking change** The build chain of `fast-check` has been CommonJS-based since day 1. With ESM moving forward in the ecosystem, it's time to move ourselves to the new standard and adapt our build chains to ESM. Unfortunately it may have some subtle impacts on our users as our package will not be a CJS one offering a ESM fallback anymore. I will rather be the opposite: an ESM package with a fallback to CJS. It implies that we moved ESM related files closer to the root of the package (we could have kept them in esm/) and moved the CJS ones further in the file structure (we had to move them). Another subtle impact is that it would impose our users to run at least Node ≥12.17.0. As such we consider it as a breaking change. On its own it should not be a huge problem for most of the users but given it changes our minimal requirement let's put it into the next major release. --- packages/fast-check/README.md | 18 +++++----- packages/fast-check/jest.setup.js | 5 +-- packages/fast-check/package.cjs-template.json | 3 ++ packages/fast-check/package.esm-template.json | 3 -- packages/fast-check/package.json | 33 ++++++++++--------- yarn.lock | 1 + 6 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 packages/fast-check/package.cjs-template.json delete mode 100644 packages/fast-check/package.esm-template.json diff --git a/packages/fast-check/README.md b/packages/fast-check/README.md index 887582b7641..a9079ebf51f 100644 --- a/packages/fast-check/README.md +++ b/packages/fast-check/README.md @@ -117,18 +117,20 @@ It also proved useful in finding bugs among major open source projects such as [ Here are the minimal requirements to use fast-check properly without any polyfills: -| fast-check | node | ECMAScript version | _TypeScript (optional)_ | -| ---------- | ------------------- | ------------------ | ----------------------- | -| **3.x** | ≥8(1) | ES2017 | ≥4.1(2) | -| **2.x** | ≥8(1) | ES2017 | ≥3.2(3) | -| **1.x** | ≥0.12(1) | ES3 | ≥3.0(3) | +| fast-check | node | ECMAScript version | _TypeScript (optional)_ | +| ---------- | -------------------- | ------------------ | ----------------------- | +| **4.x** | ≥12.17(1) | ES2017 | ≥4.1(3) | +| **3.x** | ≥8(2) | ES2017 | ≥4.1(3) | +| **2.x** | ≥8(2) | ES2017 | ≥3.2(4) | +| **1.x** | ≥0.12(2) | ES3 | ≥3.0(4) |
More details... -1. Except for features that cannot be polyfilled - such as `bigint`-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check. -2. Require either lib or target ≥ ES2020 or `@types/node` to be installed. -3. Require either lib or target ≥ ES2015 or `@types/node` to be installed. +1. Support for `package.json#exports` is required. +2. Except for features that cannot be polyfilled - such as `bigint`-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check. +3. Require either lib or target ≥ ES2020 or `@types/node` to be installed. +4. Require either lib or target ≥ ES2015 or `@types/node` to be installed.
diff --git a/packages/fast-check/jest.setup.js b/packages/fast-check/jest.setup.js index 58cff20e6d8..61cc01bbeb3 100644 --- a/packages/fast-check/jest.setup.js +++ b/packages/fast-check/jest.setup.js @@ -1,5 +1,6 @@ -const process = require('process'); -const fc = require('fast-check'); +import process from 'process'; +import fc from 'fast-check'; +import { jest } from '@jest/globals'; // Default timeout of 120s jest.setTimeout(120000); diff --git a/packages/fast-check/package.cjs-template.json b/packages/fast-check/package.cjs-template.json new file mode 100644 index 00000000000..5bbefffbabe --- /dev/null +++ b/packages/fast-check/package.cjs-template.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/packages/fast-check/package.esm-template.json b/packages/fast-check/package.esm-template.json deleted file mode 100644 index 3dbc1ca591c..00000000000 --- a/packages/fast-check/package.esm-template.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/packages/fast-check/package.json b/packages/fast-check/package.json index 60e63e7f1c7..f60f9944231 100644 --- a/packages/fast-check/package.json +++ b/packages/fast-check/package.json @@ -2,22 +2,22 @@ "name": "fast-check", "version": "3.15.0", "description": "Property based testing framework for JavaScript (like QuickCheck)", - "type": "commonjs", + "type": "module", "main": "lib/fast-check.js", "exports": { "./package.json": "./package.json", ".": { "require": { - "types": "./lib/types/fast-check.d.ts", - "default": "./lib/fast-check.js" + "types": "./lib/cjs/types/fast-check.d.ts", + "default": "./lib/cjs/fast-check.js" }, "import": { - "types": "./lib/esm/types/fast-check.d.ts", - "default": "./lib/esm/fast-check.js" + "types": "./lib/types/fast-check.d.ts", + "default": "./lib/fast-check.js" } } }, - "module": "lib/esm/fast-check.js", + "module": "lib/fast-check.js", "types": "lib/types/fast-check.d.ts", "files": [ "lib", @@ -28,17 +28,17 @@ "scripts": { "build": "yarn build:publish-cjs && yarn build:publish-esm && yarn build:publish-types && node postbuild/main.cjs", "build-ci": "cross-env EXPECT_GITHUB_SHA=true yarn build", - "build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/esm/types", - "build:publish-cjs": "tsc -p tsconfig.publish.json", - "build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node --outDir lib/esm && cp package.esm-template.json lib/esm/package.json", + "build:publish-types": "tsc -p tsconfig.publish.types.json && tsc -p tsconfig.publish.types.json --outDir lib/cjs/types", + "build:publish-cjs": "tsc -p tsconfig.publish.json --outDir lib/cjs && cp package.cjs-template.json lib/cjs/package.json", + "build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node", "typecheck": "tsc --noEmit", - "test": "jest --config jest.unit.config.cjs --coverage --verbose", - "test:watch": "jest --config jest.unit.config.cjs --watch", - "test:debug": "node --inspect ../../node_modules/jest/bin/jest.js --config jest.unit.config.cjs --watch --runInBand", - "e2e": "jest --config jest.e2e.config.cjs --coverage --verbose", - "e2e:watch": "jest --config jest.e2e.config.cjs --watch", - "e2e:debug": "node --inspect ../../node_modules/jest/bin/jest.js --config jest.e2e.config.cjs --watch --runInBand", - "update:examples": "cross-env UPDATE_CODE_SNIPPETS=true jest --config jest.examples.config.cjs", + "test": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.cjs --coverage --verbose", + "test:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.cjs --watch", + "test:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.unit.config.cjs --watch --runInBand", + "e2e": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.cjs --coverage --verbose", + "e2e:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.cjs --watch", + "e2e:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.e2e.config.cjs --watch --runInBand", + "update:examples": "cross-env UPDATE_CODE_SNIPPETS=true yarn node --experimental-vm-modules $(yarn bin jest) --config jest.examples.config.cjs", "test-bundle": "node test-bundle/run.cjs && node test-bundle/run.mjs && node test-bundle/run-advanced.cjs", "test-legacy-bundle": "nvs add 8 && $(nvs which 8) test-bundle/run.cjs && $(nvs which 8) test-bundle/run-advanced.cjs", "docs": "api-extractor run --local && rm docs/fast-check.api.json && typedoc --out docs src/fast-check-default.ts && node postbuild/main.cjs", @@ -68,6 +68,7 @@ "@babel/preset-typescript": "^7.23.3", "@fast-check/expect-type": "workspace:*", "@fast-check/poisoning": "workspace:*", + "@jest/globals": "^29.7.0", "@microsoft/api-extractor": "^7.38.5", "@types/jest": "^29.5.11", "@types/node": "^20.10.4", diff --git a/yarn.lock b/yarn.lock index 088a0d3b7c8..f075872eb9e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8848,6 +8848,7 @@ __metadata: "@babel/preset-typescript": "npm:^7.23.3" "@fast-check/expect-type": "workspace:*" "@fast-check/poisoning": "workspace:*" + "@jest/globals": "npm:^29.7.0" "@microsoft/api-extractor": "npm:^7.38.5" "@types/jest": "npm:^29.5.11" "@types/node": "npm:^20.10.4" From 6e517ab6bc913cfc558d45cf31f06fe06b5ee5cb Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 2 Jan 2024 16:24:52 +0000 Subject: [PATCH 02/15] fix postbuild scripts --- packages/fast-check/postbuild/main.cjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/fast-check/postbuild/main.cjs b/packages/fast-check/postbuild/main.cjs index 601161c2a4b..de90d85207c 100644 --- a/packages/fast-check/postbuild/main.cjs +++ b/packages/fast-check/postbuild/main.cjs @@ -41,7 +41,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => { const packageVersion = JSON.parse(data.toString()).version; const commonJsReplacement = replace.sync({ - files: 'lib/fast-check-default.js', + files: 'lib/cjs/fast-check-default.js', from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g], to: ['commonjs', packageVersion, commitHash], }); @@ -51,7 +51,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => { } const moduleReplacement = replace.sync({ - files: 'lib/esm/fast-check-default.js', + files: 'lib/fast-check-default.js', from: [/__PACKAGE_TYPE__/g, /__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g], to: ['module', packageVersion, commitHash], }); @@ -61,7 +61,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => { } const dTsReplacement = replace.sync({ - files: 'lib/types/fast-check-default.d.ts', + files: 'lib/cjs/types/fast-check-default.d.ts', from: [/__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g], to: [packageVersion, commitHash], }); @@ -71,7 +71,7 @@ fs.readFile(path.join(__dirname, '../package.json'), (err, data) => { } const dTsReplacement2 = replace.sync({ - files: 'lib/esm/types/fast-check-default.d.ts', + files: 'lib/types/fast-check-default.d.ts', from: [/__PACKAGE_VERSION__/g, /__COMMIT_HASH__/g], to: [packageVersion, commitHash], }); From c7e81cc73cf97e1a519687c23e2a5b9e8a5179f9 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 2 Jan 2024 16:30:08 +0000 Subject: [PATCH 03/15] bump legacy version --- packages/fast-check/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fast-check/package.json b/packages/fast-check/package.json index f60f9944231..7a94ab12383 100644 --- a/packages/fast-check/package.json +++ b/packages/fast-check/package.json @@ -40,7 +40,7 @@ "e2e:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.e2e.config.cjs --watch --runInBand", "update:examples": "cross-env UPDATE_CODE_SNIPPETS=true yarn node --experimental-vm-modules $(yarn bin jest) --config jest.examples.config.cjs", "test-bundle": "node test-bundle/run.cjs && node test-bundle/run.mjs && node test-bundle/run-advanced.cjs", - "test-legacy-bundle": "nvs add 8 && $(nvs which 8) test-bundle/run.cjs && $(nvs which 8) test-bundle/run-advanced.cjs", + "test-legacy-bundle": "nvs add 12.17 && $(nvs which 12.17) test-bundle/run.cjs && $(nvs which 12.17) test-bundle/run-advanced.cjs", "docs": "api-extractor run --local && rm docs/fast-check.api.json && typedoc --out docs src/fast-check-default.ts && node postbuild/main.cjs", "docs-ci": "cross-env EXPECT_GITHUB_SHA=true yarn docs", "docs:serve": "yarn dlx serve docs/" From ac96f55d384d35cc0e1fb03702ac6022ddc61a30 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sat, 6 Jan 2024 16:49:36 +0000 Subject: [PATCH 04/15] Migrate jest --- .../fast-check/{jest.config.cjs => jest.config.js} | 3 ++- .../{jest.e2e.config.cjs => jest.e2e.config.js} | 4 ++-- packages/fast-check/jest.examples.config.cjs | 5 ----- packages/fast-check/jest.examples.config.js | 5 +++++ packages/fast-check/jest.unit.config.cjs | 4 ++-- packages/fast-check/package.json | 14 +++++++------- 6 files changed, 18 insertions(+), 17 deletions(-) rename packages/fast-check/{jest.config.cjs => jest.config.js} (81%) rename packages/fast-check/{jest.e2e.config.cjs => jest.e2e.config.js} (69%) delete mode 100644 packages/fast-check/jest.examples.config.cjs create mode 100644 packages/fast-check/jest.examples.config.js diff --git a/packages/fast-check/jest.config.cjs b/packages/fast-check/jest.config.js similarity index 81% rename from packages/fast-check/jest.config.cjs rename to packages/fast-check/jest.config.js index ad965a160d1..106cf7bc96c 100644 --- a/packages/fast-check/jest.config.cjs +++ b/packages/fast-check/jest.config.js @@ -1,9 +1,10 @@ // Shared Jest configuration // Useful for Jest plugin of vscode -module.exports = { +export default { collectCoverageFrom: ['/src/**'], testMatch: ['/test/**/*.spec.ts'], setupFiles: [], setupFilesAfterEnv: ['/jest.setup.js'], + extensionsToTreatAsEsm: ['.ts'], }; diff --git a/packages/fast-check/jest.e2e.config.cjs b/packages/fast-check/jest.e2e.config.js similarity index 69% rename from packages/fast-check/jest.e2e.config.cjs rename to packages/fast-check/jest.e2e.config.js index 6a00881e667..8c247409415 100644 --- a/packages/fast-check/jest.e2e.config.cjs +++ b/packages/fast-check/jest.e2e.config.js @@ -1,6 +1,6 @@ -const conf = require('./jest.config.cjs'); +import conf from './jest.config.js'; -module.exports = Object.assign(conf, { +export default Object.assign(conf, { testMatch: ['/test/e2e/**/*.spec.ts'], testPathIgnorePatterns: typeof BigInt === 'undefined' ? ['/NoRegressionBigInt.spec.ts', '/documentation/Docs.md.spec.ts'] : [], diff --git a/packages/fast-check/jest.examples.config.cjs b/packages/fast-check/jest.examples.config.cjs deleted file mode 100644 index 39e38147363..00000000000 --- a/packages/fast-check/jest.examples.config.cjs +++ /dev/null @@ -1,5 +0,0 @@ -const conf = require('./jest.e2e.config.cjs'); - -module.exports = Object.assign(conf, { - testMatch: ['/test/e2e/documentation/**/*.spec.ts'], -}); diff --git a/packages/fast-check/jest.examples.config.js b/packages/fast-check/jest.examples.config.js new file mode 100644 index 00000000000..6f6ee517f2e --- /dev/null +++ b/packages/fast-check/jest.examples.config.js @@ -0,0 +1,5 @@ +import conf from './jest.e2e.config.js'; + +export default Object.assign(conf, { + testMatch: ['/test/e2e/documentation/**/*.spec.ts'], +}); diff --git a/packages/fast-check/jest.unit.config.cjs b/packages/fast-check/jest.unit.config.cjs index 9508fdabb00..5888542e630 100644 --- a/packages/fast-check/jest.unit.config.cjs +++ b/packages/fast-check/jest.unit.config.cjs @@ -1,6 +1,6 @@ -const conf = require('./jest.config.cjs'); +import conf from './jest.config.js'; -module.exports = Object.assign(conf, { +export default Object.assign(conf, { testMatch: ['/test/unit/**/*.spec.ts'], coverageDirectory: 'coverage', coveragePathIgnorePatterns: ['/lib/', '/test/'], diff --git a/packages/fast-check/package.json b/packages/fast-check/package.json index 7a94ab12383..325c5d1576f 100644 --- a/packages/fast-check/package.json +++ b/packages/fast-check/package.json @@ -32,13 +32,13 @@ "build:publish-cjs": "tsc -p tsconfig.publish.json --outDir lib/cjs && cp package.cjs-template.json lib/cjs/package.json", "build:publish-esm": "tsc -p tsconfig.publish.json --module es2015 --moduleResolution node", "typecheck": "tsc --noEmit", - "test": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.cjs --coverage --verbose", - "test:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.cjs --watch", - "test:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.unit.config.cjs --watch --runInBand", - "e2e": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.cjs --coverage --verbose", - "e2e:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.cjs --watch", - "e2e:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.e2e.config.cjs --watch --runInBand", - "update:examples": "cross-env UPDATE_CODE_SNIPPETS=true yarn node --experimental-vm-modules $(yarn bin jest) --config jest.examples.config.cjs", + "test": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.js --coverage --verbose", + "test:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.unit.config.js --watch", + "test:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.unit.config.js --watch --runInBand", + "e2e": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.js --coverage --verbose", + "e2e:watch": "yarn node --experimental-vm-modules $(yarn bin jest) --config jest.e2e.config.js --watch", + "e2e:debug": "yarn node --experimental-vm-modules --inspect $(yarn bin jest) --config jest.e2e.config.js --watch --runInBand", + "update:examples": "cross-env UPDATE_CODE_SNIPPETS=true yarn node --experimental-vm-modules $(yarn bin jest) --config jest.examples.config.js", "test-bundle": "node test-bundle/run.cjs && node test-bundle/run.mjs && node test-bundle/run-advanced.cjs", "test-legacy-bundle": "nvs add 12.17 && $(nvs which 12.17) test-bundle/run.cjs && $(nvs which 12.17) test-bundle/run-advanced.cjs", "docs": "api-extractor run --local && rm docs/fast-check.api.json && typedoc --out docs src/fast-check-default.ts && node postbuild/main.cjs", From 03fb4da7726f82071e75dd94a337c3c1bf5f1768 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sat, 6 Jan 2024 17:08:55 +0000 Subject: [PATCH 05/15] missing rename --- packages/fast-check/{jest.unit.config.cjs => jest.unit.config.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/fast-check/{jest.unit.config.cjs => jest.unit.config.js} (100%) diff --git a/packages/fast-check/jest.unit.config.cjs b/packages/fast-check/jest.unit.config.js similarity index 100% rename from packages/fast-check/jest.unit.config.cjs rename to packages/fast-check/jest.unit.config.js From b2abd2c869c3ea64a78ac130145aa44b6df294a3 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sat, 6 Jan 2024 23:55:39 +0100 Subject: [PATCH 06/15] Update Timeout.spec.ts --- packages/fast-check/test/e2e/Timeout.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fast-check/test/e2e/Timeout.spec.ts b/packages/fast-check/test/e2e/Timeout.spec.ts index 2dd19d05a48..05217656841 100644 --- a/packages/fast-check/test/e2e/Timeout.spec.ts +++ b/packages/fast-check/test/e2e/Timeout.spec.ts @@ -1,5 +1,6 @@ import * as fc from '../../src/fast-check'; import { seed } from './seed'; +import { jest } from '@jest/globals'; describe(`Timeout (seed: ${seed})`, () => { it('should always run beforeEach and afterEach even in case of timeout', async () => { From ea29fcf58318de832529cd71a3c6d6e6d45f7d26 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sat, 6 Jan 2024 23:56:24 +0100 Subject: [PATCH 07/15] Update NoRegressionStack.spec.ts.snap --- .../test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap b/packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap index efe497b5ece..a26b6a74e27 100644 --- a/packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap +++ b/packages/fast-check/test/e2e/__snapshots__/NoRegressionStack.spec.ts.snap @@ -20,7 +20,7 @@ Got TypeError: v is not a function at Property.predicate [as run] (packages/fast-check/src/check/property/Property.generic.ts:?:?) at run (packages/fast-check/src/check/runner/Runner.ts:?:?) at runIt (packages/fast-check/src/check/runner/Runner.ts:?:?) - at Object.check (packages/fast-check/src/check/runner/Runner.ts:?:?) + at Module.check (packages/fast-check/src/check/runner/Runner.ts:?:?) at assert (packages/fast-check/test/e2e/NoRegressionStack.spec.ts:?:?) at run (packages/fast-check/test/e2e/__test-helpers__/StackSanitizer.ts:?:?) @@ -45,7 +45,7 @@ Got error: Property failed by returning false at Property.run (packages/fast-check/src/check/property/Property.generic.ts:?:?) at run (packages/fast-check/src/check/runner/Runner.ts:?:?) at runIt (packages/fast-check/src/check/runner/Runner.ts:?:?) - at Object.check (packages/fast-check/src/check/runner/Runner.ts:?:?) + at Module.check (packages/fast-check/src/check/runner/Runner.ts:?:?) at assert (packages/fast-check/test/e2e/NoRegressionStack.spec.ts:?:?) at run (packages/fast-check/test/e2e/__test-helpers__/StackSanitizer.ts:?:?) @@ -72,7 +72,7 @@ Got error: a must be >= b at Property.predicate [as run] (packages/fast-check/src/check/property/Property.generic.ts:?:?) at run (packages/fast-check/src/check/runner/Runner.ts:?:?) at runIt (packages/fast-check/src/check/runner/Runner.ts:?:?) - at Object.check (packages/fast-check/src/check/runner/Runner.ts:?:?) + at Module.check (packages/fast-check/src/check/runner/Runner.ts:?:?) at assert (packages/fast-check/test/e2e/NoRegressionStack.spec.ts:?:?) at run (packages/fast-check/test/e2e/__test-helpers__/StackSanitizer.ts:?:?) From 1b3d51c769fc67ee9d78bd271075d7dda6bfe398 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sun, 7 Jan 2024 00:05:10 +0100 Subject: [PATCH 08/15] Update ArbitraryHelpers.ts --- .../test/unit/arbitrary/__test-helpers__/ArbitraryHelpers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryHelpers.ts b/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryHelpers.ts index 70c43f89e03..4e2babe539f 100644 --- a/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryHelpers.ts +++ b/packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryHelpers.ts @@ -3,6 +3,7 @@ import { Arbitrary } from '../../../../src/check/arbitrary/definition/Arbitrary' import { Value } from '../../../../src/check/arbitrary/definition/Value'; import type { Random } from '../../../../src/random/generator/Random'; import { Stream } from '../../../../src/stream/Stream'; +import { jest } from '@jest/globals'; /** * Generate a fake Class inheriting from Arbitrary with all methods being mocked From 9009c3495ee03215f7aaed4e8b7503e583102c7a Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sun, 7 Jan 2024 00:11:48 +0100 Subject: [PATCH 09/15] Update PropertyHelpers.ts --- .../test/unit/check/property/__test-helpers__/PropertyHelpers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fast-check/test/unit/check/property/__test-helpers__/PropertyHelpers.ts b/packages/fast-check/test/unit/check/property/__test-helpers__/PropertyHelpers.ts index f2a5759237a..ea137ee2616 100644 --- a/packages/fast-check/test/unit/check/property/__test-helpers__/PropertyHelpers.ts +++ b/packages/fast-check/test/unit/check/property/__test-helpers__/PropertyHelpers.ts @@ -1,5 +1,6 @@ import type { MaybeMocked } from '../../../__test-helpers__/Mocked'; import type { IRawProperty } from '../../../../../src/check/property/IRawProperty'; +import { jest } from '@jest/globals'; /** * Generate a fake instance inheriting from IRawProperty with all methods being mocked From 94b6f8f4b61f00012712dd011a185fafcdc41243 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sun, 7 Jan 2024 00:21:58 +0100 Subject: [PATCH 10/15] Update RandomHelpers.ts --- .../test/unit/arbitrary/__test-helpers__/RandomHelpers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts b/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts index 80aab14beb3..899cd8ef7fd 100644 --- a/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts +++ b/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts @@ -1,5 +1,6 @@ import type { MaybeMocked } from '../../__test-helpers__/Mocked'; import { Random } from '../../../../src/random/generator/Random'; +import { jest } from '@jest/globals'; export function fakeRandom(): { instance: Random } & Omit, 'internalRng' | 'uniformIn'> { const clone = jest.fn(); From 408b975a54f11235be4103b42600b7bc40c3e05e Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Mon, 19 Feb 2024 22:04:51 +0000 Subject: [PATCH 11/15] fix unit/utils --- packages/fast-check/test/unit/utils/apply.spec.ts | 1 + packages/fast-check/test/unit/utils/stringify.spec.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/fast-check/test/unit/utils/apply.spec.ts b/packages/fast-check/test/unit/utils/apply.spec.ts index 3176c71232f..d7c456bf389 100644 --- a/packages/fast-check/test/unit/utils/apply.spec.ts +++ b/packages/fast-check/test/unit/utils/apply.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { safeApply } from '../../../src/utils/apply'; describe('safeApply', () => { diff --git a/packages/fast-check/test/unit/utils/stringify.spec.ts b/packages/fast-check/test/unit/utils/stringify.spec.ts index eef5166fbbc..8bf778ad33f 100644 --- a/packages/fast-check/test/unit/utils/stringify.spec.ts +++ b/packages/fast-check/test/unit/utils/stringify.spec.ts @@ -1,4 +1,5 @@ import * as fc from 'fast-check'; +import { jest } from '@jest/globals'; // Importing 'buffer' imports the real implementation from node // Instead we want 'buffer' from our node_modules - the most used polyfill for Buffer on browser-side From f90567a17fed5c880549b08cb8b4e2a77bf29743 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Mon, 19 Feb 2024 22:07:27 +0000 Subject: [PATCH 12/15] unit/stream --- .../fast-check/test/unit/stream/LazyIterableIterator.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fast-check/test/unit/stream/LazyIterableIterator.spec.ts b/packages/fast-check/test/unit/stream/LazyIterableIterator.spec.ts index 73e7860a6b1..9540dac8cf5 100644 --- a/packages/fast-check/test/unit/stream/LazyIterableIterator.spec.ts +++ b/packages/fast-check/test/unit/stream/LazyIterableIterator.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { makeLazy } from '../../../src/stream/LazyIterableIterator'; describe('makeLazy', () => { From dacf4e32da824f741d10992ced6bdbc0113e2cf1 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Mon, 19 Feb 2024 22:13:59 +0000 Subject: [PATCH 13/15] fix unit/check without mocks fixing --- packages/fast-check/test/e2e/arbitraries/Arbitrary.spec.ts | 1 + .../test/unit/check/arbitrary/definition/Arbitrary.utest.spec.ts | 1 + .../test/unit/check/arbitrary/definition/NextValue.utest.spec.ts | 1 + .../test/unit/check/model/commands/CommandWrapper.spec.ts | 1 + .../test/unit/check/model/commands/ScheduledCommand.spec.ts | 1 + .../fast-check/test/unit/check/property/AsyncProperty.spec.ts | 1 + packages/fast-check/test/unit/check/property/Property.spec.ts | 1 + .../test/unit/check/property/SkipAfterProperty.spec.ts | 1 + .../fast-check/test/unit/check/property/TimeoutProperty.spec.ts | 1 + .../fast-check/test/unit/check/runner/DecorateProperty.spec.ts | 1 + 10 files changed, 10 insertions(+) diff --git a/packages/fast-check/test/e2e/arbitraries/Arbitrary.spec.ts b/packages/fast-check/test/e2e/arbitraries/Arbitrary.spec.ts index 65208bc1f5b..4d75bb45c14 100644 --- a/packages/fast-check/test/e2e/arbitraries/Arbitrary.spec.ts +++ b/packages/fast-check/test/e2e/arbitraries/Arbitrary.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import * as fc from '../../../src/fast-check'; import { seed } from '../seed'; diff --git a/packages/fast-check/test/unit/check/arbitrary/definition/Arbitrary.utest.spec.ts b/packages/fast-check/test/unit/check/arbitrary/definition/Arbitrary.utest.spec.ts index 583ee4b8dbd..d4c2419345e 100644 --- a/packages/fast-check/test/unit/check/arbitrary/definition/Arbitrary.utest.spec.ts +++ b/packages/fast-check/test/unit/check/arbitrary/definition/Arbitrary.utest.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { Arbitrary } from '../../../../../src/check/arbitrary/definition/Arbitrary'; import { Value } from '../../../../../src/check/arbitrary/definition/Value'; import { Stream } from '../../../../../src/stream/Stream'; diff --git a/packages/fast-check/test/unit/check/arbitrary/definition/NextValue.utest.spec.ts b/packages/fast-check/test/unit/check/arbitrary/definition/NextValue.utest.spec.ts index da9aef1f560..917f14d1a87 100644 --- a/packages/fast-check/test/unit/check/arbitrary/definition/NextValue.utest.spec.ts +++ b/packages/fast-check/test/unit/check/arbitrary/definition/NextValue.utest.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { Value } from '../../../../../src/check/arbitrary/definition/Value'; import { cloneMethod } from '../../../../../src/check/symbols'; diff --git a/packages/fast-check/test/unit/check/model/commands/CommandWrapper.spec.ts b/packages/fast-check/test/unit/check/model/commands/CommandWrapper.spec.ts index 32e999848fe..ea170c590f7 100644 --- a/packages/fast-check/test/unit/check/model/commands/CommandWrapper.spec.ts +++ b/packages/fast-check/test/unit/check/model/commands/CommandWrapper.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { CommandWrapper } from '../../../../../src/check/model/commands/CommandWrapper'; import type { Command } from '../../../../../src/check/model/command/Command'; import type { AsyncCommand } from '../../../../../src/check/model/command/AsyncCommand'; diff --git a/packages/fast-check/test/unit/check/model/commands/ScheduledCommand.spec.ts b/packages/fast-check/test/unit/check/model/commands/ScheduledCommand.spec.ts index d58c149c3c5..3aa273452cc 100644 --- a/packages/fast-check/test/unit/check/model/commands/ScheduledCommand.spec.ts +++ b/packages/fast-check/test/unit/check/model/commands/ScheduledCommand.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { ScheduledCommand } from '../../../../../src/check/model/commands/ScheduledCommand'; import type { AsyncCommand } from '../../../../../src/check/model/command/AsyncCommand'; import type { Scheduler, SchedulerSequenceItem } from '../../../../../src/arbitrary/scheduler'; diff --git a/packages/fast-check/test/unit/check/property/AsyncProperty.spec.ts b/packages/fast-check/test/unit/check/property/AsyncProperty.spec.ts index c2fa8c4754e..b56500bd269 100644 --- a/packages/fast-check/test/unit/check/property/AsyncProperty.spec.ts +++ b/packages/fast-check/test/unit/check/property/AsyncProperty.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import type { Arbitrary } from '../../../../src/check/arbitrary/definition/Arbitrary'; import { asyncProperty } from '../../../../src/check/property/AsyncProperty'; import { pre } from '../../../../src/check/precondition/Pre'; diff --git a/packages/fast-check/test/unit/check/property/Property.spec.ts b/packages/fast-check/test/unit/check/property/Property.spec.ts index 072c453a02f..dee09207ba9 100644 --- a/packages/fast-check/test/unit/check/property/Property.spec.ts +++ b/packages/fast-check/test/unit/check/property/Property.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import type { Arbitrary } from '../../../../src/check/arbitrary/definition/Arbitrary'; import { property } from '../../../../src/check/property/Property'; import { pre } from '../../../../src/check/precondition/Pre'; diff --git a/packages/fast-check/test/unit/check/property/SkipAfterProperty.spec.ts b/packages/fast-check/test/unit/check/property/SkipAfterProperty.spec.ts index bcecf332ef1..a9b76593b2c 100644 --- a/packages/fast-check/test/unit/check/property/SkipAfterProperty.spec.ts +++ b/packages/fast-check/test/unit/check/property/SkipAfterProperty.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { SkipAfterProperty } from '../../../../src/check/property/SkipAfterProperty'; import { PreconditionFailure } from '../../../../src/check/precondition/PreconditionFailure'; import { fakeProperty } from './__test-helpers__/PropertyHelpers'; diff --git a/packages/fast-check/test/unit/check/property/TimeoutProperty.spec.ts b/packages/fast-check/test/unit/check/property/TimeoutProperty.spec.ts index 29a01ce6844..8ad24e7d0f2 100644 --- a/packages/fast-check/test/unit/check/property/TimeoutProperty.spec.ts +++ b/packages/fast-check/test/unit/check/property/TimeoutProperty.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { Value } from '../../../../src/check/arbitrary/definition/Value'; import { TimeoutProperty } from '../../../../src/check/property/TimeoutProperty'; import { fakeRandom } from '../../arbitrary/__test-helpers__/RandomHelpers'; diff --git a/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts b/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts index a1ad3e3dc64..634215039d9 100644 --- a/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts +++ b/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts @@ -1,3 +1,4 @@ +import { jest } from '@jest/globals'; import { decorateProperty } from '../../../../src/check/runner/DecorateProperty'; import type { IRawProperty } from '../../../../src/check/property/IRawProperty'; import { Value } from '../../../../src/check/arbitrary/definition/Value'; From f2be5b8c933305040e0ac99ac0e3a93ff9730053 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 12 Mar 2024 08:05:57 +0000 Subject: [PATCH 14/15] Fix src/check --- .../check/runner/DecorateProperty.spec.ts | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts b/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts index 634215039d9..feda3bfbd13 100644 --- a/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts +++ b/packages/fast-check/test/unit/check/runner/DecorateProperty.spec.ts @@ -1,18 +1,27 @@ import { jest } from '@jest/globals'; -import { decorateProperty } from '../../../../src/check/runner/DecorateProperty'; import type { IRawProperty } from '../../../../src/check/property/IRawProperty'; -import { Value } from '../../../../src/check/arbitrary/definition/Value'; -import { Stream } from '../../../../src/stream/Stream'; + +jest.unstable_mockModule('./src/check/property/SkipAfterProperty', () => ({ + SkipAfterProperty: jest.fn(), +})); +jest.unstable_mockModule('./src/check/property/TimeoutProperty', () => ({ + TimeoutProperty: jest.fn(), +})); +jest.unstable_mockModule('./src/check/property/UnbiasedProperty', () => ({ + UnbiasedProperty: jest.fn(), +})); +jest.unstable_mockModule('./src/check/property/IgnoreEqualValuesProperty', () => ({ + IgnoreEqualValuesProperty: jest.fn(), +})); +const { decorateProperty } = await import('../../../../src/check/runner/DecorateProperty'); +const { Value } = await import('../../../../src/check/arbitrary/definition/Value'); +const { Stream } = await import('../../../../src/stream/Stream'); // Mocks -import { SkipAfterProperty } from '../../../../src/check/property/SkipAfterProperty'; -import { TimeoutProperty } from '../../../../src/check/property/TimeoutProperty'; -import { UnbiasedProperty } from '../../../../src/check/property/UnbiasedProperty'; -import { IgnoreEqualValuesProperty } from '../../../../src/check/property/IgnoreEqualValuesProperty'; -jest.mock('../../../../src/check/property/SkipAfterProperty'); -jest.mock('../../../../src/check/property/TimeoutProperty'); -jest.mock('../../../../src/check/property/UnbiasedProperty'); -jest.mock('../../../../src/check/property/IgnoreEqualValuesProperty'); +const { SkipAfterProperty } = await import('../../../../src/check/property/SkipAfterProperty'); +const { TimeoutProperty } = await import('../../../../src/check/property/TimeoutProperty'); +const { UnbiasedProperty } = await import('../../../../src/check/property/UnbiasedProperty'); +const { IgnoreEqualValuesProperty } = await import('../../../../src/check/property/IgnoreEqualValuesProperty'); function buildProperty(asyncProp: boolean) { return { From 6e55faca4a5e72659cc66ea6fa12e81ed4c9bf72 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 12 Mar 2024 08:20:38 +0000 Subject: [PATCH 15/15] Fix typedIntArrayArbitraryArbitraryBuilder --- .../TypedIntArrayArbitraryBuilder.spec.ts | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/fast-check/test/unit/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder.spec.ts b/packages/fast-check/test/unit/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder.spec.ts index 03057247677..5dab30e3bd5 100644 --- a/packages/fast-check/test/unit/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder.spec.ts +++ b/packages/fast-check/test/unit/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder.spec.ts @@ -1,24 +1,33 @@ +import { jest } from '@jest/globals'; import * as fc from 'fast-check'; -import { typedIntArrayArbitraryArbitraryBuilder } from '../../../../../src/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder'; -import { FakeIntegerArbitrary, fakeArbitrary, fakeArbitraryStaticValue } from '../../__test-helpers__/ArbitraryHelpers'; +jest.unstable_mockModule('./src/arbitrary/array', () => ({ + array: jest.fn(), +})); -import * as ArrayMock from '../../../../../src/arbitrary/array'; -import { +const { typedIntArrayArbitraryArbitraryBuilder } = await import( + '../../../../../src/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder' +); + +const { FakeIntegerArbitrary, fakeArbitrary, fakeArbitraryStaticValue } = await import( + '../../__test-helpers__/ArbitraryHelpers' +); +const { assertProduceCorrectValues, assertProduceSameValueGivenSameSeed, assertProduceValuesShrinkableWithoutContext, assertShrinkProducesSameValueWithoutInitialContext, -} from '../../__test-helpers__/ArbitraryAssertions'; +} = await import('../../__test-helpers__/ArbitraryAssertions'); -function beforeEachHook() { - jest.resetModules(); - jest.restoreAllMocks(); - fc.configureGlobal({ beforeEach: beforeEachHook }); -} -beforeEach(beforeEachHook); +const ArrayMock = await import('../../../../../src/arbitrary/array'); describe('typedIntArrayArbitraryArbitraryBuilder', () => { + function beforeEachHook() { + jest.resetAllMocks(); + } + fc.configureGlobal({ beforeEach: beforeEachHook }); + beforeEach(beforeEachHook); + it('should default constraints for arbitraryBuilder to defaultMin/Max when not specified', () => { fc.assert( fc.property( @@ -123,6 +132,13 @@ describe('typedIntArrayArbitraryArbitraryBuilder', () => { }); describe('typedIntArrayArbitraryArbitraryBuilder (integration)', () => { + function beforeEachHook() { + jest.resetAllMocks(); + jest.spyOn(ArrayMock, 'array').mockImplementation(jest.requireActual('./lib/cjs/arbitrary/array').array); + } + fc.configureGlobal({ beforeEach: beforeEachHook }); + beforeEach(beforeEachHook); + type Extra = { minLength?: number; maxLength?: number; min?: number; max?: number }; const extraParameters: fc.Arbitrary = fc .record(