Skip to content

Commit 86b4d30

Browse files
authored
test: mitigate config watcher startup races (#620)
1 parent f70983f commit 86b4d30

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/rstack/tests/config/reload-doc-config/index.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { writeFile } from 'node:fs/promises';
22
import path from 'node:path';
3-
import { getRandomPort } from '@rstackjs/test-utils';
3+
import { getRandomPort, waitFor } from '@rstackjs/test-utils';
44
import { test } from '#test-helpers';
55

66
test('should restart doc dev server when Rstack config changes', async ({
@@ -45,6 +45,8 @@ define.doc({
4545
`doc --config test-temp-rstack.config.ts --port ${await getRandomPort()}`,
4646
);
4747
await logHelper.expectBuildEnd();
48+
// The build log can arrive before the restart watcher finishes its initial scan.
49+
await waitFor(100);
4850
logHelper.clearLogs();
4951

5052
await writeConfig('after config change');
@@ -53,6 +55,7 @@ define.doc({
5355
'restarting server as test-temp-rstack.config.ts changed',
5456
);
5557
await logHelper.expectBuildEnd();
58+
await waitFor(100);
5659
logHelper.clearLogs();
5760

5861
await writeFile(userWatchFile, 'changed\n');
@@ -96,6 +99,7 @@ define.doc({
9699
`doc --config test-temp-import.config.ts --port ${await getRandomPort()}`,
97100
);
98101
await logHelper.expectBuildEnd();
102+
await waitFor(100);
99103
logHelper.clearLogs();
100104

101105
await writeFile(
@@ -150,6 +154,7 @@ define.doc({
150154
expect(await initialResponse.text()).toContain(
151155
'<title>before import change</title>',
152156
);
157+
await waitFor(100);
153158
logHelper.clearLogs();
154159

155160
await writeFile(

‎packages/rstack/tests/config/reload-lib-config/index.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { writeFile } from 'node:fs/promises';
22
import path from 'node:path';
3-
import { waitForFile } from '@rstackjs/test-utils';
3+
import { waitFor, waitForFile } from '@rstackjs/test-utils';
44
import { test } from '#test-helpers';
55

66
test('should restart lib watch build when Rstack config changes', async ({
@@ -44,6 +44,8 @@ define.lib({
4444
execCliAsync('lib --watch --config test-temp-rstack.config.ts');
4545
await logHelper.expectLog('build completed, watching for changes...');
4646
await waitForFile(path.join(dist1, 'index.js'));
47+
// The build log precedes the restart watcher's initial filesystem scan.
48+
await waitFor(100);
4749
logHelper.clearLogs();
4850

4951
await writeConfig('dist-2');
@@ -53,6 +55,7 @@ define.lib({
5355
);
5456
await logHelper.expectLog('build completed, watching for changes...');
5557
await waitForFile(path.join(dist2, 'index.js'));
58+
await waitFor(100);
5659
logHelper.clearLogs();
5760

5861
await writeFile(userWatchFile, 'changed\n');
@@ -93,6 +96,7 @@ define.lib({
9396
execCliAsync('lib --watch --config test-temp-import.config.ts');
9497
await logHelper.expectLog('build completed, watching for changes...');
9598
await waitForFile(path.join(dist1, 'index.js'));
99+
await waitFor(100);
96100
logHelper.clearLogs();
97101

98102
await writeFile(importedFile, "export const distPath = 'dist-import-2';\n");
@@ -138,6 +142,7 @@ define.extends([sharedConfig]);
138142
execCliAsync('lib --watch --config test-temp-shared.config.ts');
139143
await logHelper.expectLog('build completed, watching for changes...');
140144
await waitForFile(path.join(dist1, 'index.js'));
145+
await waitFor(100);
141146
logHelper.clearLogs();
142147

143148
await writeFile(

0 commit comments

Comments
 (0)