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

refactor initializing crowi instance for test

Yuki Takei 4 лет назад
Родитель
Сommit
3d3775a987
2 измененных файлов с 23 добавлено и 43 удалено
  1. 0 41
      packages/app/src/server/crowi/index.js
  2. 23 2
      packages/app/test/integration/setup-crowi.js

+ 0 - 41
packages/app/src/server/crowi/index.js

@@ -142,47 +142,6 @@ Crowi.prototype.init = async function() {
   ]);
 };
 
-Crowi.prototype.initForTest = async function() {
-  await this.setupModels();
-  await this.setupConfigManager();
-
-  // setup messaging services
-  await this.setupSocketIoService();
-
-  // // customizeService depends on AppService and XssService
-  // // passportService depends on appService
-  await Promise.all([
-    this.setUpApp(),
-    this.setUpXss(),
-    // this.setUpGrowiBridge(),
-  ]);
-
-  await Promise.all([
-    // this.scanRuntimeVersions(),
-    this.setupPassport(),
-    // this.setupSearcher(),
-    // this.setupMailer(),
-    // this.setupSlackIntegrationService(),
-    // this.setupCsrf(),
-    // this.setUpFileUpload(),
-    this.setupAttachmentService(),
-    this.setUpAcl(),
-    // this.setUpCustomize(),
-    // this.setUpRestQiitaAPI(),
-    // this.setupUserGroup(),
-    // this.setupExport(),
-    // this.setupImport(),
-    this.setupPageService(),
-    this.setupInAppNotificationService(),
-    this.setupActivityService(),
-  ]);
-
-  // globalNotification depends on slack and mailer
-  // await Promise.all([
-  //   this.setUpGlobalNotification(),
-  // ]);
-};
-
 Crowi.prototype.isPageId = function(pageId) {
   if (!pageId) {
     return false;

+ 23 - 2
packages/app/test/integration/setup-crowi.js

@@ -2,17 +2,38 @@ import Crowi from '~/server/crowi';
 
 let _instance = null;
 
+const initCrowi = async(crowi) => {
+  await crowi.setupModels();
+  await crowi.setupConfigManager();
+
+  await crowi.setupSocketIoService();
+
+  await Promise.all([
+    crowi.setUpApp(),
+    crowi.setUpXss(),
+  ]);
+
+  await Promise.all([
+    crowi.setupPassport(),
+    crowi.setupAttachmentService(),
+    crowi.setUpAcl(),
+    crowi.setupPageService(),
+    crowi.setupInAppNotificationService(),
+    crowi.setupActivityService(),
+  ]);
+};
+
 export async function getInstance(isNewInstance) {
   if (isNewInstance) {
     const crowi = new Crowi();
-    await crowi.initForTest();
+    await initCrowi(crowi);
     return crowi;
   }
 
   // initialize singleton instance
   if (_instance == null) {
     _instance = new Crowi();
-    await _instance.initForTest();
+    await initCrowi(_instance);
   }
   return _instance;
 }