Skip to content

Commit

Permalink
chore: Test multiple DBs in CI e2e tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
michaelbromley authored Jan 29, 2020
1 parent 25a03e6 commit c62f2b7
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 66 deletions.
96 changes: 70 additions & 26 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 8 additions & 0 deletions e2e-common/custom-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class MyCustomReporter {
onRunComplete(contexts, results) {
const dbType = process.env.DB || 'sqljs';
console.log(`Database engine: ${dbType}`);
}
}

module.exports = MyCustomReporter;
3 changes: 1 addition & 2 deletions e2e-common/e2e-initial-data.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
25 changes: 13 additions & 12 deletions e2e-common/jest-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
};
6 changes: 3 additions & 3 deletions e2e-common/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ 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',
};
case 'mysql':
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: '',
};
Expand Down
3 changes: 2 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/e2e/custom-fields.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const customConfig = mergeConfig(testConfig, {
{
name: 'longString',
type: 'string',
length: 60000,
length: 10000,
},
{
name: 'readonlyString',
Expand Down Expand Up @@ -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!) {
Expand Down
15 changes: 7 additions & 8 deletions packages/core/e2e/entity-uuid-strategy.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 5 additions & 6 deletions packages/core/e2e/fixtures/test-plugins.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
],
}),
Expand Down
3 changes: 2 additions & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c62f2b7

Please sign in to comment.