From 2aca829c913432766709ec920635179b4da810fe Mon Sep 17 00:00:00 2001 From: weareoutman Date: Sun, 27 Aug 2023 10:43:22 +0800 Subject: [PATCH] fix(): run storyboard function tests one by one asynchronously --- .../RunStoryboardFunctionTests.spec.ts | 6 +++++- .../RunStoryboardFunctionTests.ts | 21 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.spec.ts b/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.spec.ts index 7868a9648..a75450cbb 100644 --- a/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.spec.ts +++ b/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.spec.ts @@ -5,6 +5,10 @@ import { } from "./RunStoryboardFunctionTests"; describe("RunStoryboardFunctionTests", () => { + beforeAll(() => { + jest.useRealTimers(); + }); + it.each<[RunStoryboardFunctionTestsParams, RunStoryboardFunctionTestsResult]>( [ [ @@ -186,7 +190,7 @@ describe("RunStoryboardFunctionTests", () => { list: [true, false], }, }, - invalidFn: null, + invalidFn: null as any, noTests: { percentage: 0, stats: { diff --git a/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.ts b/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.ts index ba2fac21c..fe6c6b8b0 100644 --- a/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.ts +++ b/bricks/next-builder/src/data-providers/RunStoryboardFunctionTests.ts @@ -49,10 +49,10 @@ function getFunctionDebugger(): FunctionDebugger { return functionDebugger; } -export function RunStoryboardFunctionTests({ +export async function RunStoryboardFunctionTests({ functions, keepProcessedCoverage, -}: RunStoryboardFunctionTestsParams): RunStoryboardFunctionTestsResult { +}: RunStoryboardFunctionTestsParams): Promise { const { registerStoryboardFunctions, run, getCoverage } = getFunctionDebugger(); registerStoryboardFunctions(functions); @@ -60,7 +60,13 @@ export function RunStoryboardFunctionTests({ let passed = 0; const coverageByFunction: Record = {}; const validCoverages: CoverageCounts[] = []; - for (const fn of functions) { + + let cursor = 0; + async function one(): Promise { + if (cursor === functions.length) { + return; + } + const fn = functions[cursor]; let fnTotal = 0; let fnPassed = 0; const list: boolean[] = []; @@ -96,7 +102,16 @@ export function RunStoryboardFunctionTests({ } else { coverageByFunction[fn.name] = null; } + cursor++; + return new Promise((resolve) => { + setTimeout(() => { + resolve(one()); + }, 0); + }); } + + await one(); + return { coverage: accumulateCoverageReport(validCoverages, { total,