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

test: add e2e test #151

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b2f45e9
add e2e test
gpBlockchain Mar 24, 2023
4902575
add playwright test
gpBlockchain Mar 24, 2023
b8427e2
Delete package-lock.json
gpBlockchain Mar 24, 2023
3738671
add only option
gpBlockchain Mar 24, 2023
d0db1f8
fix:fix e2e
gpBlockchain Mar 26, 2023
abd728a
fix:fix e2e test failed
gpBlockchain Mar 26, 2023
fe55bc7
fix:fix e2e test failed
gpBlockchain Mar 26, 2023
eae2b5a
fix: const words capitalized
gpBlockchain Mar 27, 2023
b959551
Merge branch 'ckb-js:main' into lgp/fix-e2e
gpBlockchain Mar 27, 2023
f0c8f5b
Merge remote-tracking branch 'origin/lgp/fix-e2e' into lgp/fix-e2e
gpBlockchain Mar 27, 2023
7d6498e
fix: not connected => Disconnected
gpBlockchain Mar 27, 2023
737f6fd
fix: for => use it.each
gpBlockchain Mar 27, 2023
061faa3
fix: succ=>success,diff => different
gpBlockchain Mar 27, 2023
819de54
style: clarify the test case name
gpBlockchain Mar 27, 2023
66354c0
style: replace_mn=> replaceMnemonic,sed => seed
gpBlockchain Mar 27, 2023
7b7c2e5
Update .github/workflows/e2e.yaml
gpBlockchain Mar 28, 2023
3808ca8
fix: remove ui that deprecated rpcs
gpBlockchain Mar 28, 2023
2189b14
style(nexus-web): remove unused method && ckbVersion => ckbWalletVersion
gpBlockchain Mar 28, 2023
4293915
Merge branch 'ckb-js:main' into lgp/fix-e2e
gpBlockchain Mar 28, 2023
bbcebfb
style(e2e): remove tbd
gpBlockchain Mar 28, 2023
cee0763
Merge remote-tracking branch 'origin/lgp/fix-e2e' into lgp/fix-e2e
gpBlockchain Mar 28, 2023
f15f075
style(e2e): remove deprecated RPC interfaces
gpBlockchain Mar 28, 2023
8a86a68
fix(e2e): fix wallet_enable
gpBlockchain Mar 29, 2023
819d795
ci(e2e): report move to https://github.com/ckb-js/nexus-e2e-report.g…
gpBlockchain Mar 30, 2023
5b3543a
fix(e2e-web): fix e2e web and demo test
gpBlockchain Mar 30, 2023
68abe02
fix: test timeout 3min
gpBlockchain Mar 30, 2023
2604495
fix: e2e report deploy failed
gpBlockchain Mar 30, 2023
e57b061
Merge branch 'ckb-js:main' into lgp/fix-e2e
gpBlockchain Mar 30, 2023
e25dcdd
style(): injectionTestSatus => beforeAll
gpBlockchain Mar 30, 2023
a768806
Merge remote-tracking branch 'origin/lgp/fix-e2e' into lgp/fix-e2e
gpBlockchain Mar 30, 2023
2dce2e5
Merge branch 'ckb-js:main' into lgp/fix-e2e
gpBlockchain Mar 30, 2023
90b3e20
ci(e2e): move e2e report repo
gpBlockchain Mar 30, 2023
4026e6b
Merge remote-tracking branch 'origin/lgp/fix-e2e' into lgp/fix-e2e
gpBlockchain Mar 30, 2023
a730145
fix: fix connected && add todo test
gpBlockchain Mar 30, 2023
90f61a9
fix: fix connected && add todo test
gpBlockchain Mar 30, 2023
66ae1b7
fix: update package-lock.json
gpBlockchain Mar 30, 2023
94d16f3
fix: fix Screenshot failed
gpBlockchain Mar 30, 2023
d6408cc
fix: relace some url
gpBlockchain Mar 30, 2023
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
108 changes: 108 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: E2E Test
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: actions/setup-node@v3
with:
node-version: 18

- name: restore dependencies
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}

