From 32e2aa69742261b83f768b994da6adb435a6da5d Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Wed, 27 Aug 2025 16:52:41 +0000 Subject: [PATCH] test: Setup transient di cache --- .mocharc.json | 3 +++ src/backend/tests/scrobbler/TestScrobbler.ts | 5 +++++ src/backend/tests/scrobbler/scrobblers.test.ts | 10 +++------- src/backend/tests/setup.ts | 8 ++++++++ 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/backend/tests/setup.ts diff --git a/.mocharc.json b/.mocharc.json index 15d99f31..c22a525b 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -3,5 +3,8 @@ "extension": "ts", "import": "tsx/esm", "spec": "./src/backend/tests/**/*.test.ts", + "file": [ + "./src/backend/tests/setup.ts" + ], "exit": true } diff --git a/src/backend/tests/scrobbler/TestScrobbler.ts b/src/backend/tests/scrobbler/TestScrobbler.ts index 93279fab..f1bae249 100644 --- a/src/backend/tests/scrobbler/TestScrobbler.ts +++ b/src/backend/tests/scrobbler/TestScrobbler.ts @@ -28,6 +28,11 @@ export class TestScrobbler extends AbstractScrobbleClient { return (await this.existingScrobble(playObj)) !== undefined; } + protected async doParseCache() { + await this.cache.init(); + return super.doParseCache(); + } + playToClientPayload(playObject: PlayObject): object { diff --git a/src/backend/tests/scrobbler/scrobblers.test.ts b/src/backend/tests/scrobbler/scrobblers.test.ts index 4755595f..f3bf87c7 100644 --- a/src/backend/tests/scrobbler/scrobblers.test.ts +++ b/src/backend/tests/scrobbler/scrobblers.test.ts @@ -8,16 +8,14 @@ import { http, HttpResponse } from 'msw'; import pEvent from 'p-event'; import { PlayObject } from "../../../core/Atomic.js"; import { genGroupIdStr, sleep } from "../../utils.js"; -import mixedDuration from '../plays/mixedDuration.json'; -import withDuration from '../plays/withDuration.json'; +import mixedDuration from '../plays/mixedDuration.json' with { type: 'json' }; +import withDuration from '../plays/withDuration.json' with { type: 'json' }; import { MockNetworkError, withRequestInterception } from "../utils/networking.js"; import { asPlays, generatePlay, generatePlayPlatformId, generatePlays, normalizePlays } from "../utils/PlayTestUtils.js"; import MockDate from 'mockdate'; import { NowPlayingScrobbler, TestAuthScrobbler, TestScrobbler } from "./TestScrobbler.js"; import { PlayPlatformId } from '../../common/infrastructure/Atomic.js'; -import { getRoot } from '../../ioc.js'; -import { loggerTest } from '@foxxmd/logging'; chai.use(asPromised); @@ -31,8 +29,6 @@ const normalizedWithMixedDur = normalizePlays(mixedDurPlays, {initialDate: first const normalizedWithMixedDurOlder = normalizePlays(mixedDurPlays, {initialDate: olderFirstPlayDate}); -getRoot({cache: {scrobble: {provider: 'memory'}}, logger: loggerTest}); - const generateTestScrobbler = () => { const testScrobbler = new TestScrobbler(); testScrobbler.verboseOptions = { @@ -665,7 +661,7 @@ describe('Scrobble client uses transform plays correctly', function() { describe('Manages scrobble queue', function() { - before(async function() { + beforeEach(async function() { testScrobbler = generateTestScrobbler(); await testScrobbler.initialize(); testScrobbler.recentScrobbles = normalizedWithMixedDur; diff --git a/src/backend/tests/setup.ts b/src/backend/tests/setup.ts new file mode 100644 index 00000000..c41a7fff --- /dev/null +++ b/src/backend/tests/setup.ts @@ -0,0 +1,8 @@ +import { loggerTest } from '@foxxmd/logging'; +import { getRoot } from "../ioc.js"; +import { MSCache } from '../common/Cache.js'; + +const transientCache = () => new MSCache(loggerTest, {scrobble: {provider: 'memory'}}); + +const root = getRoot({cache: transientCache, logger: loggerTest}); +root.items.cache().init(); \ No newline at end of file -- 2.51.2