Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
126 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useState } from 'react' | ||
import Child from './Child' | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<Child /> | ||
</div> | ||
) | ||
} | ||
|
||
export default App |
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,3 @@ | ||
export default function Child() { | ||
return <p>Child state 1</p> | ||
} |
61 changes: 61 additions & 0 deletions
61
packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts
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,61 @@ | ||
import { | ||
editFile, | ||
untilUpdated, | ||
removeFile, | ||
addFile, | ||
isBuild | ||
} from '../../testUtils' | ||
|
||
if (!isBuild) { | ||
test('should hmr when file is deleted and restored', async () => { | ||
await untilUpdated(() => page.textContent('p'), 'Child state 1') | ||
|
||
editFile('Child.jsx', (code) => | ||
code.replace('Child state 1', 'Child state 2') | ||
) | ||
|
||
await untilUpdated(() => page.textContent('p'), 'Child state 2') | ||
|
||
editFile('App.jsx', (code) => | ||
code | ||
.replace(`import Child from './Child'`, '') | ||
.replace(`<Child />`, '<p>Child deleted</p>') | ||
) | ||
removeFile('Child.jsx') | ||
await untilUpdated(() => page.textContent('p'), 'Child deleted') | ||
|
||
// restore Child.jsx | ||
addFile( | ||
'Child.jsx', | ||
` export default function Child() { | ||
return <p>Child state 1</p> | ||
} | ||
` | ||
) | ||
|
||
// restore App.jsx | ||
editFile( | ||
'App.jsx', | ||
(code) => | ||
`import { useState } from 'react' | ||
import Child from './Child' | ||
function App() { | ||
return ( | ||
<div className="App"> | ||
<Child /> | ||
</div> | ||
) | ||
} | ||
export default App | ||
` | ||
) | ||
|
||
await untilUpdated(() => page.textContent('p'), 'Child state 1') | ||
}) | ||
} else { | ||
test('dummy test to make jest happy', async () => { | ||
// Your test suite must contain at least one test. | ||
}) | ||
} |
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,8 @@ | ||
<div id="app"></div> | ||
<script type="module"> | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from './App.jsx' | ||
|
||
ReactDOM.render(React.createElement(App), document.getElementById('app')) | ||
</script> |
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,18 @@ | ||
{ | ||
"name": "test-file-delete-restore", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-react-refresh": "^1.3.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,15 @@ | ||
const reactRefresh = require('@vitejs/plugin-react-refresh') | ||
|
||
/** | ||
* @type {import('vite').UserConfig} | ||
*/ | ||
module.exports = { | ||
plugins: [reactRefresh()], | ||
build: { | ||
// to make tests faster | ||
minify: false | ||
}, | ||
esbuild: { | ||
jsxInject: `import React from 'react'` | ||
} | ||
} |
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