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.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.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/jest.unit.config.cjs b/packages/fast-check/jest.unit.config.js similarity index 65% rename from packages/fast-check/jest.unit.config.cjs rename to packages/fast-check/jest.unit.config.js index 9508fdabb00..5888542e630 100644 --- a/packages/fast-check/jest.unit.config.cjs +++ b/packages/fast-check/jest.unit.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/unit/**/*.spec.ts'], coverageDirectory: 'coverage', coveragePathIgnorePatterns: ['/lib/', '/test/'], 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..325c5d1576f 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,19 +28,19 @@ "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.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 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/" @@ -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/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], }); 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 () => { 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:?:?) 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/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 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(); 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( 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/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 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..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,17 +1,27 @@ -import { decorateProperty } from '../../../../src/check/runner/DecorateProperty'; +import { jest } from '@jest/globals'; 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 { 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', () => { 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 diff --git a/yarn.lock b/yarn.lock index b71cc1403d7..7498e331811 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8847,6 +8847,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"