1- import { getDistFiles , getFileContent } from '@rstackjs/test-utils' ;
1+ import { writeFile } from 'node:fs/promises' ;
2+ import path from 'node:path' ;
3+ import { getDistFiles , getFileContent , getRandomPort } from '@rstackjs/test-utils' ;
24import { test } from '#test-helpers' ;
35
46const expectedText = 'define.doc works' ;
@@ -13,3 +15,79 @@ test('should build docs with define.doc config', async ({ prepareDist, execCli,
1315
1416 expect ( output ) . toContain ( expectedText ) ;
1517} , 30_000 ) ;
18+
19+ test ( 'should restart doc dev server when Rstack config changes' , async ( {
20+ execCliAsync,
21+ logHelper,
22+ } ) => {
23+ const configFile = path . join ( import . meta. dirname , 'test-temp-rstack.config.ts' ) ;
24+ const userWatchFile = path . join ( import . meta. dirname , 'test-temp-user-watch.txt' ) ;
25+
26+ const writeConfig = ( title : string ) =>
27+ writeFile (
28+ configFile ,
29+ `import { define } from 'rstack';
30+
31+ define.doc({
32+ root: 'docs',
33+ title: '${ title } ',
34+ builderConfig: {
35+ dev: {
36+ watchFiles: {
37+ paths: ${ JSON . stringify ( userWatchFile ) } ,
38+ type: 'restart',
39+ },
40+ },
41+ },
42+ });
43+ ` ,
44+ ) ;
45+
46+ await writeFile ( userWatchFile , 'initial\n' ) ;
47+ await writeConfig ( 'before config change' ) ;
48+
49+ execCliAsync ( `doc --config test-temp-rstack.config.ts --port ${ await getRandomPort ( ) } ` ) ;
50+ await logHelper . expectBuildEnd ( ) ;
51+ logHelper . clearLogs ( ) ;
52+
53+ await writeConfig ( 'after config change' ) ;
54+
55+ await logHelper . expectLog ( 'restarting server as test-temp-rstack.config.ts changed' ) ;
56+ await logHelper . expectBuildEnd ( ) ;
57+ logHelper . clearLogs ( ) ;
58+
59+ await writeFile ( userWatchFile , 'changed\n' ) ;
60+
61+ await logHelper . expectLog ( 'restarting server as test-temp-user-watch.txt changed' ) ;
62+ await logHelper . expectBuildEnd ( ) ;
63+ } , 30_000 ) ;
64+
65+ test ( 'should restart doc dev server when an imported config file changes' , async ( {
66+ execCliAsync,
67+ logHelper,
68+ } ) => {
69+ const configFile = path . join ( import . meta. dirname , 'test-temp-import.config.ts' ) ;
70+ const importedFile = path . join ( import . meta. dirname , 'test-temp-imported.ts' ) ;
71+
72+ await writeFile ( importedFile , "export const title = 'before import change';\n" ) ;
73+ await writeFile (
74+ configFile ,
75+ `import { define } from 'rstack';
76+ import { title } from './test-temp-imported.ts';
77+
78+ define.doc({
79+ root: 'docs',
80+ title,
81+ });
82+ ` ,
83+ ) ;
84+
85+ execCliAsync ( `doc --config test-temp-import.config.ts --port ${ await getRandomPort ( ) } ` ) ;
86+ await logHelper . expectBuildEnd ( ) ;
87+ logHelper . clearLogs ( ) ;
88+
89+ await writeFile ( importedFile , "export const title = 'after import change';\n" ) ;
90+
91+ await logHelper . expectLog ( 'restarting server as test-temp-imported.ts changed' ) ;
92+ await logHelper . expectBuildEnd ( ) ;
93+ } , 30_000 ) ;
0 commit comments