Skip to content

Commit

Permalink
ci: add e2e runs to main and next-deployment workflows (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
timonmasberg authored Mar 22, 2023
1 parent 3f945dc commit 3c690c0
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 171 deletions.
34 changes: 18 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,9 @@ on:
pull_request:
types:
- opened
- edited
- synchronize

jobs:
check-pr-title:
if: github.event_name == 'pull_request' && (github.event.action == 'edited' || github.event.action == 'opened')
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

main:
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -33,21 +22,34 @@ jobs:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci

- uses: nrwl/nx-set-shas@v3
- name: Check Formatting
run: npx nx format:check
- name: Lint
run: npx nx affected --target=lint --parallel=3

- name: Run Tests with Code Coverage
run: npx nx affected --target=test --parallel=3 --ci --coverage --coverageReporters=lcov
- name: Merge Coverage files
run: '[ -d "./coverage/" ] && ./node_modules/.bin/lcov-result-merger ./coverage/**/lcov.info ./coverage/lcov.info || exit 0'

- name: Create SPA Environment File
run: envsubst < apps/spa/src/environments/environment.template > apps/spa/src/environments/environment.prod.ts
env:
IS_PRODUCTION: true
DEPLOYMENT_NAME: E2E Runner
API_URL: http://localhost:3000/
- name: Create API Environment File
run: envsubst < apps/api/src/.env.template > apps/api/src/.env
env:
PORT: 3000
- name: Build
run: |
touch apps/spa/src/environments/environment.prod.ts
npx nx affected --target=build --parallel=3
- name: Run e2es
run: npx nx affected --target=e2e
run: npx nx affected --target=build --parallel=3

- name: Run E2Es
run: npm run e2e

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/next-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
environment:
name: Next
url: ${{ steps.spa-deployment.outputs.url }}
outputs:
spaUrl: ${{ steps.spa-deployment.outputs.url }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -37,3 +39,18 @@ jobs:
deploymentName: "main.${{ github.sha }}"
deploymentEnv: "next"
publishToken: ${{ secrets.AZURE_STATIC_WEB_APP_TOKEN }}

e2e:
needs: deployment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- name: Run SPA E2Es
run: npx nx e2e spa-e2e
env:
E2E_BASE_URL: ${{ needs.deployment.spaUrl }}
14 changes: 14 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: PR Title Check
on:
pull_request:
types:
- opened
- edited

jobs:
check-pr-title:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ Thumbs.db
**/test-results
**/playwright-report
**/playwright/.cache

# Environments
apps/api/src/.env
apps/spa/src/environments/environment.prod.ts
18 changes: 0 additions & 18 deletions apps/api-e2e/.eslintrc.json

This file was deleted.

20 changes: 0 additions & 20 deletions apps/api-e2e/jest.config.ts

This file was deleted.

22 changes: 0 additions & 22 deletions apps/api-e2e/project.json

This file was deleted.

28 changes: 0 additions & 28 deletions apps/api-e2e/src/api/api.spec.ts

This file was deleted.

10 changes: 0 additions & 10 deletions apps/api-e2e/src/support/global-setup.ts

This file was deleted.

7 changes: 0 additions & 7 deletions apps/api-e2e/src/support/global-teardown.ts

This file was deleted.

9 changes: 0 additions & 9 deletions apps/api-e2e/src/support/test-setup.ts

This file was deleted.

16 changes: 0 additions & 16 deletions apps/api-e2e/tsconfig.json

This file was deleted.

9 changes: 0 additions & 9 deletions apps/api-e2e/tsconfig.spec.json

This file was deleted.

1 change: 1 addition & 0 deletions apps/api/src/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=$PORT
3 changes: 2 additions & 1 deletion apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [],
imports: [ConfigModule.forRoot({ isGlobal: true, cache: true })],
controllers: [AppController],
providers: [AppService],
})
Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
* This is only a minimal backend to get started.
*/
import { Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';

async function bootstrap(): Promise<void> {
const app = await NestFactory.create(AppModule, { cors: true });
const port = process.env.PORT || 3333;
const config = app.get(ConfigService);

const envPort = config.get('PORT');
const port = envPort ? +envPort : 3000;
await app.listen(port);

Logger.log(`🚀 Application is running on: http://localhost:${port}}`);
}

Expand Down
8 changes: 1 addition & 7 deletions apps/spa-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
"executor": "@mands/nx-playwright:playwright-executor",
"options": {
"e2eFolder": "apps/spa-e2e",
"devServerTarget": "spa:serve",
"packageRunner": "yarn"
},
"configurations": {
"production": {
"devServerTarget": "spa:serve:production"
}
"packageRunner": "npx"
}
},
"ts-check": {
Expand Down
31 changes: 31 additions & 0 deletions docs/architecture-decisions/adr003-e2e.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ADR003: E2E Test Strategy

## Status

accepted

## Context

There is the need to run E2Es automatically in the pipeline to test our whole
application. We had no strategy on what and where to do any end-to-end testing.

## Decision

- We are only end-to-end testing our SPA application because:
- 1. it reduces the complexity of the whole project,
- 2. there is no value in having API E2Es while the SPA E2E cover all
functionality,
- 3. we ship only one bundle and therefore do not need regression tests for
multiple API versions.
- For PRs, we run against a "locally" (in the pipeline) started instance of the
SPA and the API Project.
- For pushes into main, we test against the next deployment on our Azure
Infrastructure.

## Consequences

We do not have an explicit end-to-end coverage of the API in exchange for faster
development and less test maintenance. The complete pipeline with interceptors
etc. of the API will not be tested explicitly. With enough unit tests and the
end-to-end tests from the SPA project which consumes the API, there should be
enough coverage for both projects.
Loading

0 comments on commit 3c690c0

Please sign in to comment.