Skip to content

Commit

Permalink
test: restore all e2e for the be ui
Browse files Browse the repository at this point in the history
  • Loading branch information
pcheremu committed Sep 29, 2023
1 parent 55350e4 commit df871c9
Show file tree
Hide file tree
Showing 30 changed files with 3,293 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/app-deploy-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,16 @@ jobs:
expires: 7d
projectId: staging-scan-v2
entryPoint: ./packages/app

mainnet:
needs: build
name: Feature Env, Mainnet+
uses: ./.github/workflows/app-e2e.yml
secrets: inherit
permissions:
contents: read
with:
targetUrl: ${{ needs.build.outputs.dappUrl }}
default_network_value_for_e2e: "/?network=mainnet"
publish_to_allure: true
environmentTags: "and not @stagingEnv"
14 changes: 14 additions & 0 deletions .github/workflows/app-deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ jobs:
run: |
run: |
echo "Block explorer app has been deployed to: ${{ steps.deploy.outputs.details_url }}"
mainnet:
needs: deploy
name: Staging Env, Mainnet+
uses: ./.github/workflows/app-e2e.yml
secrets: inherit
permissions:
contents: read
with:
targetUrl: ${{ needs.deploy.outputs.dappUrl }}
default_network_value_for_e2e: "/?network=mainnet"
publish_to_allure: true
environmentTags: "and not @featureEnv"

150 changes: 150 additions & 0 deletions .github/workflows/app-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: BE App E2E tests

on:
workflow_call:
secrets:
ALLURE_TOKEN:
description: 'A token passed from the caller workflow'
required: true
inputs:
environmentTags:
type: string
default: ''
required: false
targetUrl:
type: string
default: 'https://staging-scan-v2.zksync.dev/'
required: true
default_network_value_for_e2e:
type: string
default: '/?network=mainnet'
required: true
publish_to_allure: #Here we define the variable that can be overwritten by caller workflow
type: boolean
description: "Publish test results to allure"
default: true
required: false

env:
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
ALLURE_SEARCH_REQUEST: '[{"id":"name","type":"string","value":"#${{ github.run_number }}"}]'
ALLURE_BASIC_TAGS: "${{ github.head_ref }}, #${{ github.run_number }}, ${{ github.event.pull_request.title }}"
ALLURE_PROJECT_ID: ${{ vars.ALLURE_PROJECT_ID }}
ALLURE_ENDPOINT: ${{ vars.ALLURE_ENDPOINT }}

jobs:
e2e:
runs-on: [self-hosted, ci-runner]
permissions:
contents: read
defaults:
run:
working-directory: ./packages/app
strategy:
fail-fast: false
matrix:
tags: [
"@artifactsSet1",
"@artifactsSet2",
"@artifactsSet3",
"@artifactsSet4",
"@redirectionSet1",
"@redirectionSet2",
"@redirectionSet3",
"@copying",
"@search",
"@testnetSmokeSuite"
]

name: '${{ matrix.tags }}'
container:
image: mcr.microsoft.com/playwright:v1.27.0-focal
options: --user root
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
working-directory: ./
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: |
npm pkg delete scripts.prepare
npm ci
- name: Download allurectl
run: wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_386 -O ./allurectl

- name: Change permission for allurectl
run: chmod +x ./allurectl

- name: Launch tests
env:
CI: 'true'
TARGET_ENV: ${{ inputs.targetUrl }}
run: |
echo "Run tests"
if [ "${{ matrix.tags }}" = "@testnetSmokeSuite" ]; then
echo "Run in testnetSmokeSuite only"
E2ENETWORK='/?network=goerli' npx cucumber-js --tags "${{ matrix.tags }} ${{ inputs.environmentTags }} and not @mainnet"
else
echo "Run in mainnet"
E2ENETWORK='${{ inputs.default_network_value_for_e2e }}' npx cucumber-js --tags "${{ matrix.tags }} ${{ inputs.environmentTags }} and not @testnet"
fi
- name: Reset tags quotes
if: always()
run: |
echo "MATRIX_TAG_WITHOUT_QUOTES=$(echo ${{ matrix.tags }} | sed -e 's/@//g' )" >> $GITHUB_ENV
- name: Create launch ID
if: always()
env:
ALLURE_LAUNCH_NAME: "#${{ github.run_number }} ${{ env.MATRIX_TAG_WITHOUT_QUOTES }}"
ALLURE_LAUNCH_TAGS: "${{ env.ALLURE_BASIC_TAGS }}, ${{ env.MATRIX_TAG_WITHOUT_QUOTES }}"
run: |
echo "ALLURE_LAUNCH_ID=$(./allurectl launch create --launch-name '${{ env.ALLURE_LAUNCH_NAME }}' --no-header --format ID | tail -n1)" >> $GITHUB_ENV
- name: Upload tests to the Allure proj
if: always() && inputs.publish_to_allure == true
run: |
./allurectl upload allure-results --launch-id ${{ env.ALLURE_LAUNCH_ID }}
./allurectl launch close ${{ env.ALLURE_LAUNCH_ID }}
- if: failure()
name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: portal_e2e_${{ github.run_number }}_artifacts
path: packages/app/tests/e2e/artifacts/*

publish:
name: Publish Allure link to GIT
runs-on: ubuntu-latest
permissions:
contents: read
needs: e2e
if: always()
steps:
- name: Prepare a link
run: |
echo "BASE64_SEARCH_REQUEST=$(echo '${{ env.ALLURE_SEARCH_REQUEST }}' | base64)" >> $GITHUB_ENV
- name: Publish Allure link to GIT Summary
run: |
LINK="${{ vars.ALLURE_ENDPOINT }}project/${{ vars.ALLURE_PROJECT_ID }}/launches?search=${{ env.BASE64_SEARCH_REQUEST }}"
echo "Allure [e2e tests]($LINK) :rocket: in git run #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
6 changes: 6 additions & 0 deletions packages/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ npm run build
npm run test
```

### Run End-to-End Tests with [Playwright](https://www.playwright.io/)

```sh
npm run test:e2e
```

### Lint with [ESLint](https://eslint.org/)

```sh
Expand Down
25 changes: 25 additions & 0 deletions packages/app/cucumber.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const getWorldParams = () => {
const params = {
foo: "bar",
};

return params;
};

export default {
requireModule: ["ts-node/register"],
paths: ["tests/e2e/features/**/*.feature"],
require: ["tests/e2e/src/**/*.ts"],
format: [
//"json:tests/e2e/reports/cucumber-report.json",
//"html:tests/e2e/reports/report.html",
"summary",
"progress-bar",
"@cucumber/pretty-formatter",
"./tests/e2e/src/support/reporters/allure-reporter.js",
],
formatOptions: { snippetInterface: "async-await" },
worldParameters: getWorldParams(),
publishQuiet: true,
retry: 1,
};
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start": "vite preview --port 3010",
"test": "TZ=UTC-3 vitest --environment jsdom",
"test:ci": "TZ=UTC-3 vitest --environment jsdom --run --reporter=verbose --reporter=junit --outputFile.junit=./junit.xml",
"test:e2e": "cucumber-js -t \"not @testnet\"",
"typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
"storybook": "start-storybook -s ./public -p 6006",
Expand Down
61 changes: 61 additions & 0 deletions packages/app/tests/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# The test solution for BlockExplorer v2 E2E testing

Based on Playwright.io/TypeScript/BDD

## Recommended E2E pre-test setup

Before the execution of the end-2-end tests there needs to install dependencies:

```bash
npm install
```

## How to run E2E tests

--
all tests:
```bash
npx cucumber-js
```
or

```bash
npm run test:e2e
```

--
tests by specified tags (eg, @title):
```bash
npx cucumber-js --tags @title
```
## Variables

process.env.TARGET_ENV:
set up the target URL environment for the test run. Default value is stage https://staging-scan-v2.zksync.dev

## Reports
Reports are configured in Cucumber.mjs file and results after test runs might be gotten by the next one approaches:

Cucumber reports:

- uncomment lines in cucumber.mjs file
// "json:tests/e2e/reports/cucumber-report.json",
// "html:tests/e2e/reports/report.html",

- run the script below
```bash
open tests/e2e/reports/report.html
```
Allure reports:

It's working on CI/CD. The results are collected in allure-results folder. Every test run generate appropriate test result data in JSON format.

## Tags
Tags allow to separate the current feature scope to appropriate suits, eg:

@smoke
@sanity
@regression:small
@regression:all

Tags should be pasted above the "Feature" or "Scenario" key-word
Loading

0 comments on commit df871c9

Please sign in to comment.