From 0edd77926be8f3828c93c3a507edde91a70f4132 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 6 Nov 2026 21:28:52 +0800 Subject: [PATCH] test: mitigate config watcher startup races --- .../rstack/tests/config/reload-doc-config/index.test.ts | 7 ++++++- .../rstack/tests/config/reload-lib-config/index.test.ts | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/rstack/tests/config/reload-doc-config/index.test.ts b/packages/rstack/tests/config/reload-doc-config/index.test.ts index ded4ea17..01b63d19 100644 --- a/packages/rstack/tests/config/reload-doc-config/index.test.ts +++ b/packages/rstack/tests/config/reload-doc-config/index.test.ts @@ -1,6 +1,6 @@ import { writeFile } from 'node:fs/promises'; import path from 'node:path'; -import { getRandomPort } from '@rstackjs/test-utils'; +import { getRandomPort, waitFor } from '@rstackjs/test-utils'; import { test } from '#test-helpers'; test('should restart doc dev server when Rstack config changes', async ({ @@ -45,6 +45,8 @@ define.doc({ `doc --config test-temp-rstack.config.ts --port ${await getRandomPort()}`, ); await logHelper.expectBuildEnd(); + // The build log can arrive before the restart watcher finishes its initial scan. + await waitFor(100); logHelper.clearLogs(); await writeConfig('after config change'); @@ -53,6 +55,7 @@ define.doc({ 'restarting server as test-temp-rstack.config.ts changed', ); await logHelper.expectBuildEnd(); + await waitFor(100); logHelper.clearLogs(); await writeFile(userWatchFile, 'changed\n'); @@ -96,6 +99,7 @@ define.doc({ `doc --config test-temp-import.config.ts --port ${await getRandomPort()}`, ); await logHelper.expectBuildEnd(); + await waitFor(100); logHelper.clearLogs(); await writeFile( @@ -150,6 +154,7 @@ define.doc({ expect(await initialResponse.text()).toContain( 'before import change', ); + await waitFor(100); logHelper.clearLogs(); await writeFile( diff --git a/packages/rstack/tests/config/reload-lib-config/index.test.ts b/packages/rstack/tests/config/reload-lib-config/index.test.ts index 94694b2a..24d7268f 100644 --- a/packages/rstack/tests/config/reload-lib-config/index.test.ts +++ b/packages/rstack/tests/config/reload-lib-config/index.test.ts @@ -1,6 +1,6 @@ import { writeFile } from 'node:fs/promises'; import path from 'node:path'; -import { waitForFile } from '@rstackjs/test-utils'; +import { waitFor, waitForFile } from '@rstackjs/test-utils'; import { test } from '#test-helpers'; test('should restart lib watch build when Rstack config changes', async ({ @@ -44,6 +44,8 @@ define.lib({ execCliAsync('lib --watch --config test-temp-rstack.config.ts'); await logHelper.expectLog('build completed, watching for changes...'); await waitForFile(path.join(dist1, 'index.js')); + // The build log precedes the restart watcher's initial filesystem scan. + await waitFor(100); logHelper.clearLogs(); await writeConfig('dist-2'); @@ -53,6 +55,7 @@ define.lib({ ); await logHelper.expectLog('build completed, watching for changes...'); await waitForFile(path.join(dist2, 'index.js')); + await waitFor(100); logHelper.clearLogs(); await writeFile(userWatchFile, 'changed\n'); @@ -93,6 +96,7 @@ define.lib({ execCliAsync('lib --watch --config test-temp-import.config.ts'); await logHelper.expectLog('build completed, watching for changes...'); await waitForFile(path.join(dist1, 'index.js')); + await waitFor(100); logHelper.clearLogs(); await writeFile(importedFile, "export const distPath = 'dist-import-2';\n"); @@ -138,6 +142,7 @@ define.extends([sharedConfig]); execCliAsync('lib --watch --config test-temp-shared.config.ts'); await logHelper.expectLog('build completed, watching for changes...'); await waitForFile(path.join(dist1, 'index.js')); + await waitFor(100); logHelper.clearLogs(); await writeFile(