import { MochaOptions } from "mocha" ; export enum TestConfigs { RunAll , Coverage = "coverage" , IgnoredInCoverage = "ignored in coverage" , Mainnet = "mainnet" } const fixCoverageOptimizerDetails = { yul : true , yulDetails : { stackAllocation : true , } , } as const ; export interface TestOptions { mocha : MochaOptions ; initialBaseFeePerGas : number | undefined ; optimizerDetails : typeof fixCoverageOptimizerDetails | undefined ; } let currentConfig = TestConfigs . RunAll ; const regexpIgnoredOnCoverage = /\[skip-in-coverage\]/ ; export function setupTestConfigs ( config ) { const mocha = { } ; let optimizerDetails = undefined ; let initialBaseFeePerGas = undefined ; switch ( config ) { case undefined : currentConfig = TestConfigs . RunAll ; break ; case "coverage" : currentConfig = TestConfigs . Coverage ; mocha . grep = /^(?!Mainnet)/ ; initialBaseFeePerGas = 1 ; optimizerDetails = fixCoverageOptimizerDetails ; break ; case "ignored in coverage" : currentConfig = TestConfigs . IgnoredInCoverage ; mocha . grep = regexpIgnoredOnCoverage ; break ; case "mainnet" : currentConfig = TestConfigs . Mainnet ; mocha . grep = /^Mainnet/ ; break ; default : throw new Error ( `Invalid test config string ${ config }` ) ; } return { mocha , initialBaseFeePerGas , optimizerDetails } ; } export function skipOnCoverage ( this ) { if ( currentConfig === TestConfigs . Coverage ) { if ( ! regexpIgnoredOnCoverage . test ( this . test ?. fullTitle ( ) ?? "" ) ) { throw new Error ( "Test is ignored in coverage but does not have the flag [skip-in-coverage] in the description" ) ; } this . skip ( ) ; } }