forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support disabling
watch
completely vitejs#14189
- Loading branch information
1 parent
91a18c2
commit b30f9d6
Showing
13 changed files
with
148 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import path from 'node:path' | ||
import fs from 'node:fs' | ||
import { createServer } from 'vite' | ||
import { afterEach, expect, test } from 'vitest' | ||
import { isBuild, page, ports } from '~utils' | ||
|
||
const filename = path.resolve(__dirname, '../src/header-text.mjs') | ||
const port = ports.watch | ||
const cleanups: (() => void | Promise<void>)[] = [] | ||
|
||
afterEach(async () => { | ||
await Promise.all(cleanups.splice(0).map((cleanup) => cleanup())) | ||
}) | ||
|
||
test.skipIf(isBuild)('watch mode is enabled by default', async () => { | ||
const server = await createServer({ | ||
root: path.join(__dirname, '..'), | ||
logLevel: 'silent', | ||
server: { | ||
port, | ||
strictPort: true, | ||
}, | ||
}) | ||
|
||
cleanups.push(() => server.close()) | ||
await server.listen() | ||
|
||
const initialHeader = 'Initial header' | ||
const newHeader = 'New header' | ||
|
||
await page.goto(`http://localhost:${port}`) | ||
expect(await page.textContent('h1')).toBe(initialHeader) | ||
|
||
// Edit file and wait for content to appear on page | ||
cleanups.push(() => | ||
fs.writeFileSync( | ||
filename, | ||
`export const headerText = "${initialHeader}";`, | ||
'utf8', | ||
), | ||
) | ||
fs.writeFileSync( | ||
filename, | ||
`export const headerText = "${newHeader}";`, | ||
'utf8', | ||
) | ||
|
||
await page.waitForSelector('text=New header') | ||
}) | ||
|
||
test.skipIf(isBuild)('watch mode can be disabled', async () => { | ||
const server = await createServer({ | ||
root: path.join(__dirname, '..'), | ||
logLevel: 'silent', | ||
server: { | ||
port, | ||
strictPort: true, | ||
watch: false, | ||
}, | ||
}) | ||
cleanups.push(() => server.close()) | ||
await server.listen() | ||
|
||
const initialHeader = 'Initial header' | ||
const newHeader = 'New header' | ||
|
||
await page.goto(`http://localhost:${port}`) | ||
expect(await page.textContent('h1')).toBe(initialHeader) | ||
|
||
cleanups.push(() => | ||
fs.writeFileSync( | ||
filename, | ||
`export const headerText = "${initialHeader}";`, | ||
'utf8', | ||
), | ||
) | ||
fs.writeFileSync( | ||
filename, | ||
`export const headerText = "${newHeader}";`, | ||
'utf8', | ||
) | ||
|
||
// Initial header should still be visible after some time | ||
await new Promise((r) => setTimeout(r, 1000)) | ||
expect(await page.textContent('h1')).toBe(initialHeader) | ||
}) |
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 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Watch</title> | ||
<script src="./src/index.mjs" type="module"></script> | ||
</head> | ||
<body> | ||
<h1>Watch</h1> | ||
</body> | ||
</html> |
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,9 @@ | ||
{ | ||
"name": "@vitejs/test-watch", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": {}, | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} |
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 headerText = 'Initial header' |
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 @@ | ||
import { headerText } from './header-text.mjs' | ||
|
||
document.querySelector('h1').textContent = headerText |