Skip to content

Commit

Permalink
update location of defaultPropTestParams to not accidentally pull in …
Browse files Browse the repository at this point in the history
…jest
  • Loading branch information
bdemann committed Feb 4, 2025
1 parent 67d534f commit 2d77598
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
30 changes: 1 addition & 29 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as dns from 'node:dns';
dns.setDefaultResultOrder('ipv4first');

import { describe, expect, test } from '@jest/globals';
import * as fc from 'fast-check';

import { execSyncPretty } from '../src/build/stable/utils/exec_sync_pretty';
export { expect } from '@jest/globals';
Expand All @@ -12,6 +11,7 @@ import { runFuzzTests } from './fuzz';
export type Test = () => void;

export { getCanisterActor } from './get_canister_actor';
export { defaultPropTestParams } from './property/default_prop_test_params';

export function runTests(
tests: Test,
Expand Down Expand Up @@ -96,34 +96,6 @@ export function it(name: string, fn: () => void | Promise<void>): void {
it.only = test.only;
it.skip = test.skip;

export function defaultPropTestParams<T = unknown>(): fc.Parameters<T> {
const baseParams = {
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
reporter: (runDetails: fc.RunDetails<T>): void => {
const seed = runDetails.seed;
const path = runDetails.counterexamplePath;
const reproductionCommand = `AZLE_PROPTEST_SEED=${seed}${path !== null ? ` AZLE_PROPTEST_PATH="${path}"` : ''} AZLE_VERBOSE=true AZLE_TEMPLATE=true npm test`;
const reproductionMessage = `To reproduce this exact test case, run:\n${reproductionCommand}`;
console.info(reproductionMessage);
if (runDetails.failed) {
throw new Error(
`${reproductionMessage}\n\n${fc.defaultReportMessage(runDetails)}`
);
}
},
endOnFailure: process.env.AZLE_PROPTEST_SHRINK === 'true' ? false : true
};

const seed =
process.env.AZLE_PROPTEST_SEED !== undefined
? Number(process.env.AZLE_PROPTEST_SEED)
: undefined;

const path = process.env.AZLE_PROPTEST_PATH;

return seed !== undefined ? { ...baseParams, seed, path } : baseParams;
}

function processEnvVars(): {
shouldRunTests: boolean;
shouldRunTypeChecks: boolean;
Expand Down
29 changes: 29 additions & 0 deletions test/property/default_prop_test_params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as fc from 'fast-check';

export function defaultPropTestParams<T = unknown>(): fc.Parameters<T> {
const baseParams = {
numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1),
reporter: (runDetails: fc.RunDetails<T>): void => {
const seed = runDetails.seed;
const path = runDetails.counterexamplePath;
const reproductionCommand = `AZLE_PROPTEST_SEED=${seed}${path !== null ? ` AZLE_PROPTEST_PATH="${path}"` : ''} AZLE_VERBOSE=true AZLE_TEMPLATE=true npm test`;
const reproductionMessage = `To reproduce this exact test case, run:\n${reproductionCommand}`;
console.info(reproductionMessage);
if (runDetails.failed) {
throw new Error(
`${reproductionMessage}\n\n${fc.defaultReportMessage(runDetails)}`
);
}
},
endOnFailure: process.env.AZLE_PROPTEST_SHRINK === 'true' ? false : true
};

const seed =
process.env.AZLE_PROPTEST_SEED !== undefined
? Number(process.env.AZLE_PROPTEST_SEED)
: undefined;

const path = process.env.AZLE_PROPTEST_PATH;

return seed !== undefined ? { ...baseParams, seed, path } : baseParams;
}
2 changes: 1 addition & 1 deletion test/property/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { execSync } from 'child_process';
import fc from 'fast-check';
import { existsSync, mkdirSync, writeFileSync } from 'fs';

import { defaultPropTestParams } from '../';
import { Canister } from './arbitraries/canister_arb';
import { clear as clearUniquePrimitiveArb } from './arbitraries/unique_primitive_arb';
import { defaultPropTestParams } from './default_prop_test_params';
import { runTests } from './test';

export type Named<T> = {
Expand Down

0 comments on commit 2d77598

Please sign in to comment.