diff --git a/packages/rstack/tests/config/reload-app-config/index.test.ts b/packages/rstack/tests/config/reload-app-config/index.test.ts index 7fb1ea1c..6c8f08bc 100644 --- a/packages/rstack/tests/config/reload-app-config/index.test.ts +++ b/packages/rstack/tests/config/reload-app-config/index.test.ts @@ -82,3 +82,64 @@ define.app({ 'restarting server as test-temp-imported.ts changed', ); }); + +test('should reload config when an imported shared config changes', async ({ + execCliAsync, + logHelper, + expect, +}) => { + const configFile = path.join( + import.meta.dirname, + 'test-temp-shared.config.ts', + ); + const importedFile = path.join(import.meta.dirname, 'test-temp-shared.ts'); + const port = await getRandomPort(); + const url = `http://localhost:${port}`; + + await writeFile( + importedFile, + `export const sharedConfig = { + app: { + html: { title: 'before import change' }, + }, +}; +`, + ); + await writeFile( + configFile, + `import { define } from 'rstack'; +import { sharedConfig } from './test-temp-shared.ts'; + +define.extends([sharedConfig]); + +define.app({ + server: { port: ${port} }, +}); +`, + ); + + execCliAsync('dev --config test-temp-shared.config.ts'); + await logHelper.expectBuildEnd(); + const initialResponse = await fetch(url); + expect(await initialResponse.text()).toContain( + 'before import change', + ); + logHelper.clearLogs(); + + await writeFile( + importedFile, + `export const sharedConfig = { + app: { + html: { title: 'after import change' }, + }, +}; +`, + ); + + await logHelper.expectLog('restarting server as test-temp-shared.ts changed'); + await logHelper.expectBuildEnd(); + const updatedResponse = await fetch(url); + expect(await updatedResponse.text()).toContain( + 'after import change', + ); +}); 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 6aece32f..ac59d52e 100644 --- a/packages/rstack/tests/config/reload-doc-config/index.test.ts +++ b/packages/rstack/tests/config/reload-doc-config/index.test.ts @@ -103,3 +103,57 @@ define.doc({ ); await logHelper.expectBuildEnd(); }); + +test('should restart doc dev server when an imported shared config changes', async ({ + execCliAsync, + logHelper, + expect, +}) => { + const configFile = path.join( + import.meta.dirname, + 'test-temp-shared.config.ts', + ); + const importedFile = path.join(import.meta.dirname, 'test-temp-shared.ts'); + const port = await getRandomPort(); + const url = `http://localhost:${port}`; + + await writeFile( + importedFile, + `export const sharedConfig = { + doc: { title: 'before import change' }, +}; +`, + ); + await writeFile( + configFile, + `import { define } from 'rstack'; +import { sharedConfig } from './test-temp-shared.ts'; + +define.extends([sharedConfig]); +define.doc({ root: 'docs' }); +`, + ); + + execCliAsync(`doc --config test-temp-shared.config.ts --port ${port}`); + await logHelper.expectBuildEnd(); + const initialResponse = await fetch(url); + expect(await initialResponse.text()).toContain( + 'before import change', + ); + logHelper.clearLogs(); + + await writeFile( + importedFile, + `export const sharedConfig = { + doc: { title: 'after import change' }, +}; +`, + ); + + await logHelper.expectLog('restarting server as test-temp-shared.ts changed'); + await logHelper.expectBuildEnd(); + const updatedResponse = await fetch(url); + expect(await updatedResponse.text()).toContain( + 'after import change', + ); +}); 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 d2f27179..94694b2a 100644 --- a/packages/rstack/tests/config/reload-lib-config/index.test.ts +++ b/packages/rstack/tests/config/reload-lib-config/index.test.ts @@ -103,3 +103,54 @@ define.lib({ await logHelper.expectLog('build completed, watching for changes...'); await waitForFile(path.join(dist2, 'index.js')); }); + +test('should restart lib watch build when an imported shared config changes', async ({ + prepareDist, + execCliAsync, + logHelper, +}) => { + const dist1 = await prepareDist('dist-import-1'); + const dist2 = await prepareDist('dist-import-2'); + const configFile = path.join( + import.meta.dirname, + 'test-temp-shared.config.ts', + ); + const importedFile = path.join(import.meta.dirname, 'test-temp-shared.ts'); + + await writeFile( + importedFile, + `export const sharedConfig = { + lib: { + output: { distPath: 'dist-import-1' }, + }, +}; +`, + ); + await writeFile( + configFile, + `import { define } from 'rstack'; +import { sharedConfig } from './test-temp-shared.ts'; + +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')); + logHelper.clearLogs(); + + await writeFile( + importedFile, + `export const sharedConfig = { + lib: { + output: { distPath: 'dist-import-2' }, + }, +}; +`, + ); + + await logHelper.expectLog('restarting build as test-temp-shared.ts changed'); + await logHelper.expectLog('build completed, watching for changes...'); + await waitForFile(path.join(dist2, 'index.js')); +});