Skip to content

Commit

Permalink
chore: add checks in unit tests to ensure that the returned resolvedT…
Browse files Browse the repository at this point in the history
…imeline and resolvedState are serializable
  • Loading branch information
nytamin committed Oct 30, 2024
1 parent f6d131f commit 6d51ea6
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/groups.spec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/invalidate.spec.ts
Original file line number Diff line number Diff line change
@@ -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<T>(o: T): T {
return JSON.parse(JSON.stringify(o))
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/keyframes.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/testlib.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<typeof Timeline.resolveTimeline>
): ReturnType<typeof Timeline.resolveTimeline> {
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<typeof Timeline.getResolvedState>
): ReturnType<typeof Timeline.getResolvedState> {
const state = Timeline.getResolvedState(...args)
expect(() => JSON.stringify(state)).not.toThrow() // test that it's serializable
return state
}

0 comments on commit 6d51ea6

Please sign in to comment.