Skip to content

Commit 227fb5f

Browse files
authored
Merge pull request #89 from codebtech/feat/perf-tests
Feat/perf tests
2 parents af47de8 + 9d354a9 commit 227fb5f

File tree

9 files changed

+655
-69
lines changed

9 files changed

+655
-69
lines changed

.github/workflows/perf-tests.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Performance Tests
2+
on:
3+
push:
4+
branches-ignore:
5+
- 'main-built'
6+
pull_request:
7+
8+
jobs:
9+
performance-tests:
10+
name: 'Performance Tests'
11+
runs-on: ubuntu-latest
12+
env:
13+
WP_BASE_URL: 'http://localhost:8888'
14+
WP_USERNAME: 'admin'
15+
WP_PASSWORD: 'password'
16+
WP_AUTH_STORAGE: '.auth/wordpress.json'
17+
WP_ARTIFACTS_PATH: ${{ github.workspace }}/artifacts
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version-file: '.nvmrc'
26+
cache: yarn
27+
28+
- name: Cache Composer dependencies
29+
uses: actions/cache@v4
30+
with:
31+
path: /tmp/composer-cache
32+
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
33+
34+
- name: Setup composer
35+
uses: php-actions/composer@v6
36+
with:
37+
php_version: '8.3'
38+
dev: no
39+
40+
- name: Install dependencies
41+
run: yarn install --immutable
42+
43+
- name: Build packages
44+
run: yarn build
45+
46+
- name: Playwright install
47+
run: yarn playwright install chromium
48+
49+
- name: Start wp-env
50+
run: yarn wp-env
51+
52+
- name: Run tests
53+
run: |
54+
yarn test:performance
55+
mv ${{ env.WP_ARTIFACTS_PATH }}/performance-results.json ${{ runner.temp }}/results_after.json
56+
57+
- name: Check out base commit
58+
run: |
59+
if [[ -z "$BASE_REF" ]]; then
60+
git fetch -n origin $BASE_SHA
61+
git reset --hard $BASE_SHA
62+
else
63+
git fetch -n origin $BASE_REF
64+
git reset --hard $BASE_SHA
65+
fi
66+
env:
67+
BASE_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || '' }}
68+
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
69+
70+
# Run tests without causing job to fail if they don't pass (e.g. because of env issues).
71+
- name: Run tests for base
72+
run: |
73+
npm run test:performance || true
74+
if [ -f "{{ env.WP_ARTIFACTS_PATH }}/performance-results.json" ]; then
75+
mv ${{ env.WP_ARTIFACTS_PATH }}/performance-results.json ${{ runner.temp }}/results_before.json
76+
fi;
77+
78+
- name: Reset to original commit
79+
run: |
80+
git reset --hard $GITHUB_SHA
81+
82+
- name: Compare results with base
83+
run: |
84+
if [ -f "${{ runner.temp }}/results_before.json" ]; then
85+
yarn test:performance:results ${{ runner.temp }}/results_after.json ${{ runner.temp }}/results_before.json
86+
else
87+
yarn test:performance:results ${{ runner.temp }}/results_after.json
88+
fi;
89+
90+
- name: Add workflow summary
91+
run: |
92+
cat ${{ env.WP_ARTIFACTS_PATH }}/performance-results.md >> $GITHUB_STEP_SUMMARY
93+
94+
- name: Upload performance results
95+
if: success()
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: performance-results
99+
path: ${{ env.WP_ARTIFACTS_PATH }}/performance-results.json

jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ module.exports = {
55
},
66
modulePathIgnorePatterns: ['<rootDir>/vendor/'],
77
testEnvironment: 'jsdom',
8-
testPathIgnorePatterns: ['<rootDir>/tests/e2e/'],
8+
testPathIgnorePatterns: [
9+
'<rootDir>/tests/e2e/',
10+
'<rootDir>/tests/performance/',
11+
],
912
collectCoverage: true,
1013
coverageReporters: ['text', 'cobertura'],
1114
};

