-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for hmr with dynamic import
The self-accepting test is failing. It will be fixed
- Loading branch information
Showing
8 changed files
with
228 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<template> | ||
<h2>Hot Module Replacement</h2> | ||
<p> | ||
<span> | ||
HMR: click button and edit template part of <code>./TestHmr.vue</code>, | ||
count should not reset | ||
</span> | ||
<button class="hmr-increment" @click="count++"> | ||
>>> {{ count }} <<< | ||
</button> | ||
</p> | ||
<p> | ||
<span> | ||
HMR: edit the return value of <code>foo()</code> in | ||
<code>./testHmrPropagation.js</code>, should update without reloading | ||
page: | ||
</span> | ||
<span class="hmr-propagation">{{ foo() }}</span> | ||
</p> | ||
<p> | ||
<span> | ||
HMR: edit the value of <code>bar</code> in | ||
<code>./testDynamicImportHmrPropagation.js</code>, should update without | ||
reloading page: | ||
</span> | ||
<span class="hmr-propagation-dynamic">{{ barValue }}</span> | ||
<button class="hmr-propagation-dynamic-load" @click="loadDynamic()"> | ||
load | ||
</button> | ||
</p> | ||
<p> | ||
<span> | ||
HMR: edit the value of <code>baz</code> in | ||
<code>./testFullDynamicImportHmrPropagation.js</code>, the app should not | ||
update because the imported module is not self-accepting: | ||
</span> | ||
<span class="hmr-propagation-full-dynamic">{{ bazValue }}</span> | ||
<button | ||
class="hmr-propagation-full-dynamic-load" | ||
@click="loadFullDynamic()" | ||
> | ||
load | ||
</button> | ||
</p> | ||
<p> | ||
<span> | ||
HMR: edit the value of <code>__text</code> in | ||
<code>./testFullDynamicImportHmrPropagationSelfAccepting.js</code>, the | ||
app should update without reloading and the count state should persist, | ||
because the imported module is self-accepting: | ||
</span> | ||
<span | ||
class="hmr-propagation-full-dynamic-self-accepting" | ||
ref="dynamicDataOutlet" | ||
>qux not loaded</span | ||
> | ||
<button | ||
class="hmr-propagation-full-dynamic-load-self-accepting" | ||
@click="loadFullDynamicSelfAccepting()" | ||
> | ||
load | ||
</button> | ||
</p> | ||
<p> | ||
HMR: manual API (see console) - edit <code>./testHmrManual.js</code> and it | ||
should log new exported value without reloading the page. | ||
</p> | ||
</template> | ||
|
||
<script> | ||
import { ref } from 'vue' | ||
import { foo } from './testHmrPropagation' | ||
export default { | ||
setup() { | ||
const barValue = ref('bar not loaded') | ||
const bazValue = ref('baz not loaded') | ||
const dynamicDataOutlet = ref() | ||
return { | ||
count: 0, | ||
foo, | ||
barValue, | ||
bazValue, | ||
dynamicDataOutlet, | ||
loadDynamic() { | ||
barValue.value = 'bar loading' | ||
// This kind of dynamic import can be analyzed and rewrited by vite | ||
import('./testHmrPropagationDynamicImport').then(({ bar }) => { | ||
barValue.value = bar | ||
}) | ||
}, | ||
loadFullDynamic() { | ||
bazValue.value = 'baz loading' | ||
// This kind of dynamic import can't be analyzed and rewrited by vite | ||
import(dummy('./testHmrPropagationFullDynamicImport')).then( | ||
({ baz }) => { | ||
bazValue.value = baz | ||
} | ||
) | ||
}, | ||
loadFullDynamicSelfAccepting() { | ||
dynamicDataOutlet.value.innerHTML = 'qux loading' | ||
// This kind of dynamic import can't be analyzed and rewrited by vite | ||
import( | ||
dummy('./testHmrPropagationFullDynamicImportSelfAccepting') | ||
).then(({ render }) => { | ||
render(dynamicDataOutlet.value) | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
// make the imported path unanalysable in build time | ||
function dummy(value) { | ||
return value | ||
} | ||
</script> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const bar = 'bar loaded' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const baz = 'baz loaded' |
14 changes: 14 additions & 0 deletions
14
playground/TestHmr/testHmrPropagationFullDynamicImportSelfAccepting.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export let __text = 'qux loaded' | ||
|
||
let domEl | ||
|
||
export function render(_domEl) { | ||
domEl = _domEl | ||
domEl.innerHTML = __text | ||
} | ||
|
||
if (import.meta.hot) { | ||
import.meta.hot.accept((newModule) => { | ||
newModule.render(domEl) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters