yohei0125 4 ani în urmă
părinte
comite
f7923eba8b

+ 20 - 1
packages/app/jest.config.js

@@ -37,13 +37,32 @@ module.exports = {
 
 
       rootDir: '.',
       rootDir: '.',
       roots: ['<rootDir>'],
       roots: ['<rootDir>'],
-      testMatch: ['<rootDir>/test/integration/**/*.test.ts', '<rootDir>/test/integration/**/*.test.js'],
+      testMatch: ['<rootDir>/test/integration/**/*.test.ts', '<rootDir>/test/integration/**/*.test.js',
+                  '!<rootDir>/test/integration/service/pagev5.test.ts', '!<rootDir>/test/integration/service/pagev5.test.js'],
 
 
       testEnvironment: 'node',
       testEnvironment: 'node',
       globalSetup: '<rootDir>/test/integration/global-setup.js',
       globalSetup: '<rootDir>/test/integration/global-setup.js',
       globalTeardown: '<rootDir>/test/integration/global-teardown.js',
       globalTeardown: '<rootDir>/test/integration/global-teardown.js',
       setupFilesAfterEnv: ['<rootDir>/test/integration/setup.js'],
       setupFilesAfterEnv: ['<rootDir>/test/integration/setup.js'],
 
 
+      // Automatically clear mock calls and instances between every test
+      clearMocks: true,
+      moduleNameMapper: MODULE_NAME_MAPPING,
+    },
+    {
+      displayName: 'v5-page-service',
+
+      preset: 'ts-jest/presets/js-with-ts',
+
+      rootDir: '.',
+      roots: ['<rootDir>'],
+      testMatch: ['<rootDir>/test/integration/service/pagev5.test.ts', '<rootDir>/test/integration/service/pagev5.test.js'],
+
+      testEnvironment: 'node',
+      globalSetup: '<rootDir>/test/integration/v5-page-global-setup.js',
+      globalTeardown: '<rootDir>/test/integration/global-teardown.js',
+      setupFilesAfterEnv: ['<rootDir>/test/integration/v5-page-setup.js'],
+
       // Automatically clear mock calls and instances between every test
       // Automatically clear mock calls and instances between every test
       clearMocks: true,
       clearMocks: true,
       moduleNameMapper: MODULE_NAME_MAPPING,
       moduleNameMapper: MODULE_NAME_MAPPING,

+ 6 - 1
packages/app/test/integration/service/v5-migration.test.js

@@ -26,7 +26,7 @@ describe('V5 page migration', () => {
       jest.restoreAllMocks();
       jest.restoreAllMocks();
 
 
       // initialize pages for test
       // initialize pages for test
-      const pages = await Page.insertMany([
+      let pages = await Page.insertMany([
         {
         {
           path: '/private1',
           path: '/private1',
           grant: Page.GRANT_OWNER,
           grant: Page.GRANT_OWNER,
@@ -57,6 +57,11 @@ describe('V5 page migration', () => {
         },
         },
       ]);
       ]);
 
 
+      if (!await Page.exists({ path: '/' })) {
+        const additionalPages = await Page.insertMany([{ path: '/', grant: Page.GRANT_PUBLIC }]);
+        pages = [...additionalPages, ...pages];
+      }
+
       const pageIds = pages.map(page => page._id);
       const pageIds = pages.map(page => page._id);
       // migrate
       // migrate
       await crowi.pageService.normalizeParentRecursivelyByPageIds(pageIds, testUser1);
       await crowi.pageService.normalizeParentRecursivelyByPageIds(pageIds, testUser1);

+ 37 - 0
packages/app/test/integration/v5-page-global-setup.js

@@ -0,0 +1,37 @@
+/** **********************************************************
+ *                           Caution
+ *
+ * Module aliases by compilerOptions.paths in tsconfig.json
+ * are NOT available in setup scripts
+ *********************************************************** */
+
+import 'tsconfig-paths/register';
+
+import mongoose from 'mongoose';
+
+import { initMongooseGlobalSettings, getMongoUri, mongoOptions } from '@growi/core';
+
+// check env
+if (process.env.NODE_ENV !== 'test') {
+  throw new Error('\'process.env.NODE_ENV\' must be \'test\'');
+}
+
+
+// eslint-disable-next-line @typescript-eslint/no-var-requires
+// const { getInstance } = require('./setup-crowi');
+
+module.exports = async() => {
+  initMongooseGlobalSettings();
+  process.env.MONGO_URI = 'mongodb://mongo/growi_pagev5_test';
+  await mongoose.connect(getMongoUri(), mongoOptions);
+
+  // drop database
+  await mongoose.connection.dropDatabase();
+
+  // init DB
+  // const crowi = await getInstance();
+  // const appService = crowi.appService;
+  // await appService.initDB();
+
+  await mongoose.disconnect();
+};

+ 26 - 0
packages/app/test/integration/v5-page-setup.js

@@ -0,0 +1,26 @@
+/** **********************************************************
+ *                           Caution
+ *
+ * Module aliases by compilerOptions.paths in tsconfig.json
+ * are NOT available in setup scripts
+ *********************************************************** */
+
+const mongoose = require('mongoose');
+
+const { initMongooseGlobalSettings, getMongoUri, mongoOptions } = require('@growi/core');
+
+mongoose.Promise = global.Promise;
+
+jest.setTimeout(30000); // default 5000
+
+beforeAll(async() => {
+  initMongooseGlobalSettings();
+  process.env.MONGO_URI = 'mongodb://mongo/growi_pagev5_test';
+  await mongoose.connect(getMongoUri(), mongoOptions);
+});
+
+afterAll(async() => {
+  await mongoose.disconnect();
+});
+
+module.exports = {};