Pārlūkot izejas kodu

chore: Test multiple DBs in CI e2e tests

Closes #207 

* chore: Attempt multi DB CI setup

* chore: Add postgres test

* chore: Add postgres test fix

* chore: Add elasticsearch test

* chore: Fix yaml formatting

* chore: Fix yaml formatting again

* chore: Wip update build and test workflow

* chore(core): Configure GH workflow for multiple dbs

* chore(core): Re-enable build workflow

* chore(core): Fix yaml

* chore(core): Fix yaml again

* chore(core): Fix yaml again

* chore(core): Fixage

* chore(core): Fix mysql host

* test(core): Fix custom fields e2e test for mariaDB 10.3

* chore(test): Remove direct imports from TS source files

May improve e2e test times?

* test(elasticsearch-plugin): Use http protocol in CI
Michael Bromley 6 gadi atpakaļ
vecāks
revīzija
c62f2b7d0b

+ 70 - 26
.github/workflows/build_and_test.yml

@@ -8,41 +8,85 @@ on:
     branches:
     - master
 
+env:
+  CI: true
+  node: 12.x
 jobs:
   build:
-
+    name: build
     runs-on: ubuntu-latest
-
-    strategy:
-      matrix:
-        node-version: [10.x, 12.x]
-
-    env:
-      CI: true
-
     steps:
     - uses: actions/checkout@v1
-    - name: Use Node.js ${{ matrix.node-version }}
+    - name: Use Node.js ${{ env.node }}
       uses: actions/setup-node@v1
       with:
-        node-version: ${{ matrix.node-version }}
-    # This is required for the elasticsearch-plugin e2e tests. It would be better to use the
-    # "services" feature, but I cannot figure out how to connect to it from the test server.
-    - name: Install elasticsearch
-      run: |
-        curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz
-        tar -xvf elasticsearch-7.4.2-linux-x86_64.tar.gz
-        cd elasticsearch-7.4.2/bin
-        ./elasticsearch &
+        node-version: ${{ env.node }}
     - name: Install & build
       run: |
         yarn install
         yarn bootstrap
         yarn build
-    - name: Unit tests
-      run: yarn test
-    - name: e2e tests
-      env:
-        ELASTICSEARCH_PORT: 9200
-        ELASTICSEARCH_HOST: http://localhost
-      run: yarn e2e
+  unit-tests:
+    name: unit tests
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v1
+      - name: Use Node.js ${{ env.node }}
+        uses: actions/setup-node@v1
+        with:
+          node-version: ${{ env.node }}
+      - name: Install & build
+        run: |
+          yarn install
+          yarn bootstrap
+          yarn lerna run ci
+      - name: Unit tests
+        run: yarn test
+  e2e-tests:
+    name: e2e tests
+    runs-on: ubuntu-latest
+    services:
+      mysql:
+        image: bitnami/mariadb:10.3
+        env:
+          ALLOW_EMPTY_PASSWORD: yes
+        ports:
+          - 3306
+        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
+      postgres:
+        image: postgres:12
+        env:
+          POSTGRES_PASSWORD: Be70
+        ports:
+          - 5432
+        options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
+      elastic:
+        image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
+        env:
+          discovery.type: single-node
+          bootstrap.memory_lock: true
+          ES_JAVA_OPTS: -Xms512m -Xmx512m
+        ports:
+          - 9200
+        options: --health-cmd="curl --silent --fail localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=3
+    strategy:
+      matrix:
+        db: [sqljs, mysql, postgres]
+    steps:
+      - uses: actions/checkout@v1
+      - name: Use Node.js ${{ env.node }}
+        uses: actions/setup-node@v1
+        with:
+          node-version: ${{ env.node }}
+      - name: Install & build
+        run: |
+          yarn install
+          yarn bootstrap
+          yarn lerna run ci
+      - name: e2e tests
+        env:
+          E2E_MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
+          E2E_POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }}
+          E2E_ELASTIC_PORT: ${{ job.services.elastic.ports['9200'] }}
+          DB: ${{ matrix.db }}
+        run: yarn e2e

