Explorar o código

Integrate Crowi setup tests and refactor instance retrieval logic

Yuki Takei hai 2 meses
pai
achega
b93e215a4b

+ 3 - 15
apps/app/src/server/crowi/crowi-setup.integ.ts → apps/app/test-with-vite/setup/crowi.integ.ts

@@ -2,13 +2,10 @@
  * Integration test to verify Crowi setup works correctly in Vitest environment.
  * This ensures the test-with-vite/setup/crowi.ts utility functions properly.
  */
-import { beforeAll, describe, expect, it } from 'vitest';
 
-import {
-  getInstance,
-  resetInstance,
-} from '../../../test-with-vite/setup/crowi';
-import type Crowi from './index';
+import type Crowi from '~/server/crowi';
+
+import { getInstance, resetInstance } from './crowi';
 
 describe('Crowi Setup for Integration Tests', () => {
   let crowi: Crowi;
@@ -45,13 +42,4 @@ describe('Crowi Setup for Integration Tests', () => {
     const crowi2 = await getInstance();
     expect(crowi2).toBe(crowi);
   });
-
-  // Skip: Creating a new instance causes mongoose discriminator conflicts
-  // because models are registered globally. In practice, tests should use
-  // the singleton instance for isolation.
-  it.skip('should create new instance when isNewInstance is true', async () => {
-    const newCrowi = await getInstance(true);
-    expect(newCrowi).not.toBe(crowi);
-    expect(newCrowi.version).toBeDefined();
-  });
 });

+ 1 - 8
apps/app/test-with-vite/setup/crowi.ts

@@ -39,16 +39,9 @@ const initCrowi = async (crowi: Crowi): Promise<void> => {
  * Get a Crowi instance for integration testing.
  * By default, returns a singleton instance. Pass true to create a new instance.
  *
- * @param isNewInstance - If true, creates a new Crowi instance instead of returning singleton
  * @returns Promise resolving to a Crowi instance
  */
-export async function getInstance(isNewInstance?: boolean): Promise<Crowi> {
-  if (isNewInstance) {
-    const crowi = new Crowi();
-    await initCrowi(crowi);
-    return crowi;
-  }
-
+export async function getInstance(): Promise<Crowi> {
   // Initialize singleton instance
   if (_instance == null) {
     _instance = new Crowi();

+ 2 - 3
apps/app/test-with-vite/tsconfig.json

@@ -2,10 +2,9 @@
   "$schema": "http://json.schemastore.org/tsconfig",
   "extends": "../../../tsconfig.base.json",
   "compilerOptions": {
-    "baseUrl": "../",
     "paths": {
-      "~/*": ["./src/*"],
-      "^/*": ["./*"]
+      "~/*": ["../src/*"],
+      "^/*": ["../*"]
     }
   }
 }