Skip to content

Commit

Permalink
add intial e2e test boilerplate (TaggrNetwork#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev authored Apr 21, 2023
1 parent 55edebe commit a2a7922
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@

# rust
target/
release-artifacts/

# frontend code
node_modules/
dist/
public

# e2e tests
test-results/
playwright-report/
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@

# rust
target/
release-artifacts/

# frontend code
node_modules/
dist/
public

# e2e tests
test-results/
playwright-report/
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ RUN mkdir -p /opt/ic-wasm && \
# Install dfx
RUN sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"

# Install Playwright dependencies
RUN npx playwright install chromium --with-deps

COPY . .
RUN make build

ENTRYPOINT [ "./release.sh" ]
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@ build:
NODE_ENV=production make fe
./build.sh bucket
./build.sh taggr

test:
cargo clippy --tests --benches -- -D clippy::all
cargo test
shasum -a 256 target/wasm32-unknown-unknown/release/taggr.wasm.gz

fe:
rm -rf ./dist ./public
npm run build

e2e_test:
npx playwright install chromium --with-deps
make build
make start || true # don't fail if DFX is already running
make dev_deploy
npx playwright test
dfx stop

release:
docker build -t taggr .
docker run --rm --entrypoint cat taggr /target/wasm32-unknown-unknown/release/taggr.wasm.gz > release.wasm.gz
shasum -a 256 release.wasm.gz
docker run --rm -v $(shell pwd)/release-artifacts:/target/wasm32-unknown-unknown/release taggr
shasum -a 256 ./release-artifacts/taggr.wasm.gz
git rev-parse HEAD
23 changes: 15 additions & 8 deletions docs/LOCAL_DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

Make sure to follow the steps outlined in the rest of this file before using these commands.

| Description | Command |
| --------------------------- | --------------- |
| Build the canister | make build |
| Start the local replica | make start |
| Start the frontend server | npm start |
| Deploy the canister locally | make dev_deploy |
| Description | Command | Note |
| --------------------------- | --------------- | -------------------------------------------------- |
| Build the canister | make build | |
| Start the local replica | make start | |
| Start the frontend server | npm start | |
| Deploy the canister locally | make dev_deploy | |
| Run e2e tests | make e2e_test | If you're using Ubuntu, it must be an LTS version. |

## System Dependencies

Expand All @@ -35,12 +36,12 @@ cd taggr

The remaining steps are only necessary for deploying NNS canisters locally. This makes it easier to test new account creation with Internet Identity or to make ICP transfers to those accounts. Alternatively, you can [create a backup](#creating-and-restoring-backups) and then refer to the [command reference](#command-reference) to build and deploy.

Create or edit `~/.config/dfx/networks.json`, and add the following:
Create or edit `~/.config/dfx/networks.json`, and add the following, note that `dfx install` requires port `8080` to work:

```json
{
"local": {
"bind": "127.0.0.1:55554",
"bind": "127.0.0.1:8080",
"type": "ephemeral",
"replica": {
"subnet_type": "system"
Expand Down Expand Up @@ -93,6 +94,12 @@ Change to the new identity in DFX:
dfx identity use local-minter
```

Stop running DFX, Taggr is setup with the assumption that DFX runs on port `55554` so use the `make start` command from now on to start DFX:

```shell
dfx stop
```

At this point, you can refer to the [command reference](#command-reference) to deploy and run Taggr, create a new account and grab your account ID. Then you can transfer ICP to that account with this command:

```shell
Expand Down
13 changes: 13 additions & 0 deletions e2e/pages/home_page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Locator, Page } from "@playwright/test";

export class HomePage {
public readonly welcomeAboardHeader: Locator;

constructor(private readonly page: Page) {
this.welcomeAboardHeader = page.locator("h1");
}

public async goto(): Promise<void> {
await this.page.goto("/");
}
}
1 change: 1 addition & 0 deletions e2e/pages/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./home_page";
10 changes: 10 additions & 0 deletions e2e/tests/sanity_check.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test, expect } from "@playwright/test";
import { HomePage } from "../pages";

test("home page loads", async ({ page }) => {
const homePage = new HomePage(page);

await homePage.goto();

await expect(homePage.welcomeAboardHeader).toHaveText("Welcome aboard");
});
49 changes: 49 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"start": "webpack serve --mode development --env development"
},
"devDependencies": {
"@playwright/test": "^1.32.3",
"buffer": "6.0.3",
"copy-webpack-plugin": "^9.0.1",
"html-webpack-plugin": "5.5.0",
Expand Down
25 changes: 25 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { defineConfig, devices } from "@playwright/test";

export default defineConfig({
testDir: "./e2e",
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: "html",
use: {
baseURL: "http://127.0.0.1:8080",
trace: "on-first-retry",
},
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],
webServer: {
command: "npm run start",
url: "http://127.0.0.1:8080",
reuseExistingServer: !process.env.CI,
},
});
7 changes: 7 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

make build
make start
make dev_deploy
npx playwright test
dfx stop
2 changes: 1 addition & 1 deletion src/backend/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ impl State {
}

pub fn recompute_stalwarts(&mut self, now: u64) {
let mut users = self.users.values_mut().into_iter().collect::<Vec<_>>();
let mut users = self.users.values_mut().collect::<Vec<_>>();
users.sort_unstable_by_key(|a| std::cmp::Reverse(a.karma()));

let mut stalwart_seats = users.len() * CONFIG.stalwart_percentage / 100;
Expand Down
18 changes: 4 additions & 14 deletions src/backend/env/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ use ic_cdk::export::candid::Principal;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

#[derive(Clone, Deserialize, Debug, PartialEq, Serialize)]
#[derive(Clone, Default, Deserialize, Debug, PartialEq, Serialize)]
pub enum Status {
#[default]
Open,
Rejected,
Executed,
Cancelled,
}

impl Default for Status {
fn default() -> Self {
Status::Open
}
}

#[derive(Clone, Default, Serialize, Deserialize)]
pub struct Proposal {
pub id: u32,
Expand Down Expand Up @@ -128,19 +123,14 @@ impl Proposal {
}
}

#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Default, Serialize, Deserialize)]
pub enum Payload {
#[default]
Noop,
Release(Release),
Fund(String, Token),
}

impl Default for Payload {
fn default() -> Self {
Payload::Noop
}
}

impl Payload {
fn validate(&mut self) -> Result<(), String> {
match self {
Expand Down

0 comments on commit a2a7922

Please sign in to comment.