Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks E2E: Refactor configs and workflow #46409

Merged
merged 45 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
22ad6f0
Merge all e2e configs
WunderBart Apr 10, 2024
e2263d3
Refactor tests workflow to address config changes
WunderBart Apr 10, 2024
29ebb29
Move db import to page fixture setup
WunderBart Apr 10, 2024
5b777e5
Improve wording
WunderBart Apr 10, 2024
63c461c
Revert "Move db import to page fixture setup"
WunderBart Apr 10, 2024
03d70c4
Tweak db import messages
WunderBart Apr 10, 2024
a2ff4e5
Fix artifacts path
WunderBart Apr 10, 2024
38e32e5
Fix artifacts path again + bump action version
WunderBart Apr 10, 2024
d414289
Tweak job title
WunderBart Apr 10, 2024
36aa547
Tweak some more titling
WunderBart Apr 10, 2024
8b5bbbb
Fix artifacts name
WunderBart Apr 10, 2024
277eae0
Use beforeEach hook for activating themes
WunderBart Apr 10, 2024
752a585
Some more workflow tweaks
WunderBart Apr 10, 2024
ea98a46
Remove one more hook
WunderBart Apr 10, 2024
21c074c
Fix failing guest shopper test
WunderBart Apr 16, 2024
e26065a
Add shard prefix to artifacts upload
WunderBart Apr 16, 2024
e39c672
Use actions/checkout@v4
WunderBart Apr 16, 2024
9fd9300
Add artifacts merge step
WunderBart Apr 16, 2024
33bbfb1
Remove comment
WunderBart Apr 16, 2024
4466a5a
Add changelog entry
WunderBart Apr 16, 2024
dbe344d
Try generating html report
WunderBart Apr 17, 2024
1c22e8c
Revert "Try generating html report"
WunderBart Apr 17, 2024
60756b8
Streamline db error
WunderBart Apr 17, 2024
3a60fac
Make exec reject on error
WunderBart Apr 17, 2024
63165d4
Try 10 shards
WunderBart Apr 18, 2024
1f8a5d3
Execute templates tests in parallel like before
WunderBart Apr 18, 2024
77ebcd7
Revert "Execute templates tests in parallel like before"
WunderBart Apr 18, 2024
3c7b30e
Remove side_effects suffix from test files
WunderBart Apr 19, 2024
d38f66c
Remove accidental pause
WunderBart Apr 29, 2024
9179fdb
Fix linter errors
WunderBart Apr 29, 2024
f207d77
Restore the themed runners
WunderBart Apr 29, 2024
c3b894c
Reuse db snapshot to reduce global setup time
WunderBart Apr 29, 2024
09c954e
Remove more unnecessary setup and teardown steps
WunderBart Apr 30, 2024
c41c431
Merge remote-tracking branch 'origin' into refactor/e2e-playwright-co…
WunderBart Apr 30, 2024
4cb7525
Refactor out the isMacOS check
WunderBart Apr 30, 2024
0492dae
Try generating HTML report take 2
WunderBart May 2, 2024
03a54ea
Revert "Try generating HTML report take 2"
WunderBart May 2, 2024
f454021
Fix artifact merge when artifacts unavail. after rerun
WunderBart May 2, 2024
53a94a6
tmp: print artifact id
WunderBart May 2, 2024
c00ff79
Revert "tmp: print artifact id"
WunderBart May 2, 2024
a5ba238
Merge remote-tracking branch 'origin' into refactor/e2e-playwright-co…
WunderBart May 2, 2024
4898494
Fix mini cart test
WunderBart May 2, 2024
522fc31
Handle perfect run
WunderBart May 2, 2024
b14ca43
Merge remote-tracking branch 'origin' into refactor/e2e-playwright-co…
WunderBart May 9, 2024
894960d
Merge remote-tracking branch 'origin' into refactor/e2e-playwright-co…
WunderBart May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 35 additions & 35 deletions .github/workflows/blocks-playwright.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Blocks Playwright Tests
name: Blocks Playwright Tests

on:
pull_request:
Expand All @@ -11,13 +11,12 @@ on:
# Allow manually triggering the workflow.
workflow_dispatch:


env:
FORCE_COLOR: 1

