Просмотр исходного кода

Merge pull request #8854 from weseek/support/add-test-for-pluginkit

support: Add test for pluginkit
Yuki Takei 1 год назад
Родитель
Сommit
327a01edf6

+ 5 - 0
.changeset/blue-tips-joke.md

@@ -0,0 +1,5 @@
+---
+"@growi/pluginkit": patch
+---
+
+support: Add test for pluginkit

+ 1 - 1
packages/pluginkit/src/v4/server/utils/common/validate-growi-plugin-directive.ts

@@ -1,4 +1,4 @@
-import { GrowiPluginType } from '@growi/core';
+import type { GrowiPluginType } from '@growi/core';
 
 import { type GrowiPluginValidationData, GrowiPluginValidationError } from '../../../../model';
 

+ 39 - 0
packages/pluginkit/src/v4/server/utils/template/validate-growi-plugin-directive.spec.ts

@@ -0,0 +1,39 @@
+import path from 'path';
+
+import { GrowiPluginType } from '@growi/core';
+
+import { validateTemplatePluginGrowiDirective } from './validate-growi-plugin-directive';
+
+
+describe('validateTemplatePluginGrowiDirective()', () => {
+
+  it('returns a data object', async() => {
+    // setup
+    const projectDirRoot = path.resolve(__dirname, '../../../../../test/fixtures/example-package/template1');
+
+    // when
+    const data = validateTemplatePluginGrowiDirective(projectDirRoot);
+
+    // then
+    expect(data).not.toBeNull();
+    expect(data.growiPlugin).not.toBeNull();
+    expect(data.growiPlugin.types).toStrictEqual([GrowiPluginType.Template]);
+    expect(data.growiPlugin.tylocalespes).not.toBeNull();
+  });
+
+  describe('should throw an GrowiPluginValidationError', () => {
+
+    it("when the pkg does not have 'growiPlugin.locale' directive", () => {
+      // setup
+      const projectDirRoot = path.resolve(__dirname, '../../../../../test/fixtures/example-package/invalid-template1');
+
+      // when
+      const caller = () => { validateTemplatePluginGrowiDirective(projectDirRoot) };
+
+      // then
+      expect(caller).toThrow("Template plugin must have 'supportingLocales' and that must have one or more locales");
+    });
+
+  });
+
+});

+ 0 - 0
packages/pluginkit/test/fixtures/example-package/invalid-template1/index.js


+ 11 - 0
packages/pluginkit/test/fixtures/example-package/invalid-template1/package.json

@@ -0,0 +1,11 @@
+{
+  "name": "example-package-invalid-template1",
+  "version": "1.0.0",
+  "main": "index.js",
+  "growiPlugin": {
+    "schemaVersion": "4",
+    "types": [
+      "template"
+    ]
+  }
+}

+ 0 - 0
packages/pluginkit/test/fixtures/example-package/theme1/index.js


+ 23 - 0
packages/pluginkit/test/fixtures/example-package/theme1/package.json

@@ -0,0 +1,23 @@
+{
+  "name": "example-package-theme1",
+  "version": "1.0.0",
+  "main": "index.js",
+  "growiPlugin": {
+    "schemaVersion": "4",
+    "types": ["theme"],
+    "themes": [
+      {
+        "name": "theme1",
+        "manifestKey": "src/styles/style.scss",
+        "schemeType": "light",
+        "lightBg": "#ff0000",
+        "darkBg": "#0000ff",
+        "lightSidebar": "#ffff00",
+        "darkSidebar": "#ff8800",
+        "lightIcon": "#ff0000",
+        "darkIcon": "#000000",
+        "createBtn": "#00ff00"
+      }
+    ]
+  }
+}

+ 1 - 0
packages/preset-themes/package.json

@@ -29,6 +29,7 @@
   },
   "dependencies": {},
   "devDependencies": {
+    "@growi/core": "link:../../packages/core",
     "@growi/core-styles": "link:../../packages/core-styles",
     "bootstrap": "=5.3.2",
     "sass": "^1.55.0"

+ 2 - 1
packages/preset-themes/src/consts/preset-themes.ts

@@ -1,4 +1,5 @@
-import { GrowiThemeMetadata, GrowiThemeSchemeType } from '../interfaces/growi-theme-metadata';
+import type { GrowiThemeMetadata } from '@growi/core';
+import { GrowiThemeSchemeType } from '@growi/core';
 
 const { BOTH, LIGHT, DARK } = GrowiThemeSchemeType;
 

+ 0 - 20
packages/preset-themes/src/interfaces/growi-theme-metadata.ts

@@ -1,20 +0,0 @@
-export const GrowiThemeSchemeType = {
-  BOTH: 'both',
-  LIGHT: 'light',
-  DARK: 'dark',
-} as const;
-export type GrowiThemeSchemeType = typeof GrowiThemeSchemeType[keyof typeof GrowiThemeSchemeType];
-
-export type GrowiThemeMetadata = {
-  name: string,
-  manifestKey: string,
-  schemeType: GrowiThemeSchemeType,
-  lightBg: string,
-  darkBg: string,
-  lightSidebar: string,
-  darkSidebar: string,
-  lightIcon: string,
-  darkIcon: string,
-  createBtn: string,
-  isPresetTheme?: boolean,
-};