فهرست منبع

Merge pull request #9144 from weseek/support/improve-vitest-environment

support: Improve vitest environment
mergify[bot] 1 سال پیش
والد
کامیت
5eae82f2fa

+ 1 - 4
apps/app/package.json

@@ -35,12 +35,9 @@
     "prelint:swagger2openapi": "yarn openapi:v3",
     "test": "run-p test:*",
     "test:jest": "cross-env NODE_ENV=test TS_NODE_PROJECT=test/integration/tsconfig.json jest",
-    "test:vitest": "run-p vitest:run vitest:run:integ vitest:run:components",
+    "test:vitest": "vitest run --coverage",
     "jest:run": "cross-env NODE_ENV=test TS_NODE_PROJECT=test/integration/tsconfig.json jest --passWithNoTests -- ",
     "reg:run": "reg-suit run",
-    "vitest:run": "vitest run config src --coverage",
-    "vitest:run:integ": "vitest run -c vitest.config.integ.ts src --coverage",
-    "vitest:run:components": "vitest run -c vitest.config.components.ts src --coverage",
     "previtest:run:integ": "vitest run -c test-with-vite/download-mongo-binary/vitest.config.ts test-with-vite/download-mongo-binary",
     "//// misc": "",
     "console": "yarn repl",

+ 15 - 14
apps/app/test-with-vite/download-mongo-binary/vitest.config.ts

@@ -1,15 +1,16 @@
-import { defineConfig, mergeConfig } from 'vitest/config';
+import tsconfigPaths from 'vite-tsconfig-paths';
+import { defineConfig } from 'vitest/config';
 
-import configShared from '../../vitest.config';
-
-export default mergeConfig(
-  configShared,
-  defineConfig({
-    test: {
-      hookTimeout: 60000, // increased for downloading MongoDB binary file
-      setupFiles: [
-        './test-with-vite/setup/mongoms.ts',
-      ],
-    },
-  }),
-);
+export default defineConfig({
+  plugins: [
+    tsconfigPaths(),
+  ],
+  test: {
+    clearMocks: true,
+    globals: true,
+    hookTimeout: 60000, // increased for downloading MongoDB binary file
+    setupFiles: [
+      './test-with-vite/setup/mongoms.ts',
+    ],
+  },
+});

+ 0 - 19
apps/app/vitest.config.components.ts

@@ -1,19 +0,0 @@
-import react from '@vitejs/plugin-react';
-import tsconfigPaths from 'vite-tsconfig-paths';
-import { defineConfig } from 'vitest/config';
-
-export default defineConfig({
-  plugins: [
-    react(), tsconfigPaths(),
-  ],
-  test: {
-    globals: true,
-    environment: 'happy-dom',
-    include: [
-      '**/*.spec.{tsx,jsx}',
-    ],
-    coverage: {
-      reportsDirectory: './coverage/components',
-    },
-  },
-});

+ 0 - 23
apps/app/vitest.config.integ.ts

@@ -1,23 +0,0 @@
-import { defineConfig, mergeConfig } from 'vitest/config';
-
-import configShared from './vitest.config';
-
-export default mergeConfig(
-  configShared,
-  defineConfig({
-    test: {
-      include: [
-        '**/*.integ.ts',
-      ],
-      setupFiles: [
-        './test-with-vite/setup/mongoms.ts',
-      ],
-      coverage: {
-        reportsDirectory: './coverage/integ',
-        exclude: [
-          '**/*{.,-}integ.ts',
-        ],
-      },
-    },
-  }),
-);

+ 0 - 19
apps/app/vitest.config.ts

@@ -1,19 +0,0 @@
-import tsconfigPaths from 'vite-tsconfig-paths';
-import { defineConfig } from 'vitest/config';
-
-export default defineConfig({
-  plugins: [
-    tsconfigPaths(),
-  ],
-  test: {
-    environment: 'node',
-    exclude: [
-      '**/test/**', '**/*.spec.{tsx,jsx}',
-    ],
-    clearMocks: true,
-    globals: true,
-    coverage: {
-      reportsDirectory: './coverage/unit',
-    },
-  },
-});

+ 65 - 0
apps/app/vitest.workspace.mts

@@ -0,0 +1,65 @@
+import react from '@vitejs/plugin-react';
+import tsconfigPaths from 'vite-tsconfig-paths';
+import {
+  defineConfig, defineWorkspace, mergeConfig,
+} from 'vitest/config';
+
+const configShared = defineConfig({
+  plugins: [
+    tsconfigPaths(),
+  ],
+  test: {
+    clearMocks: true,
+    globals: true,
+    exclude: [
+      'test/**',
+      'test-with-vite/**',
+      'playwright/**',
+    ]
+  },
+});
+
+export default defineWorkspace([
+
+  // unit test
+  mergeConfig(
+    configShared,
+    {
+      test: {
+        name: 'app-unit',
+        environment: 'node',
+        include: ['**/*.spec.{ts,js}'],
+      },
+    },
+  ),
+
+  // integration test
+  mergeConfig(
+    configShared,
+    {
+      test: {
+        name: 'app-integration',
+        environment: 'node',
+        include: ['**/*.integ.ts'],
+        setupFiles: [
+          './test-with-vite/setup/mongoms.ts',
+        ],
+      },
+    },
+  ),
+
+  // component test
+  mergeConfig(
+    configShared,
+    {
+      plugins: [react()],
+      test: {
+        name: 'app-components',
+        environment: 'happy-dom',
+        include: [
+          '**/*.spec.{tsx,jsx}',
+        ],
+      },
+    },
+  ),
+]);

+ 7 - 7
package.json

@@ -52,7 +52,7 @@
     "yargs": "^17.7.1"
   },
   "// comments for defDependencies": {
-    "vitest": "v1.6.0 occures an error on ci-app-test: \"ENOENT: no such file or directory, lstat '/home/runner/work/growi/growi/apps/app/coverage/.tmp'\""
+    "vite-plugin-dts": "v4.2.1 causes the unexpected error 'Cannot find package 'vue-tsc''"
   },
   "devDependencies": {
     "@changesets/changelog-github": "^0.5.0",
@@ -69,8 +69,8 @@
     "@typescript-eslint/eslint-plugin": "^5.59.7",
     "@typescript-eslint/parser": "^5.59.7",
     "@vitejs/plugin-react": "^4.3.1",
-    "@vitest/coverage-v8": "^1.6.0",
-    "@vitest/ui": "^1.6.0",
+    "@vitest/coverage-v8": "^2.1.1",
+    "@vitest/ui": "^2.1.1",
     "eslint": "^8.41.0",
     "eslint-config-next": "^12.1.6",
     "eslint-config-weseek": "^2.1.1",
@@ -100,10 +100,10 @@
     "tsconfig-paths": "^4.2.0",
     "typescript": "~5.0.0",
     "typescript-transform-paths": "^3.4.7",
-    "vite": "^5.2.14",
-    "vite-plugin-dts": "^3.8.3",
-    "vite-tsconfig-paths": "^4.3.2",
-    "vitest": "~1.6.0",
+    "vite": "^5.4.6",
+    "vite-plugin-dts": "^3.9.1",
+    "vite-tsconfig-paths": "^5.0.1",
+    "vitest": "^2.1.1",
     "vitest-mock-extended": "^1.3.1"
   },
   "engines": {

+ 81 - 0
packages/pluginkit/src/v4/utils/template.spec.ts

@@ -0,0 +1,81 @@
+import type { TemplateSummary } from '../interfaces';
+
+import { getLocalizedTemplate, extractSupportedLocales } from './template';
+
+describe('getLocalizedTemplate', () => {
+  it('should return undefined if templateSummary is undefined', () => {
+    expect(getLocalizedTemplate(undefined)).toBeUndefined();
+  });
+
+  it('should return the default template if locale is not provided', () => {
+    const templateSummary: TemplateSummary = {
+      default: {
+        id: 'templateId',
+        locale: 'en_US',
+        isValid: true,
+        isDefault: true,
+        title: 'Default Title',
+      },
+    };
+    expect(getLocalizedTemplate(templateSummary)).toEqual(templateSummary.default);
+  });
+
+  it('should return the localized template if locale is provided and exists in templateSummary', () => {
+    const templateSummary: TemplateSummary = {
+      default: {
+        id: 'templateId',
+        locale: 'en_US',
+        isValid: true,
+        isDefault: true,
+        title: 'Default Title',
+      },
+      ja_JP: {
+        id: 'templateId',
+        locale: 'ja_JP',
+        isValid: true,
+        isDefault: false,
+        title: 'Japanese Title',
+      },
+    };
+    expect(getLocalizedTemplate(templateSummary, 'ja_JP')).toEqual(templateSummary.ja_JP);
+  });
+
+  it('should return the default template if locale is provided but does not exist in templateSummary', () => {
+    const templateSummary: TemplateSummary = {
+      default: {
+        id: 'templateId',
+        locale: 'en_US',
+        isValid: true,
+        isDefault: true,
+        title: 'Default Title',
+      },
+    };
+    expect(getLocalizedTemplate(templateSummary, 'fr')).toEqual(templateSummary.default);
+  });
+});
+
+describe('extractSupportedLocales', () => {
+  it('should return undefined if templateSummary is undefined', () => {
+    expect(extractSupportedLocales(undefined)).toBeUndefined();
+  });
+
+  it('should return a set of locales from the templateSummary', () => {
+    const templateSummary: TemplateSummary = {
+      default: {
+        id: 'templateId',
+        locale: 'en_US',
+        isValid: true,
+        isDefault: true,
+        title: 'Default Title',
+      },
+      ja_JP: {
+        id: 'templateId',
+        locale: 'ja_JP',
+        isValid: true,
+        isDefault: false,
+        title: 'Japanese Title',
+      },
+    };
+    expect(extractSupportedLocales(templateSummary)).toEqual(new Set(['en_US', 'ja_JP']));
+  });
+});

+ 10 - 5
packages/pluginkit/vitest.config.ts

@@ -1,5 +1,5 @@
 import tsconfigPaths from 'vite-tsconfig-paths';
-import { defineConfig } from 'vitest/config';
+import { defineConfig, coverageConfigDefaults } from 'vitest/config';
 
 export default defineConfig({
   plugins: [
@@ -10,11 +10,16 @@ export default defineConfig({
     clearMocks: true,
     globals: true,
     coverage: {
+      exclude: [
+        ...coverageConfigDefaults.exclude,
+        'src/v4/interfaces/**',
+        'src/**/index.ts',
+      ],
       thresholds: {
-        statements: 42.78,
-        branches: 63.15,
-        lines: 42.78,
-        functions: 26.31,
+        statements: 47.59,
+        branches: 89.47,
+        lines: 47.59,
+        functions: 66.66,
       },
     },
   },

+ 2 - 0
vitest.workspace.ts → vitest.workspace.mts

@@ -1,4 +1,6 @@
 export default [
   'apps/*/vitest.config.ts',
+  'apps/*/vitest.workspace.ts',
   'packages/*/vitest.config.ts',
+  'packages/*/vitest.workspace.ts',
 ];

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 432 - 369
yarn.lock


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است