Skip to content

Commit 3764bf6

Browse files
authored
test(config): cover shared config hot reload (#547)
1 parent b3ffe7a commit 3764bf6

3 files changed

Lines changed: 166 additions & 0 deletions

File tree

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,64 @@ define.app({
8282
'restarting server as test-temp-imported.ts changed',
8383
);
8484
});
85+
86+
test('should reload config when an imported shared config changes', async ({
87+
execCliAsync,
88+
logHelper,
89+
expect,
90+
}) => {
91+
const configFile = path.join(
92+
import.meta.dirname,
93+
'test-temp-shared.config.ts',
94+
);
95+
const importedFile = path.join(import.meta.dirname, 'test-temp-shared.ts');
96+
const port = await getRandomPort();
97+
const url = `http://localhost:${port}`;
98+
99+
await writeFile(
100+
importedFile,
101+
`export const sharedConfig = {
102+
app: {
103+
html: { title: 'before import change' },
104+
},
105+
};
106+
`,
107+
);
108+
await writeFile(
109+
configFile,
110+
`import { define } from 'rstack';
111+
import { sharedConfig } from './test-temp-shared.ts';
112+
113+
define.extends([sharedConfig]);
114+
115+
define.app({
116+
server: { port: ${port} },
117+
});
118+
`,
119+
);
120+
121+
execCliAsync('dev --config test-temp-shared.config.ts');
122+
await logHelper.expectBuildEnd();
123+
const initialResponse = await fetch(url);
124+
expect(await initialResponse.text()).toContain(
125+
'<title>before import change</title>',
126+
);
127+
logHelper.clearLogs();
128+
129+
await writeFile(
130+
importedFile,
131+
`export const sharedConfig = {
132+
app: {
133+
html: { title: 'after import change' },
134+
},
135+
};
136+
`,
137+
);
138+
139+
await logHelper.expectLog('restarting server as test-temp-shared.ts changed');
140+
await logHelper.expectBuildEnd();
141+
const updatedResponse = await fetch(url);
142+
expect(await updatedResponse.text()).toContain(
143+
'<title>after import change</title>',
144+
);
145+
});

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,57 @@ define.doc({
103103
);
104104
await logHelper.expectBuildEnd();
105105
});
106+
107+
test('should restart doc dev server when an imported shared config changes', async ({
108+
execCliAsync,
109+
logHelper,
110+
expect,
111+
}) => {
112+
const configFile = path.join(
113+
import.meta.dirname,
114+
'test-temp-shared.config.ts',
115+
);
116+
const importedFile = path.join(import.meta.dirname, 'test-temp-shared.ts');
117+
const port = await getRandomPort();
118+
const url = `http://localhost:${port}`;
119+
120+
await writeFile(
121+
importedFile,
122+
`export const sharedConfig = {
123+
doc: { title: 'before import change' },
124+
};
125+
`,
126+
);
127+
await writeFile(
128+
configFile,
129+
`import { define } from 'rstack';
130+
import { sharedConfig } from './test-temp-shared.ts';
131+
132+
define.extends([sharedConfig]);
133+
define.doc({ root: 'docs' });
134+
`,
135+
);
136+
137+
execCliAsync(`doc --config test-temp-shared.config.ts --port ${port}`);
138+
await logHelper.expectBuildEnd();
139+
const initialResponse = await fetch(url);
140+
expect(await initialResponse.text()).toContain(
141+
'<title>before import change</title>',
142+
);
143+
logHelper.clearLogs();
144+
145+
await writeFile(
146+
importedFile,
147+
`export const sharedConfig = {
148+
doc: { title: 'after import change' },
149+
};
150+
`,
151+
);
152+
153+
await logHelper.expectLog('restarting server as test-temp-shared.ts changed');
154+
await logHelper.expectBuildEnd();
155+
const updatedResponse = await fetch(url);
156+
expect(await updatedResponse.text()).toContain(
157+
'<title>after import change</title>',
158+
);
159+
});

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,54 @@ define.lib({
103103
await logHelper.expectLog('build completed, watching for changes...');
104104
await waitForFile(path.join(dist2, 'index.js'));
105105
});
106+
107+
test('should restart lib watch build when an imported shared config changes', async ({
108+
prepareDist,
109+
execCliAsync,
110+
logHelper,
111+
}) => {
112+
const dist1 = await prepareDist('dist-import-1');
113+
const dist2 = await prepareDist('dist-import-2');
114+
const configFile = path.join(
115+
import.meta.dirname,
116+
'test-temp-shared.config.ts',
117+
);
118+
const importedFile = path.join(import.meta.dirname, 'test-temp-shared.ts');
119+
120+
await writeFile(
121+
importedFile,
122+
`export const sharedConfig = {
123+
lib: {
124+
output: { distPath: 'dist-import-1' },
125+
},
126+
};
127+
`,
128+
);
129+
await writeFile(
130+
configFile,
131+
`import { define } from 'rstack';
132+
import { sharedConfig } from './test-temp-shared.ts';
133+
134+
define.extends([sharedConfig]);
135+
`,
136+
);
137+
138+
execCliAsync('lib --watch --config test-temp-shared.config.ts');
139+
await logHelper.expectLog('build completed, watching for changes...');
140+
await waitForFile(path.join(dist1, 'index.js'));
141+
logHelper.clearLogs();
142+
143+
await writeFile(
144+
importedFile,
145+
`export const sharedConfig = {
146+
lib: {
147+
output: { distPath: 'dist-import-2' },
148+
},
149+
};
150+
`,
151+
);
152+
153+
await logHelper.expectLog('restarting build as test-temp-shared.ts changed');
154+
await logHelper.expectLog('build completed, watching for changes...');
155+
await waitForFile(path.join(dist2, 'index.js'));
156+
});

0 commit comments

Comments
 (0)