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

Separated ci stage for v4 & v5 test

Taichi Masuyama 4 лет назад
Родитель
Сommit
853a549ad4

+ 45 - 3
.github/workflows/ci-app.yml

@@ -98,10 +98,52 @@ jobs:
     - name: yarn test
     - name: yarn test
       working-directory: ./packages/app
       working-directory: ./packages/app
       run: |
       run: |
-        yarn test
+        yarn test --selectProjects unit server
       env:
       env:
-        MONGO_URI_TEST_V4: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi_test
-        MONGO_URI_TEST_V5: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi_test_v5
+        MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi_test
+
+  test-v5-compatible:
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        node-version: [16.x]
+
+    services:
+      mongodb:
+        image: mongo:4.4
+        ports:
+        - 27017/tcp
+
+    steps:
+    - uses: actions/checkout@v2
+
+    - uses: actions/setup-node@v2
+      with:
+        node-version: ${{ matrix.node-version }}
+        cache: 'yarn'
+        cache-dependency-path: '**/yarn.lock'
+
+    - name: Cache/Restore node_modules
+      id: cache-dependencies
+      uses: actions/cache@v2
+      with:
+        path: |
+          **/node_modules
+        key: node_modules-${{ runner.OS }}-node${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
+        restore-keys: |
+          node_modules-${{ runner.OS }}-node${{ matrix.node-version }}-
+
+    - name: lerna bootstrap
+      run: |
+        npx lerna bootstrap -- --frozen-lockfile
+
+    - name: yarn test
+      working-directory: ./packages/app
+      run: |
+        yarn test --selectProjects server-v5
+      env:
+        MONGO_URI: mongodb://localhost:${{ job.services.mongodb.ports['27017'] }}/growi_test_v5
 
 
     - name: Upload coverage report as artifact
     - name: Upload coverage report as artifact
       uses: actions/upload-artifact@v2
       uses: actions/upload-artifact@v2

+ 2 - 2
packages/app/jest.config.js

@@ -38,7 +38,7 @@ 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/v5.*.test.ts', '?!<rootDir>/test/integration/service/v5.*.test.js'],
+                  '?!<rootDir>/test/integration/**/v5.*.test.ts', '?!<rootDir>/test/integration/**/v5.*.test.js'],
 
 
       testEnvironment: 'node',
       testEnvironment: 'node',
       globalSetup: '<rootDir>/test/integration/global-setup.js',
       globalSetup: '<rootDir>/test/integration/global-setup.js',
