|
4 | 4 | getEl,
|
5 | 5 | getText,
|
6 | 6 | editFileAndWaitForHmrComplete,
|
| 7 | + hmrCount, |
7 | 8 | untilMatches,
|
8 | 9 | sleep,
|
9 | 10 | getColor,
|
@@ -54,6 +55,10 @@ test('should respect transforms', async () => {
|
54 | 55 | if (!isBuild) {
|
55 | 56 | describe('hmr', () => {
|
56 | 57 | const updateHmrTest = editFileAndWaitForHmrComplete.bind(null, 'src/components/HmrTest.svelte');
|
| 58 | + const updateModuleContext = editFileAndWaitForHmrComplete.bind( |
| 59 | + null, |
| 60 | + 'src/components/partial-hmr/ModuleContext.svelte' |
| 61 | + ); |
57 | 62 | const updateApp = editFileAndWaitForHmrComplete.bind(null, 'src/App.svelte');
|
58 | 63 | const updateStore = editFileAndWaitForHmrComplete.bind(null, 'src/stores/hmr-stores.js');
|
59 | 64 |
|
@@ -136,6 +141,18 @@ if (!isBuild) {
|
136 | 141 | expect(await getText(`#hmr-test-3 .counter`)).toBe('0');
|
137 | 142 | });
|
138 | 143 |
|
| 144 | + test('should work when editing script context="module"', async () => { |
| 145 | + expect(await getText(`#hmr-with-context`)).toContain('x=0 y=1 slot=1'); |
| 146 | + expect(await getText(`#hmr-without-context`)).toContain('x=0 y=1 slot='); |
| 147 | + expect(hmrCount('UsingNamed.svelte'), 'updates for UsingNamed.svelte').toBe(0); |
| 148 | + expect(hmrCount('UsingDefault.svelte'), 'updates for UsingDefault.svelte').toBe(0); |
| 149 | + await updateModuleContext((content) => content.replace('y = 1', 'y = 2')); |
| 150 | + expect(await getText(`#hmr-with-context`)).toContain('x=0 y=2 slot=2'); |
| 151 | + expect(await getText(`#hmr-without-context`)).toContain('x=0 y=2 slot='); |
| 152 | + expect(hmrCount('UsingNamed.svelte'), 'updates for UsingNamed.svelte').toBe(1); |
| 153 | + expect(hmrCount('UsingDefault.svelte'), 'updates for UsingDefault.svelte').toBe(0); |
| 154 | + }); |
| 155 | + |
139 | 156 | test('should work with emitCss: false in vite config', async () => {
|
140 | 157 | await editViteConfig((c) => c.replace('svelte()', 'svelte({emitCss:false})'));
|
141 | 158 | expect(await getText(`#hmr-test-1 .counter`)).toBe('0');
|
|
0 commit comments