jobs:
e2e:
name: ${{ matrix.config.name }} [${{ matrix.shards.name }}]
blocks-playwright-tests:
name: Shard ${{ matrix.shardIndex }} of ${{ matrix.shardTotal }}
timeout-minutes: 60
runs-on: ubuntu-latest
defaults:
Expand All @@ -26,47 +25,48 @@ jobs:
strategy:
fail-fast: false
matrix:
config:
- name: Default (Block) Theme
file: playwright.config.ts
resultPath: test-results
- name: Classic Theme
file: playwright.classic-theme.config.ts
resultPath: test-results-classic-theme
- name: Side Effects
file: playwright.side-effects.config.ts
resultPath: test-results-side-effects
- name: Block Theme With Templates
file: playwright.block-theme-with-templates.config.ts
resultPath: test-results-block-theme-with-templates
shards:
- name: 1/5
- name: 2/5
- name: 3/5
- name: 4/5
- name: 5/5
shardIndex: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
shardTotal: [10]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo
with:
install: '@woocommerce/plugin-woocommerce...'
build: '@woocommerce/plugin-woocommerce'

- name: Install Playwright
run: pnpm --filter='@woocommerce/block-library' exec playwright install --with-deps
- name: Install Playwright dependencies
run: pnpm exec playwright install chromium --with-deps

- name: Start wp-env
run: pnpm --filter='@woocommerce/block-library' env:start
- name: Setup testing environment and start the server
run: pnpm env:start

- name: Run Playwright tests
working-directory: plugins/woocommerce-blocks
run: pnpm playwright test --config=tests/e2e/${{ matrix.config.file }} --shard ${{ matrix.shards.name }}
run: pnpm test:e2e --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}

- name: Archive debug artifacts (screenshots, traces)
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: failures-artifacts-shard-${{ matrix.shardIndex }}
path: plugins/woocommerce-blocks/tests/e2e/artifacts/test-results
if-no-files-found: ignore

- uses: actions/upload-artifact@v3
if: ${{ failure() }}
merge-artifacts:
# Merges all artifacts from all shards into a single zip and
# deletes the parts. In case of a rerun, artifacts from the
# previous run will be retained by merging them with the new ones.
name: Merge Artifacts
if: ${{ !cancelled() }}
needs: [blocks-playwright-tests]
runs-on: ubuntu-latest
steps:
- name: Merge 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: playwright-report-${{ matrix.config.name }}
path: plugins/woocommerce-blocks/tests/e2e/artifacts/${{ matrix.config.resultPath }}
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
name: failures-artifacts
delete-merged: true
10 changes: 3 additions & 7 deletions plugins/woocommerce-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,9 @@
"test:js": "wp-scripts test-unit-js --config tests/js/jest.config.json",
"test:debug": "ndb .",
"test:e2e": "sh ./bin/check-env.sh && pnpm playwright test --config=tests/e2e/playwright.config.ts",
"test:e2e:report": "sh ./bin/check-env.sh && npx playwright test --config=tests/e2e/playwright.config.ts --reporter=html",
"test:e2e:side-effects": "pnpm run test:e2e --config=tests/e2e/playwright.side-effects.config.ts",
"test:e2e:side-effects:report": "pnpm run test:e2e:report --config=tests/e2e/playwright.side-effects.config.ts --reporter=html",
"test:e2e:classic-theme": "pnpm run test:e2e --config=tests/e2e/playwright.classic-theme.config.ts",
"test:e2e:classic-theme:report": "pnpm run test:e2e:report --config=tests/e2e/playwright.classic-theme.config.ts",
"test:e2e:block-theme-with-templates": "pnpm run test:e2e --config=tests/e2e/playwright.block-theme-with-templates.config.ts",
"test:e2e:block-theme-with-templates:report": "pnpm run test:e2e:report --config=tests/e2e/playwright.block-theme-with-templates.config.ts",
"test:e2e:block-theme": "pnpm run test:e2e block_theme",
"test:e2e:classic-theme": "pnpm run test:e2e classic_theme",
"test:e2e:block-theme-with-templates": "pnpm run test:e2e block_theme_with_templates",
"test:e2e:jest": "pnpm run wp-env:config && cross-env JEST_PUPPETEER_CONFIG=tests/e2e-jest/config/jest-puppeteer.config.js NODE_CONFIG_DIR=tests/e2e-jest/config wp-scripts test-e2e --config tests/e2e-jest/config/jest.config.js",
"test:e2e:jest:dev": "pnpm run wp-env:config && cross-env JEST_PUPPETEER_CONFIG=tests/e2e-jest/config/jest-puppeteer.config-dev.js NODE_CONFIG_DIR=tests/e2e-jest/config wp-scripts test-e2e --config tests/e2e-jest/config/jest.config.js",
"test:e2e:jest:dev-watch": "pnpm run wp-env:config && cross-env JEST_PUPPETEER_CONFIG=tests/e2e-jest/config/jest-puppeteer.config-dev.js NODE_CONFIG_DIR=tests/e2e-jest/config wp-scripts test-e2e --config tests/e2e-jest/config/jest.config.js --watch",
Expand Down

This file was deleted.

30 changes: 0 additions & 30 deletions plugins/woocommerce-blocks/tests/e2e/block-theme.setup.ts

This file was deleted.

26 changes: 0 additions & 26 deletions plugins/woocommerce-blocks/tests/e2e/classic-theme.setup.ts

This file was deleted.

58 changes: 40 additions & 18 deletions plugins/woocommerce-blocks/tests/e2e/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
*/
import { chromium, request } from '@playwright/test';
import { RequestUtils } from '@wordpress/e2e-test-utils-playwright';
import { BASE_URL, adminFile, cli, customerFile } from '@woocommerce/e2e-utils';
import {
BASE_URL,
adminFile,
cli,
customerFile,
BLOCK_THEME_SLUG,
DB_EXPORT_FILE,
} from '@woocommerce/e2e-utils';

/**
* Internal dependencies
Expand Down Expand Up @@ -53,36 +60,51 @@ const prepareAttributes = async () => {
};

async function globalSetup() {
const timers = {
total: '└ Total time',
authentication: '├ Authentication time',
attributes: '├ Attributes preparation time',
};
console.log( 'Running global setup:' );
console.time( '└ Total time' );

console.log( 'Running global setup...' );
console.time( timers.total );
let databaseImported = false;

try {
console.log( '├ Attempting database import…' );
await cli(
`npm run wp-env run tests-cli wp db import ${ DB_EXPORT_FILE }`
);
databaseImported = true;
} catch ( _error ) {
// noop
}

const requestContext = await request.newContext( {
baseURL: BASE_URL,
} );

console.time( timers.authentication );
await new RequestUtils( requestContext, {
user: admin,
storageStatePath: adminFile,
} ).setupRest();
console.log( '├ Pre-authenticating users…' );
await new RequestUtils( requestContext, {
user: customer,
storageStatePath: customerFile,
} ).setupRest();
console.timeEnd( timers.authentication );
const requestUtils = new RequestUtils( requestContext, {
user: admin,
storageStatePath: adminFile,
} );
await requestUtils.setupRest();

if ( ! databaseImported ) {
console.log( '├ Activating default theme…' );
await requestUtils.activateTheme( BLOCK_THEME_SLUG );

console.log( '├ Preparing product attributes…' );
await prepareAttributes();
}

console.time( timers.attributes );
await prepareAttributes();
console.timeEnd( timers.attributes );
console.log( '├ Exporting database…' );
await cli(
`npm run wp-env run tests-cli wp db export ${ DB_EXPORT_FILE }`
);

await requestContext.dispose();
console.timeEnd( timers.total );
console.timeEnd( '└ Total time' );
}

export default globalSetup;
3 changes: 0 additions & 3 deletions plugins/woocommerce-blocks/tests/e2e/global-teardown.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,9 @@ const test = base.extend<
window.localStorage.clear();
} );

const cliOutput = await cli(
await cli(
`npm run wp-env run tests-cli wp db import ${ DB_EXPORT_FILE }`
);
if ( ! cliOutput.stdout.includes( 'Success: Imported ' ) ) {
throw new Error( `Failed to import ${ DB_EXPORT_FILE }` );
}
},
Comment on lines +164 to 167
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! That check was needed because the cli utility always resolved the promise, regardless of whether the executed script threw an error. I made it reject on an error in 3a60fac, so now we don't need these explicit output checks as they're handled inside the utility.

pageUtils: async ( { page }, use ) => {
await use( new PageUtils( { page } ) );
Expand Down

This file was deleted.

This file was deleted.