Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playwright e2e reconfiguration #871

Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d85490a
Reconfigure playwright, fix tests, update test:e2e and .gitignore
atomicgamedeveloper Jul 30, 2024
afcafcc
Update client.yml to run e2e tests
atomicgamedeveloper Aug 5, 2024
5641052
Implement monocart-reporter
atomicgamedeveloper Aug 12, 2024
afdd8a5
Add codecov git action and passing test
atomicgamedeveloper Aug 12, 2024
54b8f25
Fix lint, test and import issues
atomicgamedeveloper Aug 12, 2024
0782a63
Merge branch 'feature/distributed-demo' into 320-failing-e2e-tests
atomicgamedeveloper Aug 12, 2024
c0e2b4f
Update yarn.lock, rm duplicated cmd from client.yml
atomicgamedeveloper Aug 12, 2024
c45e491
Merge branch '320-failing-e2e-tests' of https://github.com/atomicgame…
atomicgamedeveloper Aug 12, 2024
5091475
Add playwright installation to git actions workflow
atomicgamedeveloper Aug 12, 2024
465aac2
Install dependencies with playwright in gha
atomicgamedeveloper Aug 12, 2024
6a60e5a
Specify config file in yarn cmd
atomicgamedeveloper Aug 12, 2024
843c7b9
Refactor and add artifact upload step
atomicgamedeveloper Aug 26, 2024
18640cf
Add defaults field with working-directory of client
atomicgamedeveloper Aug 26, 2024
bc05caa
Add defaults field with working-directory of client
atomicgamedeveloper Aug 26, 2024
a0436db
Add meaningful default base uri in playwright config, simplify test:e…
atomicgamedeveloper Aug 26, 2024
6bb6084
Fix tracing
atomicgamedeveloper Aug 26, 2024
4222b1c
Change trace path in client.yml
atomicgamedeveloper Aug 26, 2024
4df1766
Add debug and use absolute paths in client.yml
atomicgamedeveloper Aug 26, 2024
5625680
Run yarn config:test before running e2e tests, rm debug
atomicgamedeveloper Aug 26, 2024
12e0848
Actually remove debug
atomicgamedeveloper Aug 26, 2024
0641730
Let dummy test start first, name step in client.yml
atomicgamedeveloper Aug 26, 2024
5a7dacb
Remove github actions debug tests
atomicgamedeveloper Aug 27, 2024
6957862
Add cmd test:e2e:int, update readme, add console-summary
atomicgamedeveloper Sep 5, 2024
c73625d
Move yarn:config:test after yarn install in client.ymæ
atomicgamedeveloper Sep 5, 2024
a1777a6
Update readme.md and client.yml
atomicgamedeveloper Sep 6, 2024
afe2841
Add missing codeblock syntax
atomicgamedeveloper Sep 6, 2024
cebb28f
Rename yarn test:e2e:int to yarn test:e2e:ext
atomicgamedeveloper Sep 6, 2024
bb40245
Apply filters to coverage collection and rename test:e2e:int
atomicgamedeveloper Sep 17, 2024
9e30243
Merge branch 'feature/distributed-demo' into 320-failing-e2e-tests
atomicgamedeveloper Sep 18, 2024
34b48ee
Build the website before trying to copy into it
atomicgamedeveloper Sep 18, 2024
be49509
Fix formatting
atomicgamedeveloper Sep 18, 2024
fcb7a26
Update test/README.md parts about external hosting
atomicgamedeveloper Sep 18, 2024
26b66b1
Remove bug notice in DEVELOPER.md
atomicgamedeveloper Sep 19, 2024
20895a1
Update readme.md
atomicgamedeveloper Sep 20, 2024
2d4cc3b
Fix code climate issues about readme.md
atomicgamedeveloper Sep 20, 2024
b207020
Add Traeffik note to readme
atomicgamedeveloper Sep 20, 2024
b4abc81
Add Traeffik note to readme again
atomicgamedeveloper Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ on:
paths:
- 'client/**'
workflow_dispatch:
paths:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this. Otherwise, this workflow runs too many times.

- 'client/**'

jobs:
client:
name: Test react website
runs-on: ubuntu-latest
defaults:
run:
working-directory: client/
prasadtalasila marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,29 +27,49 @@ jobs:
cache: "yarn"
cache-dependency-path: "**/yarn.lock"

- name: Install dependencies and setup env
run: |
yarn config:test
yarn install
yarn playwright install --with-deps

- name: Run the linting checks
run: |
cd client/
yarn install
yarn syntax

- name: Build the React SPA website
run: |
cd client/
yarn install
yarn build

- name: Run client unit and integration tests
run: |
cd client/
yarn install
yarn config:test
yarn test:int
yarn test:unit

- name: Upload unit and integration test coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: client/coverage/clover.xml
flags: client-unit-integration-tests
flags: client-unit-integration-tests

- name: Run e2e tests
continue-on-error: true
run: |
yarn test:e2e