- name: start nexus web web
gpBlockchain marked this conversation as resolved.
Show resolved Hide resolved
id: startWeb
if: success() || failure()
run: |
cd /home/runner/work/nexus/nexus/e2e/packages/nexus-web
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a ENV property for the path /home/runner/work/nexus/nexus?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This path is the fixed path in the action, need to modify it?

npm i
npm run start > node.log 2>&1 &

- name: test
id: test
if: success() || failure()
run: |
cd /home/runner/work/nexus/nexus/e2e/packages/e2e
npm i
npm run build
xvfb-run --auto-servernum npm run jest
- name: make update file dir
if: success() || failure()
run: |
mkdir /home/runner/work/nexus/nexus/reportAndNexus
- name: cp nexus file to update file
if: success() || failure()
run: |
tar -zcvf /home/runner/work/nexus/nexus/reportAndNexus/build.tar.gz /home/runner/work/nexus/nexus/packages/extension-chrome/build

- name: package report
id: package
if: success() || failure()
run: |
tar -zcvf /home/runner/work/nexus/nexus/reportAndNexus/allure-results.tar.gz /home/runner/work/nexus/nexus/e2e/packages/e2e/allure-results

- name: Publish e2e test report and nexus build
if: success() || failure()
uses: actions/upload-artifact@v2
with:
name: jfoa-build-reports-${{ runner.os }}
path: /home/runner/work/nexus/nexus/reportAndNexus

- name: cp report
id: cp-report
if: success() || failure()
run: |
cd /home/runner/work/nexus/nexus
cp -r /home/runner/work/nexus/nexus/e2e/packages/e2e/allure-results .

- name: Get Allure history
uses: actions/checkout@v2
if: always()
continue-on-error: true
with:
ref: gh-pages
repository: gpBlockchain/nexus-e2e-report
gpBlockchain marked this conversation as resolved.
Show resolved Hide resolved
path: gh-pages

- name: Allure Report action from marketplace
uses: simple-elf/allure-report-action@master
if: always()
#id: allure-report
with:
allure_results: /home/runner/work/nexus/nexus/allure-results
github_repo: gpBlockchain/nexus-e2e-report
github_repo_owner: ${{ github.repository_owner }}
gh_pages: gh-pages
#allure_report: allure-report
allure_history: allure-history
keep_reports: 20

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
if: always()
with:
token: ${{ secrets.PERSON_TOKEN }}
folder: allure-history # The folder the action should deploy.
repository-name: gpBlockchain/nexus-e2e-report
branch: gh-pages

- name: Cat report Link
if: always()
run: |
cat allure-history/index.html
11 changes: 11 additions & 0 deletions e2e/packages/e2e/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
# editorconfig-tools is unable to ignore longs strings or urls
max_line_length = off
1 change: 1 addition & 0 deletions e2e/packages/e2e/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
30 changes: 30 additions & 0 deletions e2e/packages/e2e/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
root: true,
extends: ['react-app'],
parserOptions: {
ecmaVersion: 2020,
project: ['tsconfig.json', 'tsconfig.test.json'],
sourceType: 'module',
},
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
},
],
},
overrides: [
{
files: '*.{ts,tsx}',
rules: {
'@typescript-eslint/no-explicit-any': 'error',
Copy link
Contributor

Choose a reason for hiding this comment

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

The better way is to modify these rules. I have seen many /* eslint-disable xxxxxxx */ in e2e. these rules may not suitable to enable on the e2e test files. @homura can we modify it? I need your opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are only 12 disable mark in this PR, and I found no disable mark for any, therefore, just keep it as it is

'@typescript-eslint/explicit-module-boundary-types': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'no-console': 'warn',
'@typescript-eslint/no-throw-literal': 'error',
},
},
],
};
4 changes: 4 additions & 0 deletions e2e/packages/e2e/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lumos

# auto generated
docs/rpc.md
6 changes: 6 additions & 0 deletions e2e/packages/e2e/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true,
"arrowParens": "always"
}
140 changes: 140 additions & 0 deletions e2e/packages/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# e2e

E2E testing for dApps using playwright + Nexus

## Usage

open `nexus` extension page, connect web with `nexus`

