-
Notifications
You must be signed in to change notification settings - Fork 206
460 lines (406 loc) · 17.4 KB
/
e2e_api_tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
name: E2E_API Tests
on:
# workflow will run daily at 8:00 AM BDT (2:00 AM UTC)
schedule:
- cron: 0 2 * * *
# workflow will trigger on pull request
pull_request:
branches: [develop]
# workflow will trigger on push to develop branch
push:
branches: [develop]
# workflow can be manually triggered
workflow_dispatch:
inputs:
testsuite:
description: Choose which test suite to run
default: All
type: choice
options:
- E2E
- API
- All
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
# workflow permissions
permissions:
checks: write
contents: write
issues: write
pull-requests: write
# workflow environment variables
env:
ADMIN: admin
ADMIN_PASSWORD: password
VENDOR: vendor1
VENDOR2: vendor2
CUSTOMER: customer1
CUSTOMER2: customer2
USER_PASSWORD: 01dokan01
GMAP: ${{secrets.GMAP}}
MAPBOX: ${{secrets.MAPBOX}}
BASE_URL: http://localhost:9999
CI: true
FORCE_COLOR: 1
DB_HOST_NAME: localhost
DB_USER_NAME: root
DB_USER_PASSWORD: password
DB_PORT: 9998
DATABASE: tests-wordpress
DB_PREFIX: wp
PR_NUMBER: ${{ github.event.number }}
SHA: ${{ github.event.pull_request.head.sha }}
SYSTEM_INFO: ./tests/pw/playwright/systemInfo.json
API_TEST_RESULT: ./tests/pw/playwright-report/api/summary-report/results.json
E2E_TEST_RESULT: ./tests/pw/playwright-report/e2e/summary-report/results.json
API_COVERAGE: ./tests/pw/playwright-report/api/coverage-report/coverage.json
E2E_COVERAGE: ./tests/pw/playwright-report/e2e/coverage-report/coverage.json
jobs:
e2e_tests:
name: e2e tests
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3]
shardTotal: [3]
steps:
# Checkout testing repo
- name: Checkout testing repo
id: clone-dokan-lite
uses: actions/checkout@v4
# Use desired version of NodeJS
- name: Use desired version of NodeJS
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
# Composer install and build (Dokan-lite)
- name: Composer install and build (Dokan-lite)
run: |
composer i --no-dev -o || composer update --no-dev -o
# Npm install and build (Dokan-lite)
- name: Npm install and build (Dokan-lite)
run: |
npm ci || npm i
npm run build
# Install test dependencies
- name: Install test dependencies
working-directory: tests/pw
run: |
npm ci || npm i
# Create wp debuglog file
- name: Create wp debuglog file
id: debug-log
working-directory: tests/pw
run: |
mkdir -p wp-data && touch wp-data/debug.log
# Start wordpress environment
- name: Start WordPress Env
id: wp-env
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 2
retry_on: error
command: |
cd tests/pw
npm run start:env
# Get Playwright version
- name: Get installed Playwright version
id: playwright-version
working-directory: tests/pw
run: |
echo "PLAYWRIGHT_VERSION=$(npm ls @playwright/test --json | jq --raw-output '.dependencies["@playwright/test"].version')" >> "$GITHUB_ENV"
# Cache browser binaries, cache key is based on Playwright version and OS
- name: Cache playwright binaries
id: playwright-cache
uses: actions/cache@v4
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
restore-keys: |
${{ runner.os }}-playwright-
# Install browser binaries & OS dependencies if cache missed
- name: Install Playwright browser binaries & OS dependencies
id: pw-install
if: steps.playwright-cache.outputs.cache-hit != 'true'
working-directory: tests/pw
run: |
npm run pw:chrome-with-deps
# # Install only the OS dependencies if cache hit
# - name: Install Playwright OS dependencies
# if: steps.playwright-cache.outputs.cache-hit == 'true'
# working-directory: tests/pw
# run: |
# npm run pw:chrome-deps-only
# Run E2E tests
- name: 🧪 Run e2e tests-${{ matrix.shardIndex }}
id: e2e-test
if: success() && (github.event_name != 'workflow_dispatch' || ( github.event_name == 'workflow_dispatch' && (github.event.inputs.testsuite == 'E2E' || github.event.inputs.testsuite == 'All')))
timeout-minutes: 15
working-directory: tests/pw
run: |
npm run test:e2e -- --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
# Run e2e coverage
- name: 🧪 Run e2e coverage
if: always() && (steps.e2e-test.outcome == 'success' || steps.e2e-test.outcome == 'failure')
working-directory: tests/pw
run: |
npm run test:e2e:coverage
# # Prepare test summary
# - name: Prepare test summary
# id: prepare-test-summary
# uses: actions/github-script@v7
# if: always() && steps.clone-dokan-lite.outcome == 'success'
# with:
# result-encoding: string
# script: |
# const script = require("./tests/pw/utils/gitTestSummary.ts")
# return await script({github, context, core})
# Backup Database
- name: Backup Database
if: always() && steps.wp-env.outcome == 'success'
working-directory: tests/pw
run: |
npm run wp-env run tests-cli wp db export wp-data/db.sql
# Upload artifacts
- name: Archive test artifacts (screenshots, HTML snapshots, Reports)
if: always() && steps.debug-log.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: test-artifact-e2e-${{ matrix.shardIndex }}
path: |
tests/pw/wp-data
tests/pw/playwright
tests/pw/playwright-report
if-no-files-found: ignore
retention-days: 1
api_tests:
name: api tests
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
shardIndex: [1]
shardTotal: [1]
steps:
# Checkout testing repo
- name: Checkout testing repo
id: clone-dokan-lite
uses: actions/checkout@v4
# Use desired version of NodeJS
- name: Use desired version of NodeJS
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
# Composer install and build (Dokan-lite)
- name: Composer install and build (Dokan-lite)
run: |
composer i --no-dev -o || composer update --no-dev -o
# Npm install and build (Dokan-lite)
- name: Npm install and build (Dokan-lite)
run: |
npm ci || npm i
npm run build
# Install test dependencies
- name: Install test dependencies
working-directory: tests/pw
run: |
npm ci || npm i
# Create wp debuglog file
- name: Create wp debuglog file
id: debug-log
working-directory: tests/pw
run: |
mkdir -p wp-data && touch wp-data/debug.log
# Start wordpress environment
- name: Start WordPress Env
id: wp-env
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 2
retry_on: error
command: |
cd tests/pw
npm run start:env
# Get Playwright version
- name: Get installed Playwright version
id: playwright-version
working-directory: tests/pw
run: |
echo "PLAYWRIGHT_VERSION=$(npm ls @playwright/test --json | jq --raw-output '.dependencies["@playwright/test"].version')" >> "$GITHUB_ENV"
# Cache browser binaries, cache key is based on Playwright version and OS
- name: Cache playwright binaries
id: playwright-cache
uses: actions/cache@v4
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
restore-keys: |
${{ runner.os }}-playwright-
# Install browser binaries & OS dependencies if cache missed
- name: Install Playwright browser binaries & OS dependencies
id: pw-install
if: steps.playwright-cache.outputs.cache-hit != 'true'
working-directory: tests/pw
run: |
npm run pw:chrome-with-deps
# # Install only the OS dependencies if cache hit
# - name: Install Playwright OS dependencies
# if: steps.playwright-cache.outputs.cache-hit == 'true'
# working-directory: tests/pw
# run: |
# npm run pw:chrome-deps-only
# Run API tests
- name: 🧪 Run api tests-${{ matrix.shardIndex }}
id: api-test
if: always() && steps.wp-env.outcome == 'success' && ( github.event_name != 'workflow_dispatch' || ( github.event_name == 'workflow_dispatch' && (github.event.inputs.testsuite == 'API' || github.event.inputs.testsuite == 'All')))
timeout-minutes: 5
working-directory: tests/pw
run: |
npm run test:api -- --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
# # Prepare test summary
# - name: Prepare test summary
# id: prepare-test-summary
# if: always() && steps.clone-dokan-lite.outcome == 'success'
# uses: actions/github-script@v7
# with:
# result-encoding: string
# script: |
# const script = require("./tests/pw/utils/gitTestSummary.ts")
# return await script({github, context, core})
# Backup Database
- name: Backup Database
if: always() && steps.wp-env.outcome == 'success'
working-directory: tests/pw
run: |
npm run wp-env run tests-cli wp db export wp-data/db.sql
# Upload artifacts
- name: Archive test artifacts (screenshots, HTML snapshots, Reports)
if: always() && steps.debug-log.outcome == 'success'
uses: actions/upload-artifact@v4
with:
# name: test-artifact-api-${{ matrix.shardIndex }}
name: test-artifact-api
path: |
tests/pw/wp-data
tests/pw/playwright
tests/pw/playwright-report
if-no-files-found: ignore
retention-days: 1
merge-reports:
# Merge reports after playwright-tests, even if some shards have failed
if: ${{ !cancelled() }}
needs: [e2e_tests, api_tests]
runs-on: ubuntu-24.04
timeout-minutes: 5
# Override reports path specifically for this job
env:
API_TEST_RESULT: ./tests/pw/all-reports/test-artifact-api/playwright-report/api/summary-report/results.json
API_COVERAGE: ./tests/pw/all-reports/test-artifact-api/playwright-report/api/coverage-report/coverage.json
E2E_TEST_RESULT: ./tests/pw/all-reports/merged-summary.json
E2E_COVERAGE: ./tests/pw/all-reports/merged-coverage.json
steps:
# Checkout testing repo
- name: Checkout testing repo
id: clone-dokan-lite
uses: actions/checkout@v4
# Use desired version of NodeJS
- name: Use desired version of NodeJS
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
# Install test dependencies
- name: Install test dependencies
working-directory: tests/pw
run: |
npm ci || npm i
# Download all test artifacts from GitHub Actions
- name: Download all test artifacts from GitHub Actions
id: download-test-artifacts
uses: actions/download-artifact@v4
with:
path: tests/pw/all-reports
pattern: test-artifact-*
# Move all blob report folder contents into a single folder
- name: Move all blob report folder contents into a single folder
working-directory: tests/pw/all-reports
run: |
mkdir -p all-blob-reports
find . -type f -path "*/blob-report/*" -exec mv {} all-blob-reports/ \;
# ls all-blob-reports
# Generate HTML Report
- name: Generate HTML Report
id: generate-html-report
working-directory: tests/pw
run: |
npx playwright merge-reports --reporter html ./all-reports/all-blob-reports
mv playwright-report ./all-reports/html-report
# Clean all extracted blob reports (except ZIPs)
- name: Clean all extracted blob reports (except ZIPs)
working-directory: tests/pw
run: |
find all-reports/all-blob-reports -mindepth 1 ! -name "*.zip" -exec rm -rf {} +
# Generate merged summary report
- name: Generate merged summary report
id: merge-summary-report
if: steps.download-test-artifacts.outcome == 'success'
working-directory: tests/pw
run: |
REPORT_TYPE=e2e npx ts-node ./utils/mergeSummaryReport.ts
# Generate merged coverage report
- name: Generate merged coverage report
id: merge-coverage-report
if: steps.download-test-artifacts.outcome == 'success'
working-directory: tests/pw
run: |
REPORT_TYPE=e2e npx ts-node ./utils/mergeCoverageSummary.ts
# Prepare test summary
- name: Prepare test summary
id: prepare-test-summary
if: always() && steps.merge-summary-report.outcome == 'success'
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const script = require("./tests/pw/utils/gitTestSummary.ts")
return await script({github, context, core})
# # Find PR comment
# - name: Find PR comment by github-actions[bot]
# id: find-comment
# if: github.event_name == 'pull_request'
# uses: peter-evans/find-comment@v3
# with:
# issue-number: ${{ github.event.pull_request.number }}
# comment-author: 'github-actions[bot]'
# body-includes: Tests Summary
# # Post test summary as PR comment
# - name: Create or update PR comment
# if: github.event_name == 'pull_request'
# uses: peter-evans/create-or-update-comment@v4
# with:
# comment-id: ${{ steps.find-comment.outputs.comment-id }}
# issue-number: ${{ github.event.pull_request.number }}
# body: ${{ steps.prepare-test-summary.outputs.result }}
# reactions: hooray
# edit-mode: replace
# Upload final test artifact
- name: Upload final test artifact
if: always() && steps.download-test-artifacts.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: final-test-artifact
path: tests/pw/all-reports
if-no-files-found: ignore
retention-days: 7