Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/playwright-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,12 @@ jobs:
mkdir -p test-results/ci
suffix="${{ inputs.project-name }}${{ inputs.multisite && '-multisite' || '' }}"
: > "test-results/ci/playwright-${suffix}.log"
# shellcheck disable=SC2086 -- project-name may hold several names.
npm run test:playwright -- --project ${{ inputs.project-name }} 2>&1 | tee -a "test-results/ci/playwright-${suffix}.log"
# One --project flag per name, so several projects can be listed in the input.
project_args=()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
for project in ${{ inputs.project-name }}; do
Comment thread
coderabbitai[bot] marked this conversation as resolved.
project_args+=(--project "$project")
done
npm run test:playwright -- "${project_args[@]}" 2>&1 | tee -a "test-results/ci/playwright-${suffix}.log"
Comment thread
TallblokeUK marked this conversation as resolved.

- name: Normalize Playwright report filenames
if: always()
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/helpers/rtlUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { join } from 'path'

// The right-to-left specs sign in as an account of their own, so the rest of
// the suite never sees the site mirrored. These names are shared by the setup
// that creates the session and the teardown that removes the account.
export const RTL_LOCALE = 'he_IL'
export const RTL_USER = 'cs-e2e-rtl'

export const rtlAuthFile = join(__dirname, '..', '.auth', 'rtl-user.json')

// Records whether a run created the user, so the teardown only removes an
// account it made and never one that already existed on the site.
export const rtlCreatedMarker = join(__dirname, '..', '.auth', 'rtl-user-created')
4 changes: 3 additions & 1 deletion tests/e2e/list-toolbar-fit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ test.describe('Snippets toolbar fit', () => {
const t = toggle.getBoundingClientRect()
return {
pageOverflow: document.documentElement.scrollWidth - document.documentElement.clientWidth,
toggleInsideNav: t.left >= n.left - 1 && t.right <= n.right + 1
toggleInsideNav: t.left >= n.left - 1 && t.right <= n.right + 1,
wraps: 'wrap' === getComputedStyle(nav).flexWrap
}
})

expect(fit.wraps, 'the row collapses onto two lines up to 1400px and not above').toBe(1400 >= width)
expect(fit.pageOverflow).toBeLessThanOrEqual(0)
expect(fit.toggleInsideNav).toBe(true)
})
Expand Down
11 changes: 6 additions & 5 deletions tests/e2e/rtl.setup.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { join } from 'path'
import { writeFileSync } from 'fs'
import { expect, test as setup } from '@playwright/test'
import { RTL_LOCALE, RTL_USER, rtlAuthFile, rtlCreatedMarker } from './helpers/rtlUser'
import { wpCli } from './helpers/wpCli'

// The RTL specs sign in as a user of their own whose locale is right-to-left,
// so the rest of the suite, which signs in as the usual admin, never sees the
// site mirrored, whatever order the projects run in. The language pack is
// fetched from wordpress.org when missing; if that is impossible (offline),
// the specs notice the page is still left-to-right and skip themselves.
const RTL_LOCALE = 'he_IL'
const RTL_USER = 'rtl-admin'
const SETUP_TIMEOUT_MS = 180000

export const rtlAuthFile = join(__dirname, '.auth/rtl-user.json')

setup('sign in as a right-to-left user', async ({ page }) => {
setup.setTimeout(SETUP_TIMEOUT_MS)

Expand All @@ -23,12 +20,16 @@ setup('sign in as a right-to-left user', async ({ page }) => {
}

// `user create` takes no locale flag, so the locale is set by a second command.
let created = false

try {
await wpCli(['user', 'get', RTL_USER, '--field=ID'])
} catch {
await wpCli(['user', 'create', RTL_USER, `${RTL_USER}@example.org`, '--role=administrator'])
created = true
}

writeFileSync(rtlCreatedMarker, created ? 'created' : 'existing')
await wpCli(['user', 'update', RTL_USER, '--user_pass=password', `--locale=${RTL_LOCALE}`])

await page.goto('/wp-login.php')
Expand Down
18 changes: 13 additions & 5 deletions tests/e2e/rtl.teardown.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { existsSync, readFileSync, unlinkSync } from 'fs'
import { test as teardown } from '@playwright/test'
import { RTL_USER, rtlCreatedMarker } from './helpers/rtlUser'
import { wpCli } from './helpers/wpCli'

// Remove the right-to-left user the setup created, so the site is left as found.
// Remove the right-to-left user only if this run created it; an account that
// already existed on the site is left alone. A failed delete fails the teardown.
teardown('remove the right-to-left user', async () => {
try {
await wpCli(['user', 'delete', 'rtl-admin', '--yes'])
} catch {
// Already gone, or never created because the setup failed early.
if (!existsSync(rtlCreatedMarker)) {
return
}

const created = 'created' === readFileSync(rtlCreatedMarker, 'utf8').trim()
unlinkSync(rtlCreatedMarker)

if (created) {
await wpCli(['user', 'delete', RTL_USER, '--yes'])
}
})
Loading