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
1112import { 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
4030test . 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