```javascript
const nexusExtensionPath = './build';
const browser = await launchWithNexus({ nexusPath: nexusExtensionPath });
const nexusWallet = await setUpNexus(browser, { mock: true });
const page = await browser.newPage();
await page.goto('https://nexus-e2e.vercel.app/', {});
await page.click('#connectButton');
await nexusWallet.connect();
```

nexus methods

```javascript
export type NexusLaunchOptions = {
nexusPath: string,
playwrightOptions?: playWrightLaunchOpt,
};

export type NexusSetUpOptions = {
mock?: boolean,
userName: string,
passwd: string,
seed?: string,
};

export type AddNetworkOpt = {
name: string,
url: string,
};
export type PopupPageHelper = {
getNewPage: () => Promise<Page>,
queryWhitelist: () => Promise<string[]>,
removeWhitelistBySearch: (search: string) => void,
queryNetworkList: () => Promise<string[]>,
addNetwork: (addNetworkOpt: AddNetworkOpt) => void,
removeNetworkByName: (name: string) => void,
changeNetworkByName: (name: string) => void,
queryConnected: () => Promise<boolean>,
queryNickName: () => Promise<string>,
};

export type WalletManagerHelper = {
getNewPage: () => Promise<Page>,
importWallet: (page: Page, userName: string, mnemonic: string, password: string) => void,
createANewWallet: (page: Page, userName: string, password: string) => Promise<string>,
};
export type NexusWallet = {
popup: PopupPageHelper,
approve: (passwd: string) => void,
connect: () => void,
cancel: () => void,
walletManager: WalletManagerHelper,
getNotificationPage: () => Promise<Page>,
close: () => void,
};
```

## Run E2E Test

run test after [start nexus-e2e-web](../nexus-web/README.md)

#### start nexus web

```shell
cd e2e/packages/nexus-web
npm i
npm run start
```

# build nexus

```shell
cd e2e/packages/e2e
npm i
npm run build
```

# run test

```shell
npm run jest

```

### notice

After executing the test case, the browser will save persistent data in the `e2e/packages/e2e/tmp` directory.

# cat local allure reporter after test

```
cd e2e/packages/e2e
allure serve allure-results
```

# CI Logic

ci file: e2e.yaml

Execution Steps:

- Start nexus-web test site.
- Compile nexus plugin wallet.
- Run test cases.
- Push the report to nexus-e2e-reporter.

Execution Time:

- pull_request
- merge_request

Environment Variable:

- PERSON_TOKEN (Personal Access Token (PAT))

### How to add Personal Access Token

##### generate Personal Access Token

- click: https://github.com/settings/tokens

![img.png](imgs/img.png)

- Add PAT(Personal Access Token) to Repository Secrets

![img.png](imgs/img1.png)

### View the test report

![img.png](imgs/img_1.png)
![img.png](imgs/img_2.png)
![img.png](imgs/img_3.png)
10 changes: 10 additions & 0 deletions e2e/packages/e2e/__tests__/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const MNEMONIC = 'abandon ability able about above absent absorb abstract absurd abuse access accident';
export const USER_NAME = 'xm';
export const PASS_WORD = '1231231231231';
// export const NEXUS_WEB_URL = "https://nexus-e2e.vercel.app/"
export const NEXUS_WEB_URL = 'http://localhost:3000/';
export const NEXUS_WEB_LOCAL_URL = 'http://localhost:3000/';
export const FULL_OWNERSHIP = 'fullOwnership';
export const RULE_BASED_OWNERSHIP = 'ruleBasedOwnership';
export const CKB_RPC = 'https://testnet.ckbapp.dev';
export const NEXUS_BUILD_PATH = './build';
7 changes: 7 additions & 0 deletions e2e/packages/e2e/__tests__/env.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { setCommitHashToReport } from './util';

describe('get Env', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems it is not a test case, maybe a setup step for global.

Please use globalSetup

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At that time, I made some adjustments in globalSetup, but it seemed that the Allure plugin had not been loaded yet, which resulted in an error. Therefore, I directly wrote it in the test case instead.

it('get nexus version', async () => {
await setCommitHashToReport();
});
});
Loading