+ 8 - 0
e2e-common/custom-reporter.js

@@ -0,0 +1,8 @@
+class MyCustomReporter {
+    onRunComplete(contexts, results) {
+        const dbType = process.env.DB || 'sqljs';
+        console.log(`Database engine: ${dbType}`);
+    }
+}
+
+module.exports = MyCustomReporter;

+ 1 - 2
e2e-common/e2e-initial-data.ts

@@ -1,6 +1,5 @@
 import { LanguageCode } from '@vendure/common/lib/generated-types';
-
-import { InitialData } from '../packages/core/src/data-import/index';
+import { InitialData } from '@vendure/core/dist/data-import/index';
 
 export const initialData: InitialData = {
     defaultLanguage: LanguageCode.en,

+ 13 - 12
e2e-common/jest-config.js

@@ -4,17 +4,18 @@ const { getPackageDir } = require('./get-package-dir');
 const packageDirname = getPackageDir();
 
 module.exports = {
-  'moduleFileExtensions': ['js', 'json', 'ts'],
-  'rootDir': packageDirname,
-  'testRegex': '.e2e-spec.ts$',
-  'transform': {
-    '^.+\\.(t|j)s$': 'ts-jest',
-  },
-  'testEnvironment': 'node',
-  'globals': {
-    'ts-jest': {
-      'tsConfig': '<rootDir>/config/tsconfig.e2e.json',
-      'diagnostics': false,
+    moduleFileExtensions: ['js', 'json', 'ts'],
+    rootDir: packageDirname,
+    testRegex: '.e2e-spec.ts$',
+    transform: {
+        '^.+\\.(t|j)s$': 'ts-jest',
+    },
+    testEnvironment: 'node',
+    reporters: ['default', path.join(__dirname, 'custom-reporter.js')],
+    globals: {
+        'ts-jest': {
+            tsConfig: '<rootDir>/config/tsconfig.e2e.json',
+            diagnostics: false,
+        },
     },
-  },
 };

+ 3 - 3
e2e-common/test-config.ts

@@ -43,7 +43,7 @@ function getDbConfig(): ConnectionOptions {
                 synchronize: true,
                 type: 'postgres',
                 host: '127.0.0.1',
-                port: 5432,
+                port: process.env.CI ? +(process.env.E2E_POSTGRES_PORT || 5432) : 5432,
                 username: 'postgres',
                 password: 'Be70',
             };
@@ -51,8 +51,8 @@ function getDbConfig(): ConnectionOptions {
             return {
                 synchronize: true,
                 type: 'mysql',
-                host: '192.168.99.100',
-                port: 3306,
+                host: process.env.CI ? '127.0.0.1' : '192.168.99.100',
+                port: process.env.CI ? +(process.env.E2E_MYSQL_PORT || 3306) : 3306,
                 username: 'root',
                 password: '',
             };

+ 2 - 1
packages/common/package.json

@@ -7,7 +7,8 @@
     "watch": "tsc -p ./tsconfig.build.json -w",
     "build": "rimraf dist && tsc -p ./tsconfig.build.json",
     "lint": "tslint --fix --project ./",
-    "test": "jest --config ./jest.config.js"
+    "test": "jest --config ./jest.config.js",
+    "ci": "yarn build"
   },
   "publishConfig": {
     "access": "public"

+ 2 - 2
packages/core/e2e/custom-fields.e2e-spec.ts

@@ -92,7 +92,7 @@ const customConfig = mergeConfig(testConfig, {
             {
                 name: 'longString',
                 type: 'string',
-                length: 60000,
+                length: 10000,
             },
             {
                 name: 'readonlyString',
@@ -317,7 +317,7 @@ describe('Custom fields', () => {
     );
 
     it('string length allows long strings', async () => {
-        const longString = Array.from({ length: 4000 }, v => 'hello there!').join(' ');
+        const longString = Array.from({ length: 500 }, v => 'hello there!').join(' ');
         const result = await adminClient.query(
             gql`
                 mutation($stringValue: String!) {

+ 7 - 8
packages/core/e2e/entity-uuid-strategy.e2e-spec.ts

@@ -1,22 +1,21 @@
 /* tslint:disable:no-non-null-assertion */
 import { UuidIdStrategy } from '@vendure/core';
+// This import is here to simulate the behaviour of
+// the package end-user importing symbols from the
+// @vendure/core barrel file. Doing so will then cause the
+// recursive evaluation of all imported files. This tests
+// the resilience of the id strategy implementation to the
+// order of file evaluation.
+import '@vendure/core/dist/index';
 import { createTestEnvironment } from '@vendure/testing';
 import path from 'path';
 
 import { initialData } from '../../../e2e-common/e2e-initial-data';
 import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
-import '../src/index';
 
 import { GetProductList } from './graphql/generated-e2e-admin-types';
 import { GET_PRODUCT_LIST } from './graphql/shared-definitions';
 
-// This import is here to simulate the behaviour of
-// the package end-user importing symbols from the
-// @vendure/core barrel file. Doing so will then cause the
-// recusrsive evaluation of all imported files. This tests
-// the resilience of the id strategy implementation to the
-// order of file evaluation.
-
 describe('UuidIdStrategy', () => {
     const { server, adminClient } = createTestEnvironment({
         ...testConfig,

+ 5 - 6
packages/core/e2e/fixtures/test-plugins.ts

@@ -1,18 +1,17 @@
 import { Injectable, OnApplicationBootstrap, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
 import { Query, Resolver } from '@nestjs/graphql';
 import { LanguageCode } from '@vendure/common/lib/generated-types';
-import gql from 'graphql-tag';
-
-import { VendureConfig } from '../../src/config';
-import { ConfigModule } from '../../src/config/config.module';
-import { ConfigService } from '../../src/config/config.service';
 import {
+    ConfigService,
     OnVendureBootstrap,
     OnVendureClose,
     OnVendureWorkerBootstrap,
     OnVendureWorkerClose,
+    VendureConfig,
     VendurePlugin,
-} from '../../src/plugin/vendure-plugin';
+} from '@vendure/core';
+import { ConfigModule } from '@vendure/core/dist/config/config.module';
+import gql from 'graphql-tag';
 
 export class TestPluginWithAllLifecycleHooks
     implements OnVendureBootstrap, OnVendureWorkerBootstrap, OnVendureClose, OnVendureWorkerClose {

+ 2 - 1
packages/core/package.json

@@ -22,7 +22,8 @@
     "watch": "concurrently yarn:tsc:watch yarn:gulp:watch",
     "lint": "tslint --fix --project ./",
     "test": "jest --config ./jest.config.js",
-    "e2e": "jest --config ../../e2e-common/jest-config.js --runInBand --package=core"
+    "e2e": "jest --config ../../e2e-common/jest-config.js --runInBand --package=core",
+    "ci": "yarn build"
   },
   "publishConfig": {
     "access": "public"

+ 2 - 4
packages/elasticsearch-plugin/e2e/elasticsearch-plugin.e2e-spec.ts

@@ -53,10 +53,8 @@ describe('Elasticsearch plugin', () => {
             plugins: [
                 ElasticsearchPlugin.init({
                     indexPrefix: 'e2e-tests',
-                    port: process.env.CI ? +(process.env.ELASTICSEARCH_PORT || 9200) : 9200,
-                    host: process.env.CI
-                        ? process.env.ELASTICSEARCH_HOST || 'elasticsearch'
-                        : 'http://192.168.99.100',
+                    port: process.env.CI ? +(process.env.E2E_ELASTIC_PORT || 9200) : 9200,
+                    host: process.env.CI ? 'http://127.0.0.1' : 'http://192.168.99.100',
                 }),
             ],
         }),

+ 2 - 1
packages/testing/package.json

@@ -25,7 +25,8 @@
   "scripts": {
     "build": "tsc -p ./tsconfig.build.json",
     "watch": "tsc -p ./tsconfig.build.json -w",
-    "lint": "tslint --fix --project ./"
+    "lint": "tslint --fix --project ./",
+    "ci": "yarn build"
   },
   "bugs": {
     "url": "https://github.com/vendure-ecommerce/vendure/issues"