From 7fa50d6a761298c3ad60ce0151766438f1062347 Mon Sep 17 00:00:00 2001 From: kiosion Date: Fri, 9 Feb 2024 09:07:19 -0500 Subject: [PATCH] test: Fix issues with playwright tests --- svelte-app/.eslintrc | 3 ++- svelte-app/src/routes/+layout.ts | 24 ++++++++++++------------ svelte-app/tests/routes/index.test.ts | 6 +++--- svelte-app/tests/routes/post.test.ts | 6 +++--- svelte-app/tests/routes/work.test.ts | 8 ++++---- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/svelte-app/.eslintrc b/svelte-app/.eslintrc index 961c71f75..2fbc6aee3 100644 --- a/svelte-app/.eslintrc +++ b/svelte-app/.eslintrc @@ -135,7 +135,8 @@ "*.spec.ts" ], "rules": { - "@typescript-eslint/no-empty-function": ["off"] + "@typescript-eslint/no-empty-function": ["off"], + "no-restricted-imports": ["off"] } } ], diff --git a/svelte-app/src/routes/+layout.ts b/svelte-app/src/routes/+layout.ts index 3721ab723..c03291472 100644 --- a/svelte-app/src/routes/+layout.ts +++ b/svelte-app/src/routes/+layout.ts @@ -1,9 +1,10 @@ import { DEFAULT_APP_LANG } from '$lib/consts'; -import { handleLoadError } from '$lib/data'; import { ENV } from '$lib/env'; import Logger from '$lib/logger'; import { findOne } from '$lib/store'; +import { error } from '@sveltejs/kit'; + import type { LayoutLoad } from './$types'; import type { SiteConfig } from '$types'; @@ -12,17 +13,16 @@ export const trailingSlash = 'ignore'; export const ssr = ENV !== 'testing'; export const load = (async ({ params, url, fetch }) => { - const config = handleLoadError( - await findOne(fetch, 'config', { - lang: params.lang || DEFAULT_APP_LANG - }).catch((e: Error) => { - Logger.error('Failed to load layout data:', e); - throw new Error('Sorry, something went wrong during load.', { - cause: e?.cause, - stack: e?.stack - }); - }) - ) satisfies SiteConfig; + const config = (await findOne(fetch, 'config', { + lang: params.lang || DEFAULT_APP_LANG + }).catch((e: Error) => { + Logger.error('Failed to load layout data:', e); + throw error(500, { + message: 'Sorry, something went wrong during load.', + cause: e?.cause, + stack: e?.stack + }); + })) as SiteConfig; return { pathname: url.pathname, diff --git a/svelte-app/tests/routes/index.test.ts b/svelte-app/tests/routes/index.test.ts index c4a50f19d..5edc56519 100644 --- a/svelte-app/tests/routes/index.test.ts +++ b/svelte-app/tests/routes/index.test.ts @@ -1,8 +1,8 @@ -import { STUB_CONFIG, STUB_POST } from '$tests/fixtures'; -import { stubResponse } from '$tests/utils'; - import { expect, test } from '@playwright/test'; +import { STUB_CONFIG, STUB_POST } from '../fixtures'; +import { stubResponse } from '../utils'; + const API_CONFIG_ROUTE = /.*\/api\/get\/config.*/, API_POST_ROUTE = /.*\/api\/get\/post.*/, API_POST_MANY_ROUTE = /.*\/api\/get\/post\/many.*/; diff --git a/svelte-app/tests/routes/post.test.ts b/svelte-app/tests/routes/post.test.ts index b5aaa7420..dc08c9155 100644 --- a/svelte-app/tests/routes/post.test.ts +++ b/svelte-app/tests/routes/post.test.ts @@ -1,8 +1,8 @@ -import { STUB_CONFIG, STUB_POST } from '$tests/fixtures'; -import { API_CONFIG_ROUTE, API_POST_ROUTE, stubResponse } from '$tests/utils'; - import { expect, test } from '@playwright/test'; +import { STUB_CONFIG, STUB_POST } from '../fixtures'; +import { API_CONFIG_ROUTE, API_POST_ROUTE, stubResponse } from '../utils'; + test.beforeEach(async ({ context }) => { await context.route(API_CONFIG_ROUTE, (route) => route.fulfill(stubResponse({ data: STUB_CONFIG })) diff --git a/svelte-app/tests/routes/work.test.ts b/svelte-app/tests/routes/work.test.ts index b2bf9b6c1..1da824a39 100644 --- a/svelte-app/tests/routes/work.test.ts +++ b/svelte-app/tests/routes/work.test.ts @@ -1,12 +1,12 @@ -import { STUB_CONFIG, STUB_PROJECT } from '$tests/fixtures'; +import { expect, test } from '@playwright/test'; + +import { STUB_CONFIG, STUB_PROJECT } from '../fixtures'; import { API_CONFIG_ROUTE, API_PROJECT_MANY_ROUTE, API_PROJECT_ROUTE, stubResponse -} from '$tests/utils'; - -import { expect, test } from '@playwright/test'; +} from '../utils'; test.beforeEach(async ({ context }) => { await context.route(API_CONFIG_ROUTE, (route) =>