Skip to content

Commit

Permalink
chore: fixes integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Oct 14, 2023
1 parent 0dac733 commit 8aa6ab5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
12 changes: 12 additions & 0 deletions apps/game-utils/tests/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,15 @@ function expectNumber(
function last(/** @type {string} */ property) {
return /** @type {string} */ (property.split('.').pop())
}

export function toEngineState(
/** @type {import('@tabulous/types').StartedGame} */ game,
/** @type {import('@tabulous/types').Player|undefined} */ player
) {
return {
meshes: game.meshes,
handMeshes:
game.hands.find(({ playerId }) => playerId === player?.id)?.meshes ?? [],
history: []
}
}
13 changes: 2 additions & 11 deletions apps/games/mah-jong/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { findMesh, snapTo, unsnap } from '@tabulous/game-utils'
import {
buildDescriptorTestSuite,
buildParameters,
enroll
enroll,
toEngineState
} from '@tabulous/game-utils/tests/game.js'
import { beforeEach, describe, expect, it } from 'vitest'

Expand Down Expand Up @@ -38,16 +39,6 @@ buildDescriptorTestSuite('mah-jong', descriptor, utils => {
)
})

function toEngineState(
/** @type {import('@tabulous/types').StartedGame} */ game
) {
return {
meshes: game.meshes,
handMeshes: [],
history: []
}
}

it('computes initial score', async () => {
expect(
descriptor.computeScore(
Expand Down
21 changes: 11 additions & 10 deletions apps/web/src/stores/graphql-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,17 @@ function processErrors(
* @returns deserialized value.
*/
function deserialize(value) {
const obj = /** @type {Record<string, ?> & {schema?: ?, preferences?: ?}} */ (
value
)
if ('schemaString' in obj) {
obj.schema = JSON.parse(obj.schemaString)
delete obj.schemaString
}
if ('preferencesString' in obj) {
obj.preferences = JSON.parse(obj.preferencesString)
delete obj.preferencesString
if (value) {
const obj =
/** @type {Record<string, ?> & {schema?: ?, preferences?: ?}} */ (value)
if ('schemaString' in obj) {
obj.schema = JSON.parse(obj.schemaString)
delete obj.schemaString
}
if ('preferencesString' in obj) {
obj.preferences = JSON.parse(obj.preferencesString)
delete obj.preferencesString
}
}
return value
}
2 changes: 1 addition & 1 deletion apps/web/tests/integration/utils/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const reporters = [
{ name: 'lcov' }
]
const previewURL = 'https://localhost:3000'
const distFolder = join('dist', 'unused/unused')
const distFolder = join('.vercel', 'output/static')
const srcFolder = resolve(__filename, '../../../../src')

export async function initializeCoverage() {
Expand Down

0 comments on commit 8aa6ab5

Please sign in to comment.