@@ -56,7 +56,7 @@ module.exports = {
 
 
       rootDir: '.',
       rootDir: '.',
       roots: ['<rootDir>'],
       roots: ['<rootDir>'],
-      testMatch: ['<rootDir>/test/integration/service/v5.*.test.ts', '<rootDir>/test/integration/service/v5.*.test.js'],
+      testMatch: ['<rootDir>/test/integration/**/v5.*.test.ts', '<rootDir>/test/integration/**/v5.*.test.js'],
 
 
       testEnvironment: 'node',
       testEnvironment: 'node',
       globalSetup: '<rootDir>/test/integration/v5-global-setup.js',
       globalSetup: '<rootDir>/test/integration/v5-global-setup.js',

+ 2 - 1
packages/app/package.json

@@ -37,7 +37,8 @@
     "lint:styles": "stylelint src/**/*.scss",
     "lint:styles": "stylelint src/**/*.scss",
     "lint:swagger2openapi": "node node_modules/.bin/oas-validate tmp/swagger.json",
     "lint:swagger2openapi": "node node_modules/.bin/oas-validate tmp/swagger.json",
     "lint": "run-p lint:*",
     "lint": "run-p lint:*",
-    "test": "cross-env NODE_ENV=test jest --passWithNoTests -- ",
+    "test": "cross-env NODE_ENV=test jest --selectProjects unit server --passWithNoTests -- ",
+    "test-v5": "cross-env NODE_ENV=test jest --selectProjects server-v5 --passWithNoTests -- ",
     "prelint:eslint": "yarn resources:plugin",
     "prelint:eslint": "yarn resources:plugin",
     "prelint:swagger2openapi": "yarn openapi:v3",
     "prelint:swagger2openapi": "yarn openapi:v3",
     "reg:run": "reg-suit run",
     "reg:run": "reg-suit run",

+ 2 - 2
packages/app/test/integration/global-setup.js

@@ -9,7 +9,7 @@ import 'tsconfig-paths/register';
 
 
 import mongoose from 'mongoose';
 import mongoose from 'mongoose';
 
 
-import { initMongooseGlobalSettings, getMongoUriForTestV4, mongoOptions } from '@growi/core';
+import { initMongooseGlobalSettings, getMongoUri, mongoOptions } from '@growi/core';
 
 
 // check env
 // check env
 if (process.env.NODE_ENV !== 'test') {
 if (process.env.NODE_ENV !== 'test') {
@@ -19,7 +19,7 @@ if (process.env.NODE_ENV !== 'test') {
 module.exports = async() => {
 module.exports = async() => {
   initMongooseGlobalSettings();
   initMongooseGlobalSettings();
 
 
-  mongoose.connect(getMongoUriForTestV4(), mongoOptions);
+  mongoose.connect(getMongoUri(), mongoOptions);
 
 
   // drop database
   // drop database
   await mongoose.connection.dropDatabase();
   await mongoose.connection.dropDatabase();

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

@@ -7,7 +7,7 @@
 
 
 const mongoose = require('mongoose');
 const mongoose = require('mongoose');
 
 
-const { initMongooseGlobalSettings, getMongoUriForTestV4, mongoOptions } = require('@growi/core');
+const { initMongooseGlobalSettings, getMongoUri, mongoOptions } = require('@growi/core');
 
 
 mongoose.Promise = global.Promise;
 mongoose.Promise = global.Promise;
 
 
@@ -15,7 +15,7 @@ jest.setTimeout(30000); // default 5000
 
 
 beforeAll(async() => {
 beforeAll(async() => {
   initMongooseGlobalSettings();
   initMongooseGlobalSettings();
-  await mongoose.connect(getMongoUriForTestV4(), mongoOptions);
+  await mongoose.connect(getMongoUri(), mongoOptions);
 });
 });
 
 
 afterAll(async() => {
 afterAll(async() => {

+ 2 - 2
packages/app/test/integration/v5-global-setup.js

@@ -9,7 +9,7 @@ import 'tsconfig-paths/register';
 
 
 import mongoose from 'mongoose';
 import mongoose from 'mongoose';
 
 
-import { initMongooseGlobalSettings, getMongoUriForTestV5, mongoOptions } from '@growi/core';
+import { initMongooseGlobalSettings, getMongoUri, mongoOptions } from '@growi/core';
 
 
 // check env
 // check env
 if (process.env.NODE_ENV !== 'test') {
 if (process.env.NODE_ENV !== 'test') {
@@ -18,7 +18,7 @@ if (process.env.NODE_ENV !== 'test') {
 
 
 module.exports = async() => {
 module.exports = async() => {
   initMongooseGlobalSettings();
   initMongooseGlobalSettings();
-  mongoose.connect(getMongoUriForTestV5(), mongoOptions);
+  mongoose.connect(getMongoUri(), mongoOptions);
 
 
   // drop database
   // drop database
   await mongoose.connection.dropDatabase();
   await mongoose.connection.dropDatabase();

+ 2 - 2
packages/app/test/integration/v5-setup.js

@@ -7,7 +7,7 @@
 
 
 const mongoose = require('mongoose');
 const mongoose = require('mongoose');
 
 
-const { initMongooseGlobalSettings, getMongoUriForTestV5, mongoOptions } = require('@growi/core');
+const { initMongooseGlobalSettings, getMongoUri, mongoOptions } = require('@growi/core');
 
 
 mongoose.Promise = global.Promise;
 mongoose.Promise = global.Promise;
 
 
@@ -15,7 +15,7 @@ jest.setTimeout(30000); // default 5000
 
 
 beforeAll(async() => {
 beforeAll(async() => {
   initMongooseGlobalSettings();
   initMongooseGlobalSettings();
-  await mongoose.connect(getMongoUriForTestV5(), mongoOptions);
+  await mongoose.connect(getMongoUri(), mongoOptions);
 });
 });
 
 
 afterAll(async() => {
 afterAll(async() => {

+ 0 - 8
packages/core/src/utils/mongoose-utils.ts

@@ -21,14 +21,6 @@ export const getMongoUri = (): string => {
     || ((env.NODE_ENV === 'test') ? 'mongodb://mongo/growi_test' : 'mongodb://mongo/growi');
     || ((env.NODE_ENV === 'test') ? 'mongodb://mongo/growi_test' : 'mongodb://mongo/growi');
 };
 };
 
 
-export const getMongoUriForTestV4 = (): string => {
-  return process.env.MONGO_URI_TEST_V4 || 'mongodb://mongo/growi_test';
-};
-
-export const getMongoUriForTestV5 = (): string => {
-  return process.env.MONGO_URI_TEST_V5 || 'mongodb://mongo/growi_test_v5';
-};
-
 export const getModelSafely = <T>(modelName: string): Model<T & Document> | null => {
 export const getModelSafely = <T>(modelName: string): Model<T & Document> | null => {
   if (mongoose.modelNames().includes(modelName)) {
   if (mongoose.modelNames().includes(modelName)) {
     return mongoose.model<T & Document>(modelName);
     return mongoose.model<T & Document>(modelName);