diff --git a/property_tests/index.ts b/property_tests/index.ts index 5e896d5901..ebf9e6a6e1 100644 --- a/property_tests/index.ts +++ b/property_tests/index.ts @@ -12,60 +12,75 @@ export type Named = { export { getActor } from './get_actor'; -export function runPropTests(canisterArb: fc.Arbitrary) { - fc.assert( - fc.asyncProperty(canisterArb, async (canister) => { - if (!existsSync('src')) { - mkdirSync('src'); - } - - writeFileSync('src/index.ts', canister.sourceCode); - - execSync(`npx prettier --write src`, { - stdio: 'inherit' - }); +export async function runPropTests(canisterArb: fc.Arbitrary) { + try { + await fc.assert( + fc.asyncProperty(canisterArb, async (canister) => { + if (!existsSync('src')) { + mkdirSync('src'); + } - execSync(`dfx canister uninstall-code canister || true`, { - stdio: 'inherit' - }); + writeFileSync('src/index.ts', canister.sourceCode); - for (let i = 0; i < canister.tests.length; i++) { - execSync(`dfx deploy canister`, { + execSync(`npx prettier --write src`, { stdio: 'inherit' }); - execSync(`dfx generate canister`, { + execSync(`dfx canister uninstall-code canister || true`, { stdio: 'inherit' }); - const tests = canister.tests[i]; - - const result = await runTests( - tests, - process.env.AZLE_PROPTEST_VERBOSE !== 'true' - ); + for (let i = 0; i < canister.tests.length; i++) { + execSync(`dfx deploy canister`, { + stdio: 'inherit' + }); - execSync( - `node_modules/.bin/tsc --noEmit --skipLibCheck --target es2020 --strict --moduleResolution node --allowJs`, - { + execSync(`dfx generate canister`, { stdio: 'inherit' - } - ); + }); - clearUniquePrimitiveArb(); + const tests = canister.tests[i]; - if (result === false) { - return false; + const result = await runTests( + tests, + process.env.AZLE_PROPTEST_QUIET === 'true' + ); + + execSync( + `node_modules/.bin/tsc --noEmit --skipLibCheck --target es2020 --strict --moduleResolution node --allowJs`, + { + stdio: 'inherit' + } + ); + + clearUniquePrimitiveArb(); + + if (result === false) { + return false; + } } - } - return true; - }), - { - numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1), - endOnFailure: true // TODO This essentially disables shrinking. We don't know how to do shrinking well yet + return true; + }), + { + numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1), + endOnFailure: true // TODO This essentially disables shrinking. We don't know how to do shrinking well yet + } + ); + } catch (error) { + if (process.env.AZLE_PROPTEST_VERBOSE !== 'true') { + // Customize the error message to exclude counter example + if (error instanceof Error) { + const errorLines = error.message.split('\n'); + const newError = [ + ...errorLines.slice(0, 2), + ...errorLines.slice(errorLines.length - 4) + ].join('\n'); + error.message = newError; + } } - ); + throw error; + } } export const defaultArrayConstraints = {