Skip to content

Commit

Permalink
e2e tests (#216)
Browse files Browse the repository at this point in the history
* added e2e tests with adding images for saved layouts

* fixed checkbox check for e2e tests

* added disabled click action e2e test for saved layout

* added e2e tests for archive page pagination with "Load More" button, testing both post name and plain permalink structures

* added e2e tests for archive page pagination with Infinity, testing both post name and plain permalink structures

* Improved getWordpressImages e2e function: now we check image before add it to wordpress

* disabled no-console error for e2e archive tests

* added load more and infinity e2e archive tests and refactored all code. Now we used rest for adding and remove fixtures

* added e2e test fixtures for archive infinity and load more tests

* added additional timeout for fixed actions awaiting errors with rest

* added setPermalinkSettings running before each test

* added uploadMediaWithRetry function for getWordpressImages test method

* added archive debug artifacts task for e2e tests

* changed get terms rest method to POST

* changed afterAll methods priority calling

* added e2e additional checks for rest methods and error handlers

* added e2e retry mechanism for REST API calls in case of an error.

* changed e2e configuration timeout

* tested changed for check e2e logs

* returned e2e taxonomy rest method

* fixed e2e deletePortfolioTaxonomyTerms function and added logsEnabled for archive tests

* fixed php unit error

* Update playwright.config.js

* Update package.json

* added webp and gif formats to test images

compressed test images

* fixed a bug with displaying category links on archive pages

* improved archive tests: removed all delays and sped up the functions

* updated e2e archive fixtures and added categories to items

* limited e2e archive logging to an internal constant and added additional error handlers

* fixed methods of adding images for e2e tests: now images are loaded into the system once

* added await construction for checking image settings test

* added some logs for e2e checking image settings test

* added fixture existence validation to the e2e checking alternative image settings on saved layout test

---------

Co-authored-by: Nikita <[email protected]>
  • Loading branch information
Fellan-91 and nk-o authored Feb 5, 2025
1 parent 2ec5e5e commit 28c9afd
Show file tree
Hide file tree
Showing 36 changed files with 4,832 additions and 820 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/tests-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,46 @@ jobs:
- name: Run the tests
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test:e2e
- name: Archive debug artifacts (screenshots, traces)
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
if: ${{ !cancelled() }}
with:
name: failures-artifacts--${{ matrix.part }}
path: artifacts/test-results
if-no-files-found: ignore

- name: Archive flaky tests report
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
if: ${{ !cancelled() }}
with:
name: flaky-tests-report--${{ matrix.part }}
path: flaky-tests
if-no-files-found: ignore

merge-artifacts:
name: Merge Artifacts
if: ${{ !cancelled() }}
needs: [playwright]
runs-on: ubuntu-latest
outputs:
has-flaky-test-report: ${{ !!steps.merge-flaky-tests-reports.outputs.artifact-id }}
steps:
- name: Merge failures artifacts
uses: actions/upload-artifact/merge@v4
# Don't fail the job if there aren't any artifacts to merge.
continue-on-error: true
with:
name: failures-artifacts
# Retain the merged artifacts in case of a rerun.
pattern: failures-artifacts*
delete-merged: true

- name: Merge flaky tests reports
id: merge-flaky-tests-reports
uses: actions/upload-artifact/merge@v4
continue-on-error: true
with:
name: flaky-tests-report
pattern: flaky-tests-report*
delete-merged: true
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ jobs:
with:
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")

- name: Install SVN
run: sudo apt-get update && sudo apt-get install -y subversion

- name: Npm build
run: npm run build

Expand Down
16 changes: 13 additions & 3 deletions classes/class-archive-mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,10 +1317,20 @@ private function convert_category_to_friendly_url( $category_url ) {
}
$category_url = trailingslashit( $category_url );

if ( '' === $base_page ) {
$category_url = $category_url . $this->permalinks['category_base'] . '/' . $category_slug . '/';
// Replace the existing category part with the new category slug.
if ( strpos( $category_url, 'portfolio-category/' ) !== false ) {
$category_url = preg_replace(
'#(portfolio-category/)[^/]+/#',
'${1}' . $category_slug . '/',
$category_url
);
} else {
$category_url = str_replace( $base_page, $this->permalinks['category_base'] . '/' . $category_slug . '/', $category_url );
// If the category base is not found, append it manually.
if ( '' === $base_page ) {
$category_url = $category_url . $this->permalinks['category_base'] . '/' . $category_slug . '/';
} else {
$category_url = str_replace( $base_page, $this->permalinks['category_base'] . '/' . $category_slug . '/', $category_url );
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"bump:prerelease": "gulp bump --type prerelease",
"zip": "gulp zip",
"wp-env": "wp-env",
"env:start": "wp-env start ",
"env:start": "wp-env start",
"env:stop": "wp-env stop",
"test": "npm-run-all lint test:unit",
"env:destroy": "wp-env destroy",
"test": "npm-run-all lint test:unit:php test:e2e",
"test:e2e": "playwright test --config tests/e2e/playwright.config.js",
"test:e2e:ui": "playwright test --config tests/e2e/playwright.config.js --ui",
"pretest:unit:php": "wp-env start",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = defineConfig({
forbidOnly: !!process.env.CI,
workers: 1,
retries: process.env.CI ? 2 : 0,
timeout: parseInt(process.env.TIMEOUT || '', 10) || 100_000, // Defaults to 100 seconds.
timeout: parseInt(process.env.TIMEOUT || '', 10) || 200_000, // Defaults to 200 seconds.
// Don't report slow test "files", as we will be running our tests in serial.
reportSlowTests: null,
testDir: fileURLToPath(new URL('./specs', `file:${__filename}`).href),
Expand Down
Loading

0 comments on commit 28c9afd

Please sign in to comment.