From 8aa6ab510acc6118c49a7a1e764bd2146ead4433 Mon Sep 17 00:00:00 2001 From: feugy Date: Sat, 14 Oct 2023 14:16:11 +0200 Subject: [PATCH] chore: fixes integration tests --- apps/game-utils/tests/game.js | 12 +++++++++++ apps/games/mah-jong/index.test.js | 13 ++---------- apps/web/src/stores/graphql-client.js | 21 ++++++++++---------- apps/web/tests/integration/utils/coverage.js | 2 +- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/apps/game-utils/tests/game.js b/apps/game-utils/tests/game.js index 97d89189..6f568386 100644 --- a/apps/game-utils/tests/game.js +++ b/apps/game-utils/tests/game.js @@ -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: [] + } +} diff --git a/apps/games/mah-jong/index.test.js b/apps/games/mah-jong/index.test.js index 56e71677..d07aebe8 100644 --- a/apps/games/mah-jong/index.test.js +++ b/apps/games/mah-jong/index.test.js @@ -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' @@ -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( diff --git a/apps/web/src/stores/graphql-client.js b/apps/web/src/stores/graphql-client.js index 5c24efd5..da9cf0b5 100644 --- a/apps/web/src/stores/graphql-client.js +++ b/apps/web/src/stores/graphql-client.js @@ -193,16 +193,17 @@ function processErrors( * @returns deserialized value. */ function deserialize(value) { - const obj = /** @type {Record & {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 & {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 } diff --git a/apps/web/tests/integration/utils/coverage.js b/apps/web/tests/integration/utils/coverage.js index decb3858..d1449c6a 100644 --- a/apps/web/tests/integration/utils/coverage.js +++ b/apps/web/tests/integration/utils/coverage.js @@ -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() {