From 3ea50ab69a0a53a8d75fa5f488cf1f91f369a670 Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:19:02 +0545 Subject: [PATCH 01/13] docs: add workflow test badge in README.md and add e2e test command on workflow --- .github/workflows/test.yml | 5 ++++- README.md | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 109ff7c..3506fdd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,4 +48,7 @@ jobs: run: npm run lint - name: Run unit test - run: npm run test:unit \ No newline at end of file + run: npm run test:unit + + - name: Run e2e test + run: npm run test:e2e \ No newline at end of file diff --git a/README.md b/README.md index eba4fa7..bdbfdf0 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@

GitHub package.json version +Workflow test GitHub Lines of code Open Source Helpers From 5855a90ff3ef5d30206351966ce88fe90f53c602 Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:26:55 +0545 Subject: [PATCH 02/13] fix: update env variable for test db in github flow --- .github/workflows/test.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3506fdd..2eb6fa6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,11 +35,12 @@ jobs: uses: allenevans/set-env@v2.0.0 with: NODE_ENV: test - DATABASE_HOST: 127.0.0.1 - DATABASE_PORT: ${{ job.services.postgres.ports[5432] }} - DATABASE_NAME: truthy_db - DATABASE_USER: truthy_user - DATABASE_PASSWORD: truthypwd + DB_TYPE: postgres + DB_HOST: 127.0.0.1 + DB_PORT: ${{ job.services.postgres.ports[5432] }} + DB_DATABASE_NAME: truthy_db + DB_USERNAME: truthy_user + DB_PASSWORD: truthypwd - name: Install dependencies run: npm install From cc48d17f63d4a02a7b4271bde4ff9bea5f478fef Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:42:02 +0545 Subject: [PATCH 03/13] fix: update github action to include environment variable --- .github/actions/setvars/action.yml | 13 +++++++++++++ .github/actions/variables/myvars.env | 7 +++++++ .github/workflows/test.yml | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 .github/actions/setvars/action.yml create mode 100644 .github/actions/variables/myvars.env diff --git a/.github/actions/setvars/action.yml b/.github/actions/setvars/action.yml new file mode 100644 index 0000000..f10cf98 --- /dev/null +++ b/.github/actions/setvars/action.yml @@ -0,0 +1,13 @@ +name: 'Set environment variables' +description: 'Configures environment variables for a workflow' +inputs: + varFilePath: + description: 'File path to variable file or directory. Defaults to ./.github/variables/* if none specified and runs against each file in that directory.' + required: false + default: ./.github/variables/* +runs: + using: "composite" + steps: + - run: | + sed "" ${{ inputs.varFilePath }} >> $GITHUB_ENV + shell: bash \ No newline at end of file diff --git a/.github/actions/variables/myvars.env b/.github/actions/variables/myvars.env new file mode 100644 index 0000000..36fe5ab --- /dev/null +++ b/.github/actions/variables/myvars.env @@ -0,0 +1,7 @@ +NODE_ENV: test +DB_TYPE: postgres +DB_HOST: 127.0.0.1 +DB_PORT: 5432 +DB_DATABASE_NAME: truthy_db +DB_USERNAME: truthy_user +DB_PASSWORD: truthypwd \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2eb6fa6..d45aaa2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,6 +2,15 @@ name: test on: push +# set env variables +deploy: + runs-on: ubuntu-latest + steps: + - name: Set Environment Variables + uses: ./.github/actions/setvars + with: + varFilePath: ./.github/variables/myvars.env + jobs: test: runs-on: ubuntu-latest From 1d2c4830e5bc60c1029f633220aad45639840b8d Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:46:29 +0545 Subject: [PATCH 04/13] fix: update github action to include environment variable --- .github/workflows/test.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d45aaa2..3bcba38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,16 +2,15 @@ name: test on: push -# set env variables -deploy: +jobs: + deploy: runs-on: ubuntu-latest steps: - name: Set Environment Variables uses: ./.github/actions/setvars with: varFilePath: ./.github/variables/myvars.env - -jobs: + test: runs-on: ubuntu-latest From 4b1aeebe2587f931aec8b94184237b7205ecb629 Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:49:22 +0545 Subject: [PATCH 05/13] fix: update github action to include environment variable --- .github/workflows/test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3bcba38..183d7bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,12 +4,12 @@ on: push jobs: deploy: - runs-on: ubuntu-latest - steps: - - name: Set Environment Variables - uses: ./.github/actions/setvars - with: - varFilePath: ./.github/variables/myvars.env + runs-on: ubuntu-latest + steps: + - name: Set Environment Variables + uses: ./.github/actions/setvars + with: + varFilePath: ./.github/variables/myvars.env test: runs-on: ubuntu-latest From 3349682d18ccdd2deb08bb505767aa918def80ee Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:52:01 +0545 Subject: [PATCH 06/13] fix: update github action to include environment variable --- .github/workflows/test.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 183d7bd..ab8fcbb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,17 +2,14 @@ name: test on: push -jobs: - deploy: +jobs: + test: runs-on: ubuntu-latest steps: - name: Set Environment Variables uses: ./.github/actions/setvars with: varFilePath: ./.github/variables/myvars.env - - test: - runs-on: ubuntu-latest services: postgres: From 635d72adaf452fc9da05a14aed82bbeec4380fff Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:54:25 +0545 Subject: [PATCH 07/13] fix: update github action to include environment variable --- .github/workflows/test.yml | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ab8fcbb..30a5ad3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,11 +5,6 @@ on: push jobs: test: runs-on: ubuntu-latest - steps: - - name: Set Environment Variables - uses: ./.github/actions/setvars - with: - varFilePath: ./.github/variables/myvars.env services: postgres: @@ -36,16 +31,10 @@ jobs: with: node-version: 14.3.0 - - name: Set environment variables - uses: allenevans/set-env@v2.0.0 + - name: Set Environment Variables + uses: ./.github/actions/setvars with: - NODE_ENV: test - DB_TYPE: postgres - DB_HOST: 127.0.0.1 - DB_PORT: ${{ job.services.postgres.ports[5432] }} - DB_DATABASE_NAME: truthy_db - DB_USERNAME: truthy_user - DB_PASSWORD: truthypwd + varFilePath: ./.github/variables/myvars.env - name: Install dependencies run: npm install From f5a9b1a3e5269582fdd9f79192c79db84b61aeb4 Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 16:57:14 +0545 Subject: [PATCH 08/13] fix: update github action to include environment variable --- .github/{actions => }/variables/myvars.env | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{actions => }/variables/myvars.env (100%) diff --git a/.github/actions/variables/myvars.env b/.github/variables/myvars.env similarity index 100% rename from .github/actions/variables/myvars.env rename to .github/variables/myvars.env From a4cc31697fcdc5254833e9d3d4e8c1872b2e557a Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 17:03:40 +0545 Subject: [PATCH 09/13] fix: update github action to include environment variable --- .github/variables/myvars.env | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/variables/myvars.env b/.github/variables/myvars.env index 36fe5ab..9560ce4 100644 --- a/.github/variables/myvars.env +++ b/.github/variables/myvars.env @@ -1,7 +1,7 @@ -NODE_ENV: test -DB_TYPE: postgres -DB_HOST: 127.0.0.1 -DB_PORT: 5432 -DB_DATABASE_NAME: truthy_db -DB_USERNAME: truthy_user -DB_PASSWORD: truthypwd \ No newline at end of file +NODE_ENV=test +DB_TYPE=postgres +DB_HOST=127.0.0.1 +DB_PORT=5432 +DB_DATABASE_NAME=truthy_db +DB_USERNAME=truthy_user +DB_PASSWORD=truthypwd \ No newline at end of file From 3f611639885d4acf4179e94dfe31df3c2537137c Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 17:08:51 +0545 Subject: [PATCH 10/13] fix: update github action to include environment variable --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0fce97b..73700a5 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "test:watch": "jest --config ./test/unit/jest-unit.json --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./test/e2e/jest-e2e.json", - "test:unit": "jest --config ./test/unit/jest-unit.json --runInBand", + "test:e2e": "jest --config ./test/e2e/jest-e2e.json --detectOpenHandles", + "test:unit": "jest --config ./test/unit/jest-unit.json --runInBand --runInBand", "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/config/ormconfig.ts", "orm-create": "npm run typeorm migration:create -- -n", "migrate": "npm run typeorm migration:run", From 84d7c1ca4f822de6c309127f05320da8e756657d Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 17:19:44 +0545 Subject: [PATCH 11/13] ci: debug e2e test setting --- test/factories/app.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/factories/app.ts b/test/factories/app.ts index 064c03a..b1f6f8a 100644 --- a/test/factories/app.ts +++ b/test/factories/app.ts @@ -121,6 +121,20 @@ const setupRedis = async () => { const setupTestDatabase = async () => { const database = `test_${uuid4()}`; + console.log('🚀 ~ file: app.ts ~ line 124 ~ setupTestDatabase ~ database', { + type: dbConfig.type, + host: process.env.DB_HOST || dbConfig.host, + port: parseInt(process.env.DB_PORT) || dbConfig.port, + database: process.env.DB_DATABASE_NAME || dbConfig.database, + username: process.env.DB_USERNAME || dbConfig.username, + password: process.env.DB_PASSWORD || dbConfig.password, + logging: false, + synchronize: false, + migrationsRun: true, + migrationsTableName: 'migrations', + migrations: [__dirname + '/../../src/database/migrations/**/*{.ts,.js}'], + entities: [__dirname + '/../../src/**/*.entity{.ts,.js}'] + }); const manager = new ConnectionManager().create({ type: dbConfig.type, host: process.env.DB_HOST || dbConfig.host, From a73ffa893032a0c7ba758eb7af788e3e43ae110b Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 17:32:44 +0545 Subject: [PATCH 12/13] ci: debug e2e test setting --- .github/variables/myvars.env | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/variables/myvars.env b/.github/variables/myvars.env index 9560ce4..efe01b0 100644 --- a/.github/variables/myvars.env +++ b/.github/variables/myvars.env @@ -1,6 +1,6 @@ NODE_ENV=test DB_TYPE=postgres -DB_HOST=127.0.0.1 +DB_HOST=localhost DB_PORT=5432 DB_DATABASE_NAME=truthy_db DB_USERNAME=truthy_user diff --git a/package.json b/package.json index 73700a5..f2d5bd6 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "test:watch": "jest --config ./test/unit/jest-unit.json --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./test/e2e/jest-e2e.json --detectOpenHandles", - "test:unit": "jest --config ./test/unit/jest-unit.json --runInBand --runInBand", + "test:e2e": "jest --config ./test/e2e/jest-e2e.json --runInBand --detectOpenHandles", + "test:unit": "jest --config ./test/unit/jest-unit.json --runInBand", "typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config src/config/ormconfig.ts", "orm-create": "npm run typeorm migration:create -- -n", "migrate": "npm run typeorm migration:run", From 57a0ce164c030e25535c5a7ecd5048c4382b7d06 Mon Sep 17 00:00:00 2001 From: Roshan Ranabhat Date: Sat, 19 Mar 2022 17:43:40 +0545 Subject: [PATCH 13/13] ci: debug e2e test redis setting --- .github/workflows/test.yml | 3 +++ test/factories/app.ts | 19 ++++--------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30a5ad3..db06b8f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,7 @@ jobs: POSTGRES_PASSWORD: truthypwd ports: - 5432:5432 + redis: image: redis options: >- @@ -22,6 +23,8 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - 6379:6379 steps: - uses: actions/checkout@v2 diff --git a/test/factories/app.ts b/test/factories/app.ts index b1f6f8a..4dd8ac8 100644 --- a/test/factories/app.ts +++ b/test/factories/app.ts @@ -114,27 +114,16 @@ export class AppFactory { } const setupRedis = async () => { - const redis = new Redis({}); + const redis = new Redis({ + host: process.env.REDIS_HOST || 'localhost', + port: parseInt(process.env.REDIS_PORT) || 6379 + }); await redis.flushall(); return redis; }; const setupTestDatabase = async () => { const database = `test_${uuid4()}`; - console.log('🚀 ~ file: app.ts ~ line 124 ~ setupTestDatabase ~ database', { - type: dbConfig.type, - host: process.env.DB_HOST || dbConfig.host, - port: parseInt(process.env.DB_PORT) || dbConfig.port, - database: process.env.DB_DATABASE_NAME || dbConfig.database, - username: process.env.DB_USERNAME || dbConfig.username, - password: process.env.DB_PASSWORD || dbConfig.password, - logging: false, - synchronize: false, - migrationsRun: true, - migrationsTableName: 'migrations', - migrations: [__dirname + '/../../src/database/migrations/**/*{.ts,.js}'], - entities: [__dirname + '/../../src/**/*.entity{.ts,.js}'] - }); const manager = new ConnectionManager().create({ type: dbConfig.type, host: process.env.DB_HOST || dbConfig.host,