|
| 1 | +import { writeFile } from 'node:fs/promises'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { getRandomPort } from '@rstackjs/test-utils'; |
| 4 | +import { test } from '#test-helpers'; |
| 5 | + |
| 6 | +test('should restart doc dev server when Rstack config changes', async ({ |
| 7 | + execCliAsync, |
| 8 | + logHelper, |
| 9 | +}) => { |
| 10 | + const configFile = path.join(import.meta.dirname, 'test-temp-rstack.config.ts'); |
| 11 | + const userWatchFile = path.join(import.meta.dirname, 'test-temp-user-watch.txt'); |
| 12 | + |
| 13 | + const writeConfig = (title: string) => |
| 14 | + writeFile( |
| 15 | + configFile, |
| 16 | + `import { define } from 'rstack'; |
| 17 | +
|
| 18 | +define.doc({ |
| 19 | + root: 'docs', |
| 20 | + title: '${title}', |
| 21 | + builderConfig: { |
| 22 | + dev: { |
| 23 | + watchFiles: { |
| 24 | + paths: ${JSON.stringify(userWatchFile)}, |
| 25 | + type: 'restart', |
| 26 | + }, |
| 27 | + }, |
| 28 | + }, |
| 29 | +}); |
| 30 | +`, |
| 31 | + ); |
| 32 | + |
| 33 | + await writeFile(userWatchFile, 'initial\n'); |
| 34 | + await writeConfig('before config change'); |
| 35 | + |
| 36 | + execCliAsync(`doc --config test-temp-rstack.config.ts --port ${await getRandomPort()}`); |
| 37 | + await logHelper.expectBuildEnd(); |
| 38 | + logHelper.clearLogs(); |
| 39 | + |
| 40 | + await writeConfig('after config change'); |
| 41 | + |
| 42 | + await logHelper.expectLog('restarting server as test-temp-rstack.config.ts changed'); |
| 43 | + await logHelper.expectBuildEnd(); |
| 44 | + logHelper.clearLogs(); |
| 45 | + |
| 46 | + await writeFile(userWatchFile, 'changed\n'); |
| 47 | + |
| 48 | + await logHelper.expectLog('restarting server as test-temp-user-watch.txt changed'); |
| 49 | + await logHelper.expectBuildEnd(); |
| 50 | +}); |
| 51 | + |
| 52 | +test('should restart doc dev server when an imported config file changes', async ({ |
| 53 | + execCliAsync, |
| 54 | + logHelper, |
| 55 | +}) => { |
| 56 | + const configFile = path.join(import.meta.dirname, 'test-temp-import.config.ts'); |
| 57 | + const importedFile = path.join(import.meta.dirname, 'test-temp-imported.ts'); |
| 58 | + |
| 59 | + await writeFile(importedFile, "export const title = 'before import change';\n"); |
| 60 | + await writeFile( |
| 61 | + configFile, |
| 62 | + `import { define } from 'rstack'; |
| 63 | +import { title } from './test-temp-imported.ts'; |
| 64 | +
|
| 65 | +define.doc({ |
| 66 | + root: 'docs', |
| 67 | + title, |
| 68 | +}); |
| 69 | +`, |
| 70 | + ); |
| 71 | + |
| 72 | + execCliAsync(`doc --config test-temp-import.config.ts --port ${await getRandomPort()}`); |
| 73 | + await logHelper.expectBuildEnd(); |
| 74 | + logHelper.clearLogs(); |
| 75 | + |
| 76 | + await writeFile(importedFile, "export const title = 'after import change';\n"); |
| 77 | + |
| 78 | + await logHelper.expectLog('restarting server as test-temp-imported.ts changed'); |
| 79 | + await logHelper.expectBuildEnd(); |
| 80 | +}); |
0 commit comments