forked from vitejs/vite
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
176 additions
and
40 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 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,113 @@ | ||
import { isBuild, editFile, untilUpdated } from '../../testUtils' | ||
|
||
test('should render', async () => { | ||
expect(await page.textContent('.app')).toBe('1') | ||
expect(await page.textContent('.dep')).toBe('1') | ||
expect(await page.textContent('.nested')).toBe('1') | ||
}) | ||
|
||
if (!isBuild) { | ||
test('should connect', async () => { | ||
expect(pageLogs.length).toBe(2) | ||
expect(pageLogs.some((msg) => msg.match('connected'))).toBe(true) | ||
pageLogs.length = 0 | ||
}) | ||
|
||
test('self accept', async () => { | ||
const el = await page.$('.app') | ||
|
||
editFile('hmr.js', (code) => code.replace('const foo = 1', 'const foo = 2')) | ||
await untilUpdated(() => el.textContent(), '2') | ||
|
||
expect(pageLogs).toMatchObject([ | ||
'foo was: 1', | ||
'(self-accepting 1) foo is now: 2', | ||
'(self-accepting 2) foo is now: 2', | ||
'[vite] hot updated: /hmr.js' | ||
]) | ||
pageLogs.length = 0 | ||
|
||
editFile('hmr.js', (code) => code.replace('const foo = 2', 'const foo = 3')) | ||
await untilUpdated(() => el.textContent(), '3') | ||
|
||
expect(pageLogs).toMatchObject([ | ||
'foo was: 2', | ||
'(self-accepting 1) foo is now: 3', | ||
'(self-accepting 2) foo is now: 3', | ||
'[vite] hot updated: /hmr.js' | ||
]) | ||
pageLogs.length = 0 | ||
}) | ||
|
||
test('accept dep', async () => { | ||
const el = await page.$('.dep') | ||
|
||
editFile('hmrDep.js', (code) => | ||
code.replace('const foo = 1', 'const foo = 2') | ||
) | ||
await untilUpdated(() => el.textContent(), '2') | ||
|
||
expect(pageLogs).toMatchObject([ | ||
'(dep) foo was: 1', | ||
'(dep) foo from dispose: 1', | ||
'(single dep) foo is now: 2', | ||
'(single dep) nested foo is now: 1', | ||
'(multi deps) foo is now: 2', | ||
'(multi deps) nested foo is now: 1', | ||
'[vite] hot updated: /hmrDep.js via /hmr.js' | ||
]) | ||
pageLogs.length = 0 | ||
|
||
editFile('hmrDep.js', (code) => | ||
code.replace('const foo = 2', 'const foo = 3') | ||
) | ||
await untilUpdated(() => el.textContent(), '3') | ||
|
||
expect(pageLogs).toMatchObject([ | ||
'(dep) foo was: 2', | ||
'(dep) foo from dispose: 2', | ||
'(single dep) foo is now: 3', | ||
'(single dep) nested foo is now: 1', | ||
'(multi deps) foo is now: 3', | ||
'(multi deps) nested foo is now: 1', | ||
'[vite] hot updated: /hmrDep.js via /hmr.js' | ||
]) | ||
pageLogs.length = 0 | ||
}) | ||
|
||
test('nested dep propagation', async () => { | ||
const el = await page.$('.nested') | ||
|
||
editFile('hmrNestedDep.js', (code) => | ||
code.replace('const foo = 1', 'const foo = 2') | ||
) | ||
await untilUpdated(() => el.textContent(), '2') | ||
|
||
expect(pageLogs).toMatchObject([ | ||
'(dep) foo was: 3', | ||
'(dep) foo from dispose: 3', | ||
'(single dep) foo is now: 3', | ||
'(single dep) nested foo is now: 2', | ||
'(multi deps) foo is now: 3', | ||
'(multi deps) nested foo is now: 2', | ||
'[vite] hot updated: /hmrDep.js via /hmr.js' | ||
]) | ||
pageLogs.length = 0 | ||
|
||
editFile('hmrNestedDep.js', (code) => | ||
code.replace('const foo = 2', 'const foo = 3') | ||
) | ||
await untilUpdated(() => el.textContent(), '3') | ||
|
||
expect(pageLogs).toMatchObject([ | ||
'(dep) foo was: 3', | ||
'(dep) foo from dispose: 3', | ||
'(single dep) foo is now: 3', | ||
'(single dep) nested foo is now: 3', | ||
'(multi deps) foo is now: 3', | ||
'(multi deps) nested foo is now: 3', | ||
'[vite] hot updated: /hmrDep.js via /hmr.js' | ||
]) | ||
pageLogs.length = 0 | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,26 +1,39 @@ | ||
import './hmrDep.js' | ||
import './style.css' | ||
import { foo as depFoo, nestedFoo } from './hmrDep' | ||
|
||
export const foo = 222233 | ||
export const foo = 1 | ||
text('.app', foo) | ||
text('.dep', depFoo) | ||
text('.nested', nestedFoo) | ||
|
||
if (import.meta.hot) { | ||
import.meta.hot.accept(({ foo }) => { | ||
console.log('(self-accepting)1.foo is now:', foo) | ||
console.log('(self-accepting 1) foo is now:', foo) | ||
}) | ||
|
||
import.meta.hot.accept(({ foo }) => { | ||
console.log('(self-accepting)2.foo is now:', foo) | ||
console.log('(self-accepting 2) foo is now:', foo) | ||
}) | ||
|
||
import.meta.hot.accept('./hmrDep', ({ foo }) => { | ||
console.log('(single dep) foo is now:', foo) | ||
const handleDep = (type, newFoo, newNestedFoo) => { | ||
console.log(`(${type}) foo is now: ${newFoo}`) | ||
console.log(`(${type}) nested foo is now: ${newNestedFoo}`) | ||
text('.dep', newFoo) | ||
text('.nested', newNestedFoo) | ||
} | ||
|
||
import.meta.hot.accept('./hmrDep', ({ foo, nestedFoo }) => { | ||
handleDep('single dep', foo, nestedFoo) | ||
}) | ||
|
||
import.meta.hot.accept(['./hmrDep'], (modules) => { | ||
console.log('(multiple deps) foo is now:', modules[0].foo) | ||
import.meta.hot.accept(['./hmrDep'], ([{ foo, nestedFoo }]) => { | ||
handleDep('multi deps', foo, nestedFoo) | ||
}) | ||
|
||
import.meta.hot.dispose(() => { | ||
console.log(`foo was:`, foo) | ||
}) | ||
} | ||
|
||
function text(el, text) { | ||
document.querySelector(el).textContent = text | ||
} |
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 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 |
---|---|---|
@@ -1 +1 @@ | ||
console.log('I should log?') | ||
export const foo = 1 |
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,5 @@ | ||
<script type="module" src="./hmr.js"></script> | ||
|
||
<div class="app"></div> | ||
<div class="dep"></div> | ||
<div class="nested"></div> |
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,10 @@ | ||
{ | ||
"name": "test-hmr", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite" | ||
} | ||
} |
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 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 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 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 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 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 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