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

👷 Move build chain to ESM #4592

Open
wants to merge 16 commits into
base: next-3_15_0
Choose a base branch
from
18 changes: 10 additions & 8 deletions packages/fast-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<sup>(1)</sup> | ES2017 | ≥4.1<sup>(2)</sup> |
| **2.x** | ≥8<sup>(1)</sup> | ES2017 | ≥3.2<sup>(3)</sup> |
| **1.x** | ≥0.12<sup>(1)</sup> | ES3 | ≥3.0<sup>(3)</sup> |
| fast-check | node | ECMAScript version | _TypeScript (optional)_ |
| ---------- | -------------------- | ------------------ | ----------------------- |
| **4.x** | ≥12.17<sup>(1)</sup> | ES2017 | ≥4.1<sup>(3)</sup> |
| **3.x** | ≥8<sup>(2)</sup> | ES2017 | ≥4.1<sup>(3)</sup> |
| **2.x** | ≥8<sup>(2)</sup> | ES2017 | ≥3.2<sup>(4)</sup> |
| **1.x** | ≥0.12<sup>(2)</sup> | ES3 | ≥3.0<sup>(4)</sup> |

<details>
<summary>More details...</summary>

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.

</details>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Shared Jest configuration
// Useful for Jest plugin of vscode

module.exports = {
export default {
collectCoverageFrom: ['<rootDir>/src/**'],
testMatch: ['<rootDir>/test/**/*.spec.ts'],
setupFiles: [],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
extensionsToTreatAsEsm: ['.ts'],
};
Original file line number Diff line number Diff line change
@@ -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: ['<rootDir>/test/e2e/**/*.spec.ts'],
testPathIgnorePatterns:
typeof BigInt === 'undefined' ? ['/NoRegressionBigInt.spec.ts', '/documentation/Docs.md.spec.ts'] : [],
Expand Down
5 changes: 0 additions & 5 deletions packages/fast-check/jest.examples.config.cjs

This file was deleted.

5 changes: 5 additions & 0 deletions packages/fast-check/jest.examples.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import conf from './jest.e2e.config.js';

export default Object.assign(conf, {
testMatch: ['<rootDir>/test/e2e/documentation/**/*.spec.ts'],
});
5 changes: 3 additions & 2 deletions packages/fast-check/jest.setup.js
Original file line number Diff line number Diff line change
@@ -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';
dubzzz marked this conversation as resolved.
Show resolved Hide resolved

// Default timeout of 120s
jest.setTimeout(120000);
Expand Down
Original file line number Diff line number Diff line change
@@ -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: ['<rootDir>/test/unit/**/*.spec.ts'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/test/'],
Expand Down
3 changes: 3 additions & 0 deletions packages/fast-check/package.cjs-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 0 additions & 3 deletions packages/fast-check/package.esm-template.json

This file was deleted.

35 changes: 18 additions & 17 deletions packages/fast-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/"
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/fast-check/postbuild/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
Expand All @@ -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],
});
Expand All @@ -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],
});
Expand All @@ -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],
});
Expand Down
1 change: 1 addition & 0 deletions packages/fast-check/test/e2e/Timeout.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:?:?)

Expand All @@ -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:?:?)

Expand All @@ -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:?:?)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';

Check failure on line 1 in packages/fast-check/test/e2e/arbitraries/Arbitrary.spec.ts

View workflow job for this annotation

GitHub Actions / Format & Lint

'jest' is defined but never used
import * as fc from '../../../src/fast-check';
import { seed } from '../seed';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MaybeMocked<Random>, 'internalRng' | 'uniformIn'> {
const clone = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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<Extra> = fc
.record(
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import { Value } from '../../../../../src/check/arbitrary/definition/Value';
import { cloneMethod } from '../../../../../src/check/symbols';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import { makeLazy } from '../../../src/stream/LazyIterableIterator';

describe('makeLazy', () => {
Expand Down
Loading
Loading