From 8b22f31ff298fbb79ce1eb8a290959dd5f14bee6 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 28 Jun 2025 18:12:16 +0200 Subject: [PATCH 1/5] chore(api-server): Cleanup after premature merge --- .../api-server/src/__tests__/fastify.test.ts | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/packages/api-server/src/__tests__/fastify.test.ts b/packages/api-server/src/__tests__/fastify.test.ts index 28abbcabf6..de141ece85 100644 --- a/packages/api-server/src/__tests__/fastify.test.ts +++ b/packages/api-server/src/__tests__/fastify.test.ts @@ -54,38 +54,24 @@ const userConfig = { requestTimeout: 25_000, } -console.log('dirname', __dirname) -const fileOSRoot = path.parse(__dirname).root -console.log('fileOSRoot', fileOSRoot) - -vi.mock('/graphql/cedar-app/api/server.config.js', () => { - return { - default: { - config: userConfig, - }, - } -}) -vi.mock('/D:/graphql/cedar-app/api/server.config.js', () => { - return { - default: { - config: userConfig, - }, - } -}) -vi.mock('D:/graphql/cedar-app/api/server.config.js', () => { - return { - default: { - config: userConfig, - }, - } -}) -vi.mock('\\graphql\\cedar-app\\api\\server.config.js', () => { - return { - default: { - config: userConfig, - }, - } -}) +// This will be `D:\` on Windows, `/` on Unix. +const osRoot = path.parse(__dirname).root + +console.log( + 'full path', + path.join(osRoot, 'graphql/cedar-app/api/server.config.js'), +) + +vi.mock( + import(path.join(osRoot, 'graphql/cedar-app/api/server.config.js')), + () => { + return { + default: { + config: userConfig, + }, + } + }, +) describe('createFastifyInstance', () => { it('instantiates a fastify instance with default config', async () => { From 2ab441204e7cbbcc1174fb0404e3e30d11385353 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 28 Jun 2025 18:34:03 +0200 Subject: [PATCH 2/5] paths... --- packages/api-server/src/__tests__/fastify.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/api-server/src/__tests__/fastify.test.ts b/packages/api-server/src/__tests__/fastify.test.ts index de141ece85..06875004aa 100644 --- a/packages/api-server/src/__tests__/fastify.test.ts +++ b/packages/api-server/src/__tests__/fastify.test.ts @@ -1,4 +1,5 @@ import path from 'node:path' +import { pathToFileURL } from 'node:url' import fastify from 'fastify' import { vol } from 'memfs' @@ -63,7 +64,10 @@ console.log( ) vi.mock( - import(path.join(osRoot, 'graphql/cedar-app/api/server.config.js')), + import( + pathToFileURL(path.join(osRoot, 'graphql/cedar-app/api/server.config.js')) + .href + ), () => { return { default: { From 30d17ac8b59106d0c600aefdb981610613047119 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 28 Jun 2025 18:41:49 +0200 Subject: [PATCH 3/5] simple concat --- .../api-server/src/__tests__/fastify.test.ts | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/api-server/src/__tests__/fastify.test.ts b/packages/api-server/src/__tests__/fastify.test.ts index 06875004aa..0652e26e7c 100644 --- a/packages/api-server/src/__tests__/fastify.test.ts +++ b/packages/api-server/src/__tests__/fastify.test.ts @@ -1,5 +1,4 @@ import path from 'node:path' -import { pathToFileURL } from 'node:url' import fastify from 'fastify' import { vol } from 'memfs' @@ -56,26 +55,17 @@ const userConfig = { } // This will be `D:\` on Windows, `/` on Unix. -const osRoot = path.parse(__dirname).root - -console.log( - 'full path', - path.join(osRoot, 'graphql/cedar-app/api/server.config.js'), -) - -vi.mock( - import( - pathToFileURL(path.join(osRoot, 'graphql/cedar-app/api/server.config.js')) - .href - ), - () => { - return { - default: { - config: userConfig, - }, - } - }, -) +const osRoot = path.parse(__dirname).root.replace('\\', '/') + +console.log('full path', osRoot + 'graphql/cedar-app/api/server.config.js') + +vi.mock(osRoot + 'graphql/cedar-app/api/server.config.js', () => { + return { + default: { + config: userConfig, + }, + } +}) describe('createFastifyInstance', () => { it('instantiates a fastify instance with default config', async () => { From fa728ffb4cdba8955b7bca026c80be914c028b41 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 28 Jun 2025 18:57:02 +0200 Subject: [PATCH 4/5] hoisted --- packages/api-server/src/__tests__/fastify.test.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/api-server/src/__tests__/fastify.test.ts b/packages/api-server/src/__tests__/fastify.test.ts index 0652e26e7c..145f28f59f 100644 --- a/packages/api-server/src/__tests__/fastify.test.ts +++ b/packages/api-server/src/__tests__/fastify.test.ts @@ -1,5 +1,3 @@ -import path from 'node:path' - import fastify from 'fastify' import { vol } from 'memfs' import { @@ -54,12 +52,17 @@ const userConfig = { requestTimeout: 25_000, } -// This will be `D:\` on Windows, `/` on Unix. -const osRoot = path.parse(__dirname).root.replace('\\', '/') +const configPath = await vi.hoisted(async () => { + const path = await import('node:path') + + // This will be `D:\` on Windows, `/` on Unix. + const osRoot = path.parse(__dirname).root.replace('\\', '/') -console.log('full path', osRoot + 'graphql/cedar-app/api/server.config.js') + console.log('full path', osRoot + 'graphql/cedar-app/api/server.config.js') + return osRoot + 'graphql/cedar-app/api/server.config.js' +}) -vi.mock(osRoot + 'graphql/cedar-app/api/server.config.js', () => { +vi.mock(configPath, () => { return { default: { config: userConfig, From c76b87fbf6ac59f2cdd50e462940288f79a8b077 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 28 Jun 2025 19:20:58 +0200 Subject: [PATCH 5/5] supress logging in tests again --- packages/api-server/src/__tests__/fastify.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/api-server/src/__tests__/fastify.test.ts b/packages/api-server/src/__tests__/fastify.test.ts index 145f28f59f..ca2cf742cc 100644 --- a/packages/api-server/src/__tests__/fastify.test.ts +++ b/packages/api-server/src/__tests__/fastify.test.ts @@ -26,7 +26,7 @@ vi.mock('fastify', () => { }) // Suppress terminal logging. -// console.log = vi.fn() +console.log = vi.fn() // Set up RWJS_CWD. let original_RWJS_CWD: string | undefined @@ -55,10 +55,9 @@ const userConfig = { const configPath = await vi.hoisted(async () => { const path = await import('node:path') - // This will be `D:\` on Windows, `/` on Unix. + // This will be `D:\` on Windows (or some other drive letter) and `/` on Unix const osRoot = path.parse(__dirname).root.replace('\\', '/') - console.log('full path', osRoot + 'graphql/cedar-app/api/server.config.js') return osRoot + 'graphql/cedar-app/api/server.config.js' })