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/variables/myvars.env b/.github/variables/myvars.env new file mode 100644 index 0000000..efe01b0 --- /dev/null +++ b/.github/variables/myvars.env @@ -0,0 +1,7 @@ +NODE_ENV=test +DB_TYPE=postgres +DB_HOST=localhost +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 109ff7c..db06b8f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: test on: push -jobs: +jobs: test: runs-on: ubuntu-latest @@ -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 @@ -31,15 +34,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 - DATABASE_HOST: 127.0.0.1 - DATABASE_PORT: ${{ job.services.postgres.ports[5432] }} - DATABASE_NAME: truthy_db - DATABASE_USER: truthy_user - DATABASE_PASSWORD: truthypwd + varFilePath: ./.github/variables/myvars.env - name: Install dependencies run: npm install @@ -48,4 +46,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 diff --git a/package.json b/package.json index 0fce97b..f2d5bd6 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "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: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", diff --git a/test/factories/app.ts b/test/factories/app.ts index 064c03a..4dd8ac8 100644 --- a/test/factories/app.ts +++ b/test/factories/app.ts @@ -114,7 +114,10 @@ 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; };