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: adding e2e tests for the dapp #73

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ jobs:
run: yarn lint
- name: yarn build
run: yarn build
- name: yarn test
run: yarn test
- name: yarn test:e2e
run: yarn test:e2e
integration:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These steps were removed for two reasons:

  1. The test in the file ui/test/App.e2e.ts were eliminated. The test was basic and focused on checking if the UI was functional, a task already covered by the e2e tests implicitly.

  2. Including these steps was causing a failure in our CI process. This failure was due to the involvement of tests in this PR defined in the e2e folder. Currently, I am in the process of setting up proper CI for our e2e tests, as detailed in this pull request.

Copy link
Member

Choose a reason for hiding this comment

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

I just realized... we took out yarn test?!

runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
.env

# Editor directories and files
.vscode/*
Expand All @@ -22,3 +23,7 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Synpress directories and files
screenshots
videos
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@
"test": "yarn workspaces run test",
"test:e2e": "yarn workspace offer-up-ui test:e2e",
"build": "yarn workspaces run build"
},
"devDependencies": {
"@agoric/synpress": "^3.8.1-beta.1",
"eslint-config-turbo": "^1.13.0",
"eslint-plugin-chai-friendly": "^0.7.4",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-testing-library": "^6.2.0",
"eslint-plugin-ui-testing": "^2.0.1"
Comment on lines +53 to +57
Copy link
Member

Choose a reason for hiding this comment

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

these are all needed by @agoric/synpress? maybe they should be dependencies so they're pulled in without this additional work and maintenance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they're required by @agoric/synpress.

And I was thinking the same about adding them as dependencies because it's been quite tedious to add them in every dapp I've worked with so far. Will discuss it with Fraz to confirm as he worked with the linting stuff.

}
}
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "vite",
"build": "tsc && vite build",
"test": "vitest spec",
"test:e2e": "vitest e2e",
"test:e2e": "EXTENSION=keplr synpress run --configFile=test/e2e/synpress.config.cjs",
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if I missed some docs somewhere. I get an error about SECRET_WORDS ...

$ yarn test:e2e
yarn run v1.22.21
$ yarn workspace offer-up-ui test:e2e
$ EXTENSION=keplr synpress run --configFile=test/e2e/synpress.config.cjs
/home/connolly/projects/dapp-offer-up/node_modules/@agoric/synpress/synpress.js:43
    throw new Error(
    ^

Error: Please provide SECRET_WORDS or PRIVATE_KEY environment variable

"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "yarn lint --fix",
"preview": "vite preview"
Expand Down
28 changes: 0 additions & 28 deletions ui/test/App.e2e.ts

This file was deleted.

10 changes: 10 additions & 0 deletions ui/test/e2e/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');
const cwd = process.cwd();
const directories = cwd.split(path.sep);
directories.pop();
const updatedPath = directories.join(path.sep);
const synpressPath = path.join(updatedPath, '/node_modules/@agoric/synpress');

module.exports = {
Copy link
Member

Choose a reason for hiding this comment

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

Why use .cjs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because in offer-up dApp we are using ES modules. But @agoric/synpress uses commonJS modules.

On line 24:
https://github.com/agoric-labs/synpress/blob/dev/package.json

Copy link
Member

Choose a reason for hiding this comment

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

That makes me curious why synpress uses commonJS. But I guess it's not critical.

extends: `${synpressPath}/.eslintrc.js`,
};
59 changes: 59 additions & 0 deletions ui/test/e2e/specs/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable ui-testing/no-disabled-tests */

describe('DAPP Offer Up E2E Test Cases', () => {
context('Test commands', () => {
it(`should complete Keplr setup by importing an existing wallet using 24 word phrase`, () => {
cy.setupWallet().then((setupFinished) => {
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

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

the import-24-words stuff is happening twice when I run the test. Is that by design?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dckc Yes it is by design. But it's something we are planning to remove in the next release of @agoric/synpress.

expect(setupFinished).to.be.true;
});
cy.visit('/');
});
it(`should reject connection with wallet`, () => {
const alertShown = cy.stub().as('alertShown');
cy.on('window:alert', alertShown);

cy.contains('Connect Wallet').click();
Copy link
Member

Choose a reason for hiding this comment

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

I'm struggling to get it to work.

yarn test:e2e results
$ SECRET_WORDS="powder bicycle deputy will move hen romance pear spring chest yard hunt cruise lumber host plug list trend alone frame sick define february copper" yarn test:e2e
yarn run v1.22.21
$ yarn workspace offer-up-ui test:e2e
$ EXTENSION=keplr synpress run --configFile=test/e2e/synpress.config.cjs
It looks like this is your first time using Cypress: 12.17.3

✔  Verified Cypress! /home/connolly/.cache/Cypress/12.17.3/Cypress

Opening Cypress...

=============================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        12.17.3                                                                        │
  │ Browser:        Chrome 123                                                                     │
  │ Node Version:   v20.11.1 (/home/connolly/.nvm/versions/node/v20.11.1/bin/node)                 │
  │ Specs:          1 found (test.spec.js)                                                         │
  │ Searched:       test/e2e/specs/**/*spec.{js,jsx,ts,tsx}                                        │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  test.spec.js                                                                    (1 of 1)


  DAPP Offer Up E2E Test Cases
    Test commands
      ✓ should complete Keplr setup by  importing an existing wallet using 24 word phrase (28048ms)
      1) should reject connection with wallet
      2) should accept connection with wallet
      3) should reject make an offer transaction
      4) should confirm make an offer transaction


  1 passing (2m)
  4 failing

  1) DAPP Offer Up E2E Test Cases
       Test commands
         should reject connection with wallet:
     AssertionError: Timed out retrying after 30000ms: Expected to find content: 'Connect Wallet' but never did.
      at Context.eval (webpack:///./specs/test.spec.js:15:9)

  2) DAPP Offer Up E2E Test Cases
       Test commands
         should accept connection with wallet:
     AssertionError: Timed out retrying after 30000ms: Expected to find content: 'Connect Wallet' but never did.
      at Context.eval (webpack:///./specs/test.spec.js:25:9)

  3) DAPP Offer Up E2E Test Cases
       Test commands
         should reject make an offer transaction:
     AssertionError: Timed out retrying after 30000ms: Expected to find content: 'Make an Offer' but never did.
      at Context.eval (webpack:///./specs/test.spec.js:34:9)

  4) DAPP Offer Up E2E Test Cases
       Test commands
         should confirm make an offer transaction:
     AssertionError: Timed out retrying after 30000ms: Expected to find content: 'Make an Offer' but never did.
      at Context.eval (webpack:///./specs/test.spec.js:48:9)




  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        5                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      4                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  4                                                                                │
  │ Video:        true                                                                             │
  │ Duration:     2 minutes, 28 seconds                                                            │
  │ Spec Ran:     test.spec.js                                                                     │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Screenshots)

  -  /home/connolly/projects/dapp-offer-up/ui/test/e2e/screenshots/test.spec.js/DAPP       (945x848)
     Offer Up E2E Test Cases -- Test commands -- should reject connection with wallet               
      (failed).png                                                                                  
  -  /home/connolly/projects/dapp-offer-up/ui/test/e2e/screenshots/test.spec.js/DAPP       (945x848)
     Offer Up E2E Test Cases -- Test commands -- should accept connection with wallet               
      (failed).png                                                                                  
  -  /home/connolly/projects/dapp-offer-up/ui/test/e2e/screenshots/test.spec.js/DAPP       (945x848)
     Offer Up E2E Test Cases -- Test commands -- should reject make an offer transact               
     ion (failed).png                                                                               
  -  /home/connolly/projects/dapp-offer-up/ui/test/e2e/screenshots/test.spec.js/DAPP       (945x848)
     Offer Up E2E Test Cases -- Test commands -- should confirm make an offer transac               
     tion (failed).png                                                                              


  (Video)

  -  Started compressing: Compressing to 32 CRF                                                     
  -  Finished compressing: 10 seconds                                                
    Compression progress:  100%

  -  Video output: /home/connolly/projects/dapp-offer-up/ui/test/e2e/videos/test.spec.js.mp4


=============================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✖  test.spec.js                             02:28        5        1        4        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✖  1 of 1 failed (100%)                     02:28        5        1        4        -        -  

Cypress run results: 5 total tests, 1 passed, 4 failed
error Command failed with exit code 4.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 4
Command: /home/connolly/.nvm/versions/node/v20.11.1/bin/node
Arguments: /home/connolly/.cache/node/corepack/yarn/1.22.21/lib/cli.js test:e2e
Directory: /home/connolly/projects/dapp-offer-up/ui
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
error Command failed with exit code 4.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Copy link
Member

@dckc dckc Apr 3, 2024

Choose a reason for hiding this comment

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

I tried again with the right mnemonic:

SECRET_WORDS="spike siege world rather ordinary upper napkin voice brush oppose junior route trim crush expire angry seminar anchor panther piano image pepper chest alone" yarn test:e2e

but the address shown in the test is agoric1p2aqakv3ulz4qfy2nut86j9gx0dx0yw09h96md. I don't know where that's coming from.
The "spike siege..." words correspond to agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk.

https://github.com/Agoric/agoric-3-proposals/blob/bf97facd3bb802e385933d4c29514e8faa21a98b/packages/synthetic-chain/src/lib/constants.js#L6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dckc This is actually a bug in @agoric/synpress.

At the moment, we hardcode the mnemonic:

'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology',

Adding an issue for it in @agoric/synpress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added it as an over here.

cy.rejectAccess().then((rejected) => {
expect(rejected).to.be.true;
});
cy.get('@alertShown').should(
'have.been.calledOnceWith',
'Request rejected'
);
});
it(`should accept connection with wallet`, () => {
cy.contains('Connect Wallet').click();
cy.acceptAccess().then((taskCompleted) => {
expect(taskCompleted).to.be.true;
});
});
it(`should reject make an offer transaction`, () => {
const alertShown = cy.stub().as('alertShown');
cy.on('window:alert', alertShown);

cy.contains('Make an Offer').click();
cy.rejectTransaction().then((taskCompleted) => {
expect(taskCompleted).to.be.true;
});

cy.get('@alertShown').should(
'have.been.calledOnceWith',
'Offer error: Error: Request rejected'
);
});
it(`should confirm make an offer transaction`, () => {
const alertShown = cy.stub().as('alertShown');
cy.on('window:alert', alertShown);

cy.contains('Make an Offer').click();
cy.confirmTransaction().then((taskCompleted) => {
expect(taskCompleted).to.be.true;
});

cy.get('@alertShown').should(
'have.been.calledOnceWith',
'Offer accepted'
);
});
});
});
14 changes: 14 additions & 0 deletions ui/test/e2e/synpress.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const config = require('@agoric/synpress/synpress.config');
const { defineConfig } = require('cypress');

module.exports = defineConfig({
Copy link
Member

Choose a reason for hiding this comment

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

why .cjs?

...config,
e2e: {
...config.e2e,
baseUrl: 'http://localhost:5173',
specPattern: 'test/e2e/specs/**/*spec.{js,jsx,ts,tsx}',
supportFile: 'test/support.js',
screenshotsFolder: 'test/e2e/screenshots',
videosFolder: 'test/e2e/videos'
},
});
1 change: 1 addition & 0 deletions ui/test/support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@agoric/synpress/support/index';
Loading
Loading