package.json

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,72 @@
11
{
2-
"name": "codeb-feature-flags",
3-
"version": "0.3.2",
4-
"description": "Allows developers to enable / disable features based on flags.",
5-
"license": "ISC",
6-
"author": "Mohan Raj <https://mohanraj.dev>",
7-
"scripts": {
8-
"build": "wp-scripts build",
9-
"lint:css": "wp-scripts lint-style",
10-
"lint:css:fix": "npm run lint:css -- --fix",
11-
"lint:js": "wp-scripts lint-js",
12-
"lint:js:fix": "wp-scripts lint-js --fix",
13-
"prepare": "husky",
14-
"start": "wp-scripts start",
15-
"test:e2e": "wp-scripts test-playwright",
16-
"test:js": "wp-scripts test-unit-js",
17-
"test:watch": "wp-scripts test-unit-js --watch",
18-
"version:major": "node ./scripts/version major",
19-
"version:minor": "node ./scripts/version minor",
20-
"version:patch": "node ./scripts/version patch",
21-
"wp-env": "wp-env start",
22-
"wp-env:coverage": "wp-env start --xdebug=coverage",
23-
"php:unit": "wp-env run --env-cwd='wp-content/plugins/feature-flags' tests-wordpress composer test:unit",
24-
"php:integration": "wp-env run tests-wordpress --env-cwd=wp-content/plugins/feature-flags composer test:integration",
25-
"php:multisite": "wp-env run tests-wordpress --env-cwd=wp-content/plugins/feature-flags composer test:multisite"
26-
},
27-
"dependencies": {
28-
"@testing-library/user-event": "^14.5.2",
29-
"@wordpress/api-fetch": "^6.48.0",
30-
"@wordpress/components": "^27.1.0",
31-
"@wordpress/data": "^9.23.0",
32-
"@wordpress/dom-ready": "^3.53.0",
33-
"@wordpress/hooks": "^3.53.0",
34-
"@wordpress/i18n": "^4.53.0",
35-
"@wordpress/notices": "^4.21.0",
36-
"dotenv": "^16.4.5",
37-
"react": "18.2.0",
38-
"react-dom": "18.2.0",
39-
"react-syntax-highlighter": "^15.5.0",
40-
"react-test-renderer": "^18.2.0",
41-
"ts-loader": "^9.5.1",
42-
"typescript": "^5.4.2"
43-
},
44-
"devDependencies": {
45-
"@playwright/test": "^1.42.1",
46-
"@testing-library/jest-dom": "^6.4.2",
47-
"@testing-library/react": "14.2.1",
48-
"@types/jest": "^29.5.12",
49-
"@types/node": "^20.11.25",
50-
"@types/react-syntax-highlighter": "^15.5.11",
51-
"@types/wordpress__components": "^23.0.11",
52-
"@wordpress/e2e-test-utils-playwright": "^0.21.0",
53-
"@wordpress/env": "^9.5.0",
54-
"@wordpress/eslint-plugin": "^17.10.0",
55-
"@wordpress/scripts": "^27.4.0",
56-
"eslint": "^8.57.0",
57-
"eslint-import-resolver-alias": "^1.1.2",
58-
"eslint-plugin-cypress": "^2.15.1",
59-
"eslint-plugin-import": "^2.29.1",
60-
"husky": "^9.0.11",
61-
"jest-environment-jsdom": "^29.7.0",
62-
"prettier": "^3.2.5"
63-
},
64-
"keywords": [
65-
"feature flags",
66-
"wordpress",
67-
"plugin"
68-
]
2+
"name": "codeb-feature-flags",
3+
"version": "0.3.2",
4+
"description": "Allows developers to enable / disable features based on flags.",
5+
"license": "ISC",
6+
"author": "Mohan Raj <https://mohanraj.dev>",
7+
"scripts": {
8+
"build": "wp-scripts build",
9+
"lint:css": "wp-scripts lint-style",
10+
"lint:css:fix": "npm run lint:css -- --fix",
11+
"lint:js": "wp-scripts lint-js",
12+
"lint:js:fix": "wp-scripts lint-js --fix",
13+
"prepare": "husky",
14+
"start": "wp-scripts start",
15+
"test:e2e": "wp-scripts test-playwright",
16+
"test:js": "wp-scripts test-unit-js",
17+
"test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.ts",
18+
"test:performance:merge-reports": "playwright merge-reports --reporter tests/performance/config/performance-reporter.ts ./blob-report",
19+
"test:performance:results": "node tests/performance/cli/results.js",
20+
"test:watch": "wp-scripts test-unit-js --watch",
21+
"version:major": "node ./scripts/version major",
22+
"version:minor": "node ./scripts/version minor",
23+
"version:patch": "node ./scripts/version patch",
24+
"wp-env": "wp-env start",
25+
"wp-env:coverage": "wp-env start --xdebug=coverage",
26+
"php:unit": "wp-env run --env-cwd='wp-content/plugins/feature-flags' tests-wordpress composer test:unit",
27+
"php:integration": "wp-env run tests-wordpress --env-cwd=wp-content/plugins/feature-flags composer test:integration",
28+
"php:multisite": "wp-env run tests-wordpress --env-cwd=wp-content/plugins/feature-flags composer test:multisite"
29+
},
30+
"dependencies": {
31+
"@testing-library/user-event": "^14.5.2",
32+
"@wordpress/api-fetch": "^6.48.0",
33+
"@wordpress/components": "^27.1.0",
34+
"@wordpress/data": "^9.23.0",
35+
"@wordpress/dom-ready": "^3.53.0",
36+
"@wordpress/hooks": "^3.53.0",
37+
"@wordpress/i18n": "^4.53.0",
38+
"@wordpress/notices": "^4.21.0",
39+
"dotenv": "^16.4.5",
40+
"react": "18.2.0",
41+
"react-dom": "18.2.0",
42+
"react-syntax-highlighter": "^15.5.0",
43+
"react-test-renderer": "^18.2.0",
44+
"ts-loader": "^9.5.1",
45+
"typescript": "^5.4.2"
46+
},
47+
"devDependencies": {
48+
"@playwright/test": "^1.42.1",
49+
"@testing-library/jest-dom": "^6.4.2",
50+
"@testing-library/react": "14.2.1",
51+
"@types/jest": "^29.5.12",
52+
"@types/node": "^20.11.25",
53+
"@types/react-syntax-highlighter": "^15.5.11",
54+
"@types/wordpress__components": "^23.0.11",
55+
"@wordpress/e2e-test-utils-playwright": "^0.21.0",
56+
"@wordpress/env": "^9.5.0",
57+
"@wordpress/eslint-plugin": "^17.10.0",
58+
"@wordpress/scripts": "^27.4.0",
59+
"eslint": "^8.57.0",
60+
"eslint-import-resolver-alias": "^1.1.2",
61+
"eslint-plugin-cypress": "^2.15.1",
62+
"eslint-plugin-import": "^2.29.1",
63+
"husky": "^9.0.11",
64+
"jest-environment-jsdom": "^29.7.0",
65+
"prettier": "^3.2.5"
66+
},
67+
"keywords": [
68+
"feature flags",
69+
"wordpress",
70+
"plugin"
71+
]
6972
}

src/components/modals/__tests__/SdkModal.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SdkModal from '../SdkModal';
44

55
describe('SdkModal component', () => {
66
test('should render modal correctly', async () => {
7-
const item = { name: 'Test Flag' };
7+
const item = { id: 1, name: 'Test Flag', enabled: false };
88
const closeSdkModal = jest.fn();
99
render(<SdkModal item={item} closeSdkModal={closeSdkModal} />);
1010

0 commit comments

Comments
 (0)