From afad2eb6ebf99e83113d41502d83626f349718ec Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Tue, 3 Sep 2024 13:12:07 +0200 Subject: [PATCH] chore: update unit tests --- src/__tests__/invalidate.spec.ts | 6 +++--- src/__tests__/performance.spec.ts | 4 ++-- src/__tests__/performance.ts | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/__tests__/invalidate.spec.ts b/src/__tests__/invalidate.spec.ts index efc7598c..a1e37856 100644 --- a/src/__tests__/invalidate.spec.ts +++ b/src/__tests__/invalidate.spec.ts @@ -55,7 +55,7 @@ describeVariants( graphic1.enable.start = '#graphic0.end + 15' // 35 const resolved2 = resolveTimeline(timeline, { time: 0, cache }) - expect(resolved2.statistics.resolvingObjectCount).toEqual(1) + expect(resolved2.statistics.resolvingObjectCount).toEqual(2) expect(resolved2.objects['video'].resolved).toMatchObject({ instances: [{ start: 0, end: 100 }] }) expect(resolved2.objects['graphic0'].resolved).toMatchObject({ instances: [{ start: 10, end: 20 }] }) expect(resolved2.objects['graphic1'].resolved).toMatchObject({ instances: [{ start: 35, end: 50 }] }) @@ -121,7 +121,7 @@ describeVariants( const resolved2 = resolveTimeline(timeline, { time: 0, cache }) - expect(resolved2.statistics.resolvingObjectCount).toEqual(2) + expect(resolved2.statistics.resolvingObjectCount).toEqual(3) expect(resolved2.objects['video0'].resolved.instances).toMatchObject([{ start: 20, end: 30 }]) expect(resolved2.objects['graphic0'].resolved.instances).toMatchObject([{ start: 30, end: 40 }]) expect(resolved2.objects['graphic1'].resolved.instances).toHaveLength(0) @@ -261,7 +261,7 @@ describeVariants( timeline.splice(index, 1) const resolved3 = resolveTimeline(timeline, { time: 0, cache }) - expect(resolved3.statistics.resolvingObjectCount).toEqual(1) + expect(resolved3.statistics.resolvingObjectCount).toEqual(2) expect(resolved3.objects['video0'].resolved).toMatchObject({ instances: [{ start: 0, end: 100 }] }) expect(resolved3.objects['graphic0'].resolved).toMatchObject({ instances: [{ start: 10, end: 20 }] }) expect(resolved3.objects['graphic1'].resolved).toMatchObject({ instances: [{ start: 20, end: 25 }] }) diff --git a/src/__tests__/performance.spec.ts b/src/__tests__/performance.spec.ts index 68d04dff..1f0925ac 100644 --- a/src/__tests__/performance.spec.ts +++ b/src/__tests__/performance.spec.ts @@ -11,7 +11,7 @@ describe('performance', () => { test( 'performance test, no cache', () => { - const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, false) + const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, TIMEOUT_TIME, false) console.log( `No Cache: Average time of execution: ${round(executionTimeAvg)} ms\n` + 'Worst 5:\n' + @@ -29,7 +29,7 @@ describe('performance', () => { test( 'performance test, with cache', () => { - const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, true) + const { sortedTimes, executionTimeAvg } = doPerformanceTest(TEST_COUNT, TIMEOUT_TIME, true) console.log( `With cache: Average time of execution: ${round(executionTimeAvg)} ms\n` + 'Worst 5:\n' + diff --git a/src/__tests__/performance.ts b/src/__tests__/performance.ts index 3cc5ec01..748479d2 100644 --- a/src/__tests__/performance.ts +++ b/src/__tests__/performance.ts @@ -27,6 +27,7 @@ export const round = (num: number): number => { export const doPerformanceTest = ( testCount: number, + timeoutTime: number, useCache: boolean ): { errorCount: number @@ -48,8 +49,13 @@ export const doPerformanceTest = ( const testCountMax = testCount * 2 + const startTime = Date.now() for (let i = 0; i < testCountMax; i++) { if (executionTimeCount >= testCount) break + const totalDuration = Date.now() - startTime + if (totalDuration >= timeoutTime) { + throw new Error(`Tests took too long (${totalDuration}ms)`) + } seed++