- name: Upload Playwright Report
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: client/playwright-report/**
retention-days: 30

- name: Upload e2e test coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: client/coverage/e2e/codecov.json
flags: client-e2e-tests

get_version:
name: Get version
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ build/
# Test reports
coverage/
playwright-report/
playwright/
client/playwright/
test_results/

# Mac temp files
Expand Down
3 changes: 2 additions & 1 deletion client/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ api/
build/
config/
node_modules/
script/
script/
coverage/
3 changes: 2 additions & 1 deletion client/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
playwright/.auth/
playwright/.auth/
test-results/
5 changes: 4 additions & 1 deletion client/package.json
prasadtalasila marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"stop": "npx kill-port 4000",
"syntax": "npx eslint . --fix",
"test:all": "yarn test:unit && yarn test:int && yarn test:e2e",
"test:e2e": "yarn build && yarn config:test && npx kill-port 4000 && yarn start >/dev/null & playwright test && npx kill-port 4000",
"test:e2e:int": "cross-env int=true yarn test:e2e",
"test:e2e": "playwright test -c ./playwright.config.ts",
"test:int": "jest -c ./jest.config.json ../test/integration --setupFilesAfterEnv ./test/integration/jest.setup.ts",
"test:unit": "jest -c ./jest.config.json ../test/unit --setupFilesAfterEnv ./test/unit/jest.setup.ts"
},
Expand All @@ -50,6 +51,7 @@
"@types/styled-components": "^5.1.32",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"cross-env": "^7.0.3",
"dotenv": "^16.1.4",
"eslint": "8.54.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand Down Expand Up @@ -89,6 +91,7 @@
"@types/react-dom": "^18.2.17",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"monocart-coverage-reports": "^2.10.2",
"playwright": "^1.32.1",
"prettier": "^3.2.4",
"shx": "^0.3.4",
Expand Down
40 changes: 32 additions & 8 deletions client/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,48 @@
import { defineConfig, devices } from '@playwright/test';
import * as dotenv from 'dotenv';

// Check if playwright was called with 'int' flag.
const useIntServer = process.env.int === 'true';

dotenv.config({ path: './test/.env' });
// import fs from 'fs';
// import path from 'path';

// const storeState = JSON.parse(fs.readFileSync(path.resolve('./playwright/.auth/user.json'), 'utf-8'));
const BASE_URI = process.env.REACT_APP_URL.toString() ?? '';
const BASE_URI = process.env.REACT_APP_URL ?? 'http://localhost:4000/';

export default defineConfig({
prasadtalasila marked this conversation as resolved.
Show resolved Hide resolved
timeout: 45000,
globalTimeout: 600000,
testDir: './test/e2e',
webServer: useIntServer ? undefined : {
command: 'yarn start'
},
timeout: 60 * 1000,
globalTimeout: 10 * 60 * 1000,
testDir: './test/e2e/tests',
testMatch: /.*\.test\.ts/,
reporter: [
['html', { outputFile: 'playwright-report/index.html' }],
[
'html',
{
outputFile: 'playwright-report/index.html',
},
],
['list'],
['junit', { outputFile: 'playwright-report/results.xml' }],
['json', { outputFile: 'playwright-report/results.json' }],
],
[
'junit',
{
outputFile: 'playwright-report/results.xml',
},
],
[
'json',
{
outputFile: 'playwright-report/results.json',
},
],
], // Codecov handled through Monocart-Reporter https://github.com/cenfun/monocart-reporter
use: {
baseURL: BASE_URI,
trace: 'retain-on-failure',
},
projects: [
// Setup project
Expand All @@ -51,4 +73,6 @@ export default defineConfig({
dependencies: ['setup'],
},
],
globalSetup: 'test/e2e/setup/global.setup.ts',
globalTeardown: 'test/e2e/setup/global-teardown.ts',
});
47 changes: 30 additions & 17 deletions client/test/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# End-to-End (E2E) Tests

The E2E tests require a functional gitlab oauth setup, traefik gateway and a
live react client website. The E2E tests do not launch the react client website.
So it is important to launch the website using `yarn start`. Keep this server
running while performing the E2E tests with `yarn test:e2e` command.
The E2E tests require playwright test runner, an on-premise GitLab OAuth setup and
configured `config/test.js` and `test/.env` files. When everything is set up, you
can run the tests by running `yarn test:e2e`.

By default, Playwright launches the react client website as specified in `config/test.js`
and terminates it afterwards. Running `yarn test:e2e:int` allows you to skip this so
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

you can host the website yourself.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that we can host the client at a doman address (say sandbox.cps.digit.au.dk) and perform E2E tests?


## Playwright

The E2E tests use playwright test runner. You also need to have the software
installed. If it is not installed, you can install with the following command.
installed. If it is not installed, you can install it with the following command.

```bash
sudo npx playwright install-deps
yarn playwright install --with-deps
```

## OAuth Setup

You can follow the instructions in
[authorization page](../../docs/admin/client/auth.md) to setup oauth for the
You can follow the instructions in [authorization page](../../docs/admin/client/auth.md) to setup OAuth for the
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

react client website. Remember to add the `http://localhost:4000` as callback URL
in the oauth application. The gitlab will still be running on a remote machine.
It is not possible to run both the gitlab and react client website on localhost.
in the OAuth application. The GitLab will still be running on a remote machine.
It is not possible to run both the GitLab and react client website on localhost.

## config/test.js file

Expand All @@ -35,8 +39,7 @@ the details of your testing environment. For instance, you need to adjust:
* `REACT_APP_LOGOUT_REDIRECT_URI`

to reflect your test setup. More information on about the environment settings is
available in [authorization](../../docs/admin/client/auth.md) and
[client deployment](../../docs/admin/client/CLIENT.md) pages.
available in [authorization](../../docs/admin/client/auth.md) and [client deployment](../../docs/admin/client/CLIENT.md) pages.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length


Here's an example of relevant values for variables. This example is suitable for
testing on developer computer.
Expand All @@ -48,6 +51,8 @@ REACT_APP_REDIRECT_URI="http://localhost:4000/Library"
REACT_APP_LOGOUT_REDIRECT_URI="http://localhost:4000"
```

Finally, run `yarn config:test` to copy the config file into the `build` and `public` folders.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length


## env file

You need to create a `test/.env` file where you will store the GitLab user
Expand Down Expand Up @@ -77,7 +82,8 @@ REACT_APP_URL='http://localhost:4000'

## Testing on localhost

There are two possible testing setups you can create.
If you want to handle starting the react client server yourself, there are two
possible testing setups you can create.

1. Host website on the developer computer and test from developer computer
1. Host website on the integration server and test from the integration server
Expand Down Expand Up @@ -127,7 +133,7 @@ credentials on `gitlab.foo.com`.
## Testing on the integration server

In this test setup, the DTaaS application is running at `https://foo.com` and
the gitlab instance is running at `https://gitlab.foo.com`. The E2E test shall
the GitLab instance is running at `https://gitlab.foo.com`. The E2E test shall
be run from the developer computer. The codebase commit should be the same on
both the developer computer and integration server.

Expand All @@ -150,7 +156,7 @@ window.env = {
REACT_APP_AUTH_AUTHORITY: 'https://gitlab.foo.com/',
REACT_APP_REDIRECT_URI: 'https://foo.com/Library',
REACT_APP_LOGOUT_REDIRECT_UR: 'https://foo.com/',
REACT_APP_GITLAB_SCOPES: 'openid profile read_user read_repository api',
REACT_APP_GitLab_SCOPES: 'openid profile read_user read_repository api',
};
```

Expand All @@ -171,12 +177,19 @@ gateway and the client website hosted behind traefik.

## Running the Tests

Once you've properly set up your .env file, you can now run the end-to-end tests.
Once you've properly set up your .env file, you can run the end-to-end tests as follows:

```bash
yarn test:e2e
```
Or with manual website launch:
```bash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

yarn test:e2e:int
```

These commands launch the test runner and execute all end-to-end tests. The first
command also runs the `yarn start` command to start the client website
and terminates it after testing.

This command launches the test runner and executes all end-to-end tests.
Make sure you have an active internet connection while running these tests,
as they simulate real user interactions with your GitLab account.
47 changes: 47 additions & 0 deletions client/test/e2e/setup/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { test as testBase } from '@playwright/test';
import MCR from 'monocart-coverage-reports';
import coverageOptions from './mcr.config';

// fixtures
const test = testBase.extend<{
autoTestFixture: string;
}>({
autoTestFixture: [
async ({ page }, use) => {
const isChromium = test.info().project.name === 'chromium';

// console.log('autoTestFixture setup...');
// coverage API is chromium only
if (isChromium) {
await Promise.all([
page.coverage.startJSCoverage({
resetOnNavigation: false,
}),
page.coverage.startCSSCoverage({
resetOnNavigation: false,
}),
]);
}

await use('autoTestFixture');

// console.log('autoTestFixture teardown...');
if (isChromium) {
const [jsCoverage, cssCoverage] = await Promise.all([
page.coverage.stopJSCoverage(),
page.coverage.stopCSSCoverage(),
]);
const coverageList = [...jsCoverage, ...cssCoverage];
// console.log(coverageList.map((item) => item.url));
const mcr = MCR(coverageOptions);
await mcr.add(coverageList);
}
},
{
scope: 'test',
auto: true,
},
],
});

export default test;
9 changes: 9 additions & 0 deletions client/test/e2e/setup/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import MCR from 'monocart-coverage-reports';
import coverageOptions from './mcr.config';

async function globalTeardown() {
const mcr = MCR(coverageOptions);
await mcr.generate();
}

export default globalTeardown;
9 changes: 9 additions & 0 deletions client/test/e2e/setup/global.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import MCR from 'monocart-coverage-reports';
import coverageOptions from './mcr.config';

async function globalSetup() {
const mcr = MCR(coverageOptions);
await mcr.cleanCache();
}

export default globalSetup;
12 changes: 12 additions & 0 deletions client/test/e2e/setup/mcr.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CoverageReportOptions } from 'monocart-coverage-reports';

// https://github.com/cenfun/monocart-coverage-reports
const coverageOptions: CoverageReportOptions = {
name: 'Playwright Monocart Coverage Reports',

reports: ['codecov', 'v8', 'console-summary'],

outputDir: './coverage/e2e',
};

export default coverageOptions;
Loading