in packages/sqrl/src/testing/SqrlTest.ts [162:220]
async executeStatements(
ctx: Context,
statements: StatementAst[],
waitExecute: boolean = false
): Promise<SqrlExecutionState> {
const parserState = new SqrlParserState({
statements: [...this.statements, ...statements],
allowAssertions: true,
allowReplaceInput: true,
allowPrivate: this.allowPrivate,
instance: this.instance,
filesystem: this.filesystem,
});
const compiled = await SqrlCompiledOutput.build(ctx, parserState, {
skipCostCalculations: !this.calculateCost,
});
const slotCallback = this.executionContext.compileSlots(compiled.slotJs);
const sourcePrinter = new SqrlSourcePrinter({
slotNames: compiled.slotNames,
slotJs: compiled.slotJs,
});
// sourcePrinter.printAllSource();
const manipulator = this.manipulatorFactory
? this.manipulatorFactory()
: null;
// Create an execution state and run
const state = new SqrlExecutionState(
ctx,
slotCallback,
compiled.slotNames,
manipulator,
{
sourcePrinter,
featureTimeout: this.featureTimeout,
ruleSpecs: compiled.ruleSpecs,
},
this.inputs
);
await state.fetchClock();
await Promise.all([
state.tryWait("SqrlAssertionStatements").then(() => this.extendTimeout()),
state.tryWait("SqrlLogStatements").then(() => this.extendTimeout()),
waitExecute
? state
.fetchByName("SqrlExecutionComplete")
.then(() => this.extendTimeout())
: Promise.resolve(),
]);
return state;
}