Yuki Takei hace 2 años
padre
commit
c8c849211d

+ 48 - 0
packages/preset-templates/test/index.test.ts

@@ -0,0 +1,48 @@
+import path from 'node:path';
+
+import { scanAllTemplateStatus, validateTemplatePluginPackageJson } from '@growi/pluginkit/dist/server/utils/v4';
+
+
+const projectDirRoot = path.resolve(__dirname, '../');
+
+
+it('Validation should be passed', () => {
+
+  // when
+  const caller = () => validateTemplatePluginPackageJson(projectDirRoot);
+
+  // then
+  expect(caller).not.toThrow();
+});
+
+
+describe('Scanning the template package', () => {
+
+  it('ends up with no errors', () => {
+    // when
+    const caller = () => scanAllTemplateStatus(projectDirRoot);
+
+    // then
+    expect(caller).not.toThrow();
+  });
+
+  it('successfully returns results that each template has at least one valid template', async() => {
+    // when
+    const results = await scanAllTemplateStatus(projectDirRoot);
+
+    const idValidMap: { [id: string]: boolean[] } = {};
+    results.forEach((status) => {
+      const validMap = idValidMap[status.id] ?? [];
+      validMap.push(status.isValid);
+      idValidMap[status.id] = validMap;
+    });
+
+    // then
+    expect(results.length).toBeGreaterThan(0);
+
+    Object.entries(idValidMap).forEach(([, validMap]) => {
+      expect(validMap.some(bool => bool === true)).toBeTruthy();
+    });
+  });
+
+});

+ 10 - 0
packages/preset-templates/tsconfig.json

@@ -0,0 +1,10 @@
+{
+  "$schema": "http://json.schemastore.org/tsconfig",
+  "compilerOptions": {
+    "esModuleInterop": true,
+    "resolveJsonModule": true,
+    "types": [
+      "vitest/globals"
+    ]
+  }
+}

+ 9 - 0
packages/preset-templates/vitest.config.ts

@@ -0,0 +1,9 @@
+import { defineConfig } from 'vitest/config';
+
+export default defineConfig({
+  test: {
+    environment: 'node',
+    clearMocks: true,
+    globals: true,
+  },
+});

+ 4 - 0
turbo.json

@@ -160,6 +160,10 @@
       "dependsOn": ["@growi/slack#dev"],
       "outputMode": "new-only"
     },
+    "@growi/preset-templates#test": {
+      "dependsOn": ["@growi/pluginkit#dev"],
+      "outputMode": "new-only"
+    },
     "@growi/remark-lsx#test": {
       "dependsOn": ["@growi/core#dev"],
       "outputMode": "new-only"