Commit a31259f9ce8 for woocommerce

commit a31259f9ce80d1064e529055dc61afcc502ec077
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date:   Tue Sep 29 17:48:46 2026 +0300

    e2e tests: fix flaky JS file count E2E test by counting server-rendered scripts (#69205)

diff --git a/plugins/woocommerce/changelog/fix-e2e-js-file-monitor b/plugins/woocommerce/changelog/fix-e2e-js-file-monitor
new file mode 100644
index 00000000000..4915fde619f
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-e2e-js-file-monitor
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Fix flaky JS file count E2E test by counting server-rendered scripts; no production change.
+
diff --git a/plugins/woocommerce/tests/e2e/tests/js-file-monitor/monitor-js-file-number.spec.ts b/plugins/woocommerce/tests/e2e/tests/js-file-monitor/monitor-js-file-number.spec.ts
index 2b95f67725c..f4b670e7d03 100644
--- a/plugins/woocommerce/tests/e2e/tests/js-file-monitor/monitor-js-file-number.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/js-file-monitor/monitor-js-file-number.spec.ts
@@ -73,12 +73,20 @@ for ( const group of pageGroups ) {
 			test( `${ name } should load at most ${ expectedCount } JS files`, async ( {
 				page,
 			} ) => {
-				// networkidle is needed to ensure all JS files are loaded and avoid race conditions
-				// eslint-disable-next-line playwright/no-networkidle
-				await page.goto( url, { waitUntil: 'networkidle' } );
-				const javascriptFiles = await page.$$eval(
-					'script[src]',
-					( scripts ) => scripts.map( ( s ) => s.src )
+				// Count the scripts in the server HTML, not the live DOM. Loaders such as
+				// TinyMCE and webpack add a script tag per lazy file and remove it once loaded,
+				// so a DOM count depends on what is still in flight at that moment.
+				const response = await page.goto( url );
+				expect( response?.ok() ).toBe( true );
+				const javascriptFiles = await page.evaluate(
+					( html ) =>
+						Array.from(
+							new DOMParser()
+								.parseFromString( html, 'text/html' )
+								.querySelectorAll( 'script[src]' ),
+							( s ) => s.getAttribute( 'src' )
+						),
+					await response!.text()
 				);

 				expect