Yuki Takei 1 год назад
Родитель
Сommit
0296a8b899

+ 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"
+      }
+    ]
+  }
+}