Skip to content

Commit bb41d96

Browse files
author
Soare Robert-Daniel
committed
dev: CI
1 parent b4b484c commit bb41d96

6 files changed

Lines changed: 48 additions & 29 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ vendor
88
languages/woocommerce-product-addon.pot
99
*.log
1010
artifacts
11-
.phpunit.result.cache
11+
.phpunit.result.cache
12+
tests/e2e/fixtures/generated/

bin/e2e-after-setup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
# Add some woocommerce products.
44
npm run wp-env run tests-cli bash ./wp-content/plugins/woocommerce-product-addon/bin/env/create-products.sh
55

6+
# Seed the quantity-matrix fixture data used by critical storefront E2E coverage.
7+
npm run wp-env run tests-cli bash ./wp-content/plugins/woocommerce-product-addon/bin/env/create-quantity-matrix-group.sh
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
fixture_path="./wp-content/plugins/woocommerce-product-addon/tests/e2e/fixtures/create-quantity-matrix-group.php"
6+
output_path="./wp-content/plugins/woocommerce-product-addon/tests/e2e/fixtures/generated/quantity-matrix-group.json"
7+
suffix="${1:-e2e_quantity_matrix}"
8+
9+
mkdir -p "$(dirname "$output_path")"
10+
11+
fixture_output="$(wp eval-file "$fixture_path" "$suffix")"
12+
json_line="$(printf '%s\n' "$fixture_output" | sed '/^[[:space:]]*$/d' | tail -n 1)"
13+
14+
if [ -z "$json_line" ]; then
15+
echo "Failed to seed the quantity-matrix fixture." >&2
16+
exit 1
17+
fi
18+
19+
printf '%s\n' "$json_line" > "$output_path"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
/**
3+
* Placeholder admin template kept for backward compatibility.
4+
*
5+
* @package PPOM
6+
*/

tests/e2e/fixtures/create-quantity-matrix-group.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
'status' => 'success',
116116
'meta_id' => $meta_id,
117117
'product_id' => $product_id,
118+
'product_name' => get_the_title( $product_id ),
118119
'product_permalink' => get_permalink( $product_id ),
119120
'quantity_field_id' => 'seat_quantity_' . $suffix,
120121
)

tests/e2e/specs/quantity-matrix-critical.spec.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* External dependencies
33
*/
4-
import { execFileSync } from 'node:child_process';
4+
import { readFileSync } from 'node:fs';
5+
import path from 'node:path';
56

67
/**
78
* WordPress dependencies
@@ -10,38 +11,27 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright';
1011

1112
import { clearCart } from '../utils';
1213

13-
const RUN_SUFFIX = Date.now().toString();
14+
const SEEDED_GROUP_PATH = path.join(
15+
process.cwd(),
16+
'tests/e2e/fixtures/generated/quantity-matrix-group.json'
17+
);
1418

15-
function seedQuantityMatrixGroup() {
16-
const output = execFileSync(
17-
'./node_modules/.bin/wp-env',
18-
[
19-
'run',
20-
'cli',
21-
'wp',
22-
'eval-file',
23-
'./wp-content/plugins/woocommerce-product-addon/tests/e2e/fixtures/create-quantity-matrix-group.php',
24-
RUN_SUFFIX,
25-
],
26-
{
27-
cwd: process.cwd(),
28-
encoding: 'utf8',
29-
}
30-
).trim();
31-
const jsonLine = output
32-
.split( '\n' )
33-
.map( ( line ) => line.trim() )
34-
.filter( Boolean )
35-
.at( -1 );
36-
37-
return JSON.parse( jsonLine );
19+
function readSeededQuantityMatrixGroup() {
20+
try {
21+
return JSON.parse( readFileSync( SEEDED_GROUP_PATH, 'utf8' ) );
22+
} catch ( error ) {
23+
throw new Error(
24+
`Missing quantity-matrix fixture data at ${ SEEDED_GROUP_PATH }. Run "bash ./bin/e2e-after-setup.sh" after starting wp-env.`,
25+
{ cause: error }
26+
);
27+
}
3828
}
3929

4030
test.describe( 'Quantity Matrix', () => {
4131
test( '@critical quantity limits and matrix pricing stay aligned', async ( {
4232
page,
4333
} ) => {
44-
const seededGroup = seedQuantityMatrixGroup();
34+
const seededGroup = readSeededQuantityMatrixGroup();
4535

4636
expect( seededGroup.status ).toBe( 'success' );
4737

@@ -73,7 +63,7 @@ test.describe( 'Quantity Matrix', () => {
7363
await page.goto( '/cart/' );
7464
await expect(
7565
page.getByRole( 'spinbutton', {
76-
name: 'Quantity of Product 1 in your cart.',
66+
name: `Quantity of ${ seededGroup.product_name } in your cart.`,
7767
} )
7868
).toHaveValue( '2' );
7969
await expect( page.locator( 'body' ) ).toContainText( '$16.00' );
@@ -90,7 +80,7 @@ test.describe( 'Quantity Matrix', () => {
9080
await page.goto( '/cart/' );
9181
await expect(
9282
page.getByRole( 'spinbutton', {
93-
name: 'Quantity of Product 1 in your cart.',
83+
name: `Quantity of ${ seededGroup.product_name } in your cart.`,
9484
} )
9585
).toHaveValue( '4' );
9686
await expect( page.locator( 'body' ) ).toContainText( '$28.00' );

0 commit comments

Comments
 (0)