Skip to content

Commit

Permalink
feat: Performance Tests (#924)
Browse files Browse the repository at this point in the history
* feat: Performance Tests

Added Performance tests

* feat: Performance Tests

Updated scripts

* try direct script

* Add tests for release branches

* Version Bumps

---------

Co-authored-by: Alex Risch <alex@xmtp.com>
  • Loading branch information
alexrisch and Alex Risch authored Oct 17, 2024
1 parent d81f822 commit eb9c49d
Show file tree
Hide file tree
Showing 9 changed files with 774 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check-android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- release/*
paths:
- "android/**"
- "package.json"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/check-ios-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- release/*
paths:
- "ios/**"
- "package.json"
Expand Down
56 changes: 46 additions & 10 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,77 @@ on:
pull_request:
branches:
- main

- release/*
paths:
- "**/*.ts"
- "**/*.tsx"
- "package.json"
jobs:
tsc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4.0.2
- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
cache: "yarn"
- run: yarn
- run: yarn typecheck
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4.0.2
- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
cache: "yarn"
- run: yarn
- run: yarn lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4.0.2
- uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 20.x
cache: "yarn"
- run: yarn
- run: yarn test
performance-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "yarn"
- run: |
BASELINE_BRANCH=${GITHUB_BASE_REF:="main"}
# Required for `git switch` on CI
git fetch origin
# Gather baseline perf measurements
git switch "$BASELINE_BRANCH"
yarn
yarn reassure --baseline
# Gather current perf measurements & compare results
git switch --detach -
yarn
yarn reassure --branch
- name: Run Danger.js
run: yarn danger ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ builds

# iOS
ios/Converse.xcworkspace/xcshareddata/swiftpm/Package.resolved
# Reassure output directory
.reassure
48 changes: 48 additions & 0 deletions components/__tests__/Avatar.perf-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { jest, test } from "@jest/globals";
import { screen } from "@testing-library/react-native";
import React from "react";
import { measureRenders } from "reassure";

import Avatar from "../Avatar";

jest.setTimeout(600_000);

const TestComponent = ({ uri }: { uri?: string }) => <Avatar uri={uri} />;

test("Empty Avatar 10 runs", async () => {
const scenario = async () => {
await screen.findByTestId("avatar-placeholder");
};

await measureRenders(<TestComponent />, { scenario, runs: 10 });
});

test("Empty Avatar 50 runs", async () => {
const scenario = async () => {
await screen.findByTestId("avatar-placeholder");
};

await measureRenders(<TestComponent />, { scenario, runs: 50 });
});

test("Avatar Image 10 runs", async () => {
const scenario = async () => {
await screen.findByTestId("avatar-image");
};

await measureRenders(<TestComponent uri="https://picsum.photos/200/300" />, {
scenario,
runs: 10,
});
});

test("Avatar Image 50 runs", async () => {
const scenario = async () => {
await screen.findByTestId("avatar-image");
};

await measureRenders(<TestComponent uri="https://picsum.photos/200/300" />, {
scenario,
runs: 50,
});
});
7 changes: 7 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
import path from 'path';
import { dangerReassure } from 'reassure';

dangerReassure({
inputFilePath: path.join(__dirname, './.reassure/output.md'),
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"ios": "EXPO_ENV=dev expo start --ios",
"postinstall": "patch-package && node scripts/wasm.js && husky install && cross-os postinstall",
"start": "EXPO_ENV=dev expo start",
"test": "echo \"➜ Running tests...\" && jest",
"test": "echo \"➜ Running tests...\" && jest --testPathIgnorePatterns='.*\\.perf-test\\.tsx$'",
"test:perf": "echo \"➜ Running tests with performance...\" && echo \"➜ Capture baseline performance tests...\" && yarn reassure --baseline && echo \"➜ Running current performance tests...\" && jest --testPathIgnorePatterns='.*\\.perf-test\\.tsx$'",
"typecheck": "echo \"➜ Typechecking project...\" && tsc --noEmit",
"update": "node scripts/build/update.js",
"web:preview": "EXPO_ENV=preview expo export -p web"
Expand Down Expand Up @@ -218,6 +219,7 @@
"@typescript-eslint/typescript-estree": "^6.3.0",
"@welldone-software/why-did-you-render": "^8.0.3",
"cross-os": "^1.5.0",
"danger": "^12.3.3",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-universe": "^12.0.0",
Expand All @@ -237,6 +239,7 @@
"plist": "^3.0.6",
"prettier": "^3.0.1",
"process": "^0.11.10",
"reassure": "^1.2.1",
"sqlite3": "^5.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.3.0",
Expand Down
19 changes: 19 additions & 0 deletions reassure-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e

BASELINE_BRANCH=${GITHUB_BASE_REF:="main"}

# Required for `git switch` on CI
git fetch origin

# Gather baseline perf measurements
git switch "$BASELINE_BRANCH"

yarn
yarn reassure --baseline

# Gather current perf measurements & compare results
git switch --detach -

yarn
yarn reassure --branch
Loading

0 comments on commit eb9c49d

Please sign in to comment.