From 6d51ea6d4d49257948ab02ca5ec56023b3b0475b Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Wed, 30 Oct 2024 07:59:15 +0100 Subject: [PATCH] chore: add checks in unit tests to ensure that the returned resolvedTimeline and resolvedState are serializable --- src/__tests__/basic.spec.ts | 4 ++-- src/__tests__/groups.spec.ts | 4 ++-- src/__tests__/index.spec.ts | 3 +-- src/__tests__/invalidate.spec.ts | 4 ++-- src/__tests__/keyframes.spec.ts | 4 ++-- src/__tests__/legacy.spec.ts | 2 +- src/__tests__/testlib.ts | 18 ++++++++++++++++++ 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/__tests__/basic.spec.ts b/src/__tests__/basic.spec.ts index 9d5d7033..ce52e1c9 100644 --- a/src/__tests__/basic.spec.ts +++ b/src/__tests__/basic.spec.ts @@ -1,9 +1,9 @@ /* eslint-disable jest/no-standalone-expect */ -import { EventType, ResolvedTimelineObject, TimelineObjectInstance, getResolvedState, resolveTimeline } from '..' +import { EventType, ResolvedTimelineObject, TimelineObjectInstance } from '..' import { baseInstances } from '../resolver/lib/instance' -import { describeVariants } from './testlib' +import { describeVariants, resolveTimeline, getResolvedState } from './testlib' describeVariants( 'Resolver, basic', diff --git a/src/__tests__/groups.spec.ts b/src/__tests__/groups.spec.ts index 0b567dfe..ee42b9e2 100644 --- a/src/__tests__/groups.spec.ts +++ b/src/__tests__/groups.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable jest/no-standalone-expect */ -import { EventType, TimelineObjectInstance, getResolvedState, resolveTimeline } from '../' -import { describeVariants } from './testlib' +import { EventType, TimelineObjectInstance } from '../' +import { describeVariants, resolveTimeline, getResolvedState } from './testlib' import { omit } from '../resolver/lib/lib' import { baseInstances } from '../resolver/lib/instance' diff --git a/src/__tests__/index.spec.ts b/src/__tests__/index.spec.ts index a50bb44d..8ebdea9b 100644 --- a/src/__tests__/index.spec.ts +++ b/src/__tests__/index.spec.ts @@ -4,13 +4,12 @@ import { EventType, validateObject, validateTimeline, - resolveTimeline, - getResolvedState, applyKeyframeContent, ResolveError, } from '../index' import { baseInstances } from '../resolver/lib/instance' import { clone } from '../resolver/lib/lib' +import { resolveTimeline, getResolvedState } from './testlib' describe('index', () => { test('resolve timeline', () => { diff --git a/src/__tests__/invalidate.spec.ts b/src/__tests__/invalidate.spec.ts index a1e37856..3c38a9ad 100644 --- a/src/__tests__/invalidate.spec.ts +++ b/src/__tests__/invalidate.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable jest/no-standalone-expect */ -import { TimelineObject, getResolvedState, resolveTimeline } from '../' -import { describeVariants } from './testlib' +import { TimelineObject } from '../' +import { describeVariants, resolveTimeline, getResolvedState } from './testlib' function clone(o: T): T { return JSON.parse(JSON.stringify(o)) diff --git a/src/__tests__/keyframes.spec.ts b/src/__tests__/keyframes.spec.ts index db85881e..7d7fd270 100644 --- a/src/__tests__/keyframes.spec.ts +++ b/src/__tests__/keyframes.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable jest/no-standalone-expect */ -import { EventType, getResolvedState, resolveTimeline } from '../' +import { EventType } from '../' import { baseInstances } from '../resolver/lib/instance' -import { describeVariants } from './testlib' +import { describeVariants, resolveTimeline, getResolvedState } from './testlib' describeVariants( 'Resolver, keyframes', diff --git a/src/__tests__/legacy.spec.ts b/src/__tests__/legacy.spec.ts index f367593e..c59e7d31 100644 --- a/src/__tests__/legacy.spec.ts +++ b/src/__tests__/legacy.spec.ts @@ -12,7 +12,7 @@ import { TimelineEnable, } from '../api' -import { getResolvedState, resolveTimeline } from '..' +import { resolveTimeline, getResolvedState } from './testlib' import { clone, isEmpty, sortBy } from '../resolver/lib/lib' import { baseInstances } from '../resolver/lib/instance' diff --git a/src/__tests__/testlib.ts b/src/__tests__/testlib.ts index 1a44b6a1..ca59536b 100644 --- a/src/__tests__/testlib.ts +++ b/src/__tests__/testlib.ts @@ -1,6 +1,7 @@ /* eslint-disable jest/no-export, jest/valid-title, jest/expect-expect, jest/no-standalone-expect, jest/no-done-callback */ import { ResolverCache, TimelineObject } from '../api' +import * as Timeline from '..' interface Test { (name: string, fn?: ProvidesCallback, timeout?: number): void @@ -142,3 +143,20 @@ function reverseTimeline(tl: TimelineObject[]): TimelineObject[] { return tl } + +/** resolveTimeline, with an extra check that the timeline is serializable */ +export function resolveTimeline( + ...args: Parameters +): ReturnType { + const tl = Timeline.resolveTimeline(...args) + expect(() => JSON.stringify(tl)).not.toThrow() // test that it's serializable + return tl +} +/** getResolvedState, with an extra check that the state is serializable */ +export function getResolvedState( + ...args: Parameters +): ReturnType { + const state = Timeline.getResolvedState(...args) + expect(() => JSON.stringify(state)).not.toThrow() // test that it's serializable + return state +}