Skip to content

Commit

Permalink
feat: create initial setup for e2e + gh automation (#558)
Browse files Browse the repository at this point in the history
* feat: create initial setup for e2e + gh automation

* skip e2e when running unit tests

* exclude e2e from unit testts

* add env variables to ci

* increase timeout to 15s

* use gh env variables for non secrets
  • Loading branch information
MCarlomagno authored Sep 17, 2024
1 parent c755816 commit 7359ec0
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 73 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test end-to-end

on:
push:
branches: [ "main" ]

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

# Declare default permissions as read only.
permissions: read-all

env:
API_KEY: ${{ secrets.E2E_API_KEY }}
API_SECRET: ${{ secrets.E2E_API_SECRET }}
DEFENDER_API_URL: $E2E_DEFENDER_API_URL
DEFENDER_POOL_ID: $E2E_DEFENDER_POOL_ID
DEFENDER_POOL_CLIENT_ID: $E2E_DEFENDER_POOL_CLIENT_ID

jobs:
build-test:
name: Run build & e2e test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.5.4

- name: Prepare pre-requisites
uses: ./.github/actions/prepare

- name: Build
run: |
pnpm nx-build-skip-cache
- name: Test end-to-end
run: |
pnpm test:e2e
7 changes: 7 additions & 0 deletions e2e/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
API_KEY=
API_SECRET=

# OPTIONAL FOR LOWER ENVIRONMENTS
DEFENDER_API_URL=
DEFENDER_POOL_ID=
DEFENDER_POOL_CLIENT_ID=
5 changes: 5 additions & 0 deletions e2e/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/src/**/*.test.ts'],
};
23 changes: 23 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "e2e",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest",
"test:watch": "jest --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.5.12",
"axios": "^1.7.2",
"jest": "^29.7.0",
"ts-jest": "^29.1.2"
},
"dependencies": {
"@openzeppelin/defender-sdk": "workspace:^",
"dotenv": "^16.4.5"
}
}
15 changes: 15 additions & 0 deletions e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "e2e",
"root": "e2e",
"sourceRoot": "e2e/src",
"projectType": "application",
"targets": {
"test": {
"executor": "nx:run-commands",
"options": {
"command": "pnpm test",
"cwd": "e2e"
}
}
}
}
17 changes: 17 additions & 0 deletions e2e/src/actions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require('dotenv').config();
import { Defender } from '@openzeppelin/defender-sdk';

// Default timeout is not enough, using 15s timeout instead.
jest.setTimeout(15 * 1000);

describe('actions', () => {
const actionClient = new Defender({
apiKey: process.env.API_KEY,
apiSecret: process.env.API_SECRET,
}).action;

it('should list actions', async () => {
const result = await actionClient.list();
expect(result.items).toBeDefined();
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"lint:fix": "pnpm prettier:fix && pnpm lint:check && pnpm prettier:check",
"prettier:check": "prettier -u --check '**/*.{js,ts,tsx,md}' '!**/.nx/**'",
"prettier:fix": "prettier -u --write '**/*.{js,ts,tsx,md}' '!**/.nx/**'",
"test": "nx run-many -t test --parallel=1",
"test": "nx run-many -t test --exclude=e2e --parallel=1",
"test:e2e": "nx run e2e:test",
"build:changed": "nx affected:build --base=origin/main --skip-nx-cache --parallel=1",
"test:changed": "nx affected:test --base=origin/main --skip-nx-cache --parallel=1",
"style": "pnpm lint:fix",
Expand Down
118 changes: 46 additions & 72 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- 'packages/*'
- 'examples/*'
- 'e2e'

0 comments on commit 7359ec0

Please sign in to comment.