-
-
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.
- Loading branch information
Showing
2 changed files
with
8 additions
and
51 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
packages/vite/src/node/server/__tests__/fixtures/watched/index.js
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 |
---|---|---|
@@ -1,66 +1,24 @@ | ||
import { dirname, resolve } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { writeFileSync } from 'node:fs' | ||
import { afterEach, describe, expect, it } from 'vitest' | ||
import { describe, expect, it } from 'vitest' | ||
import { createServer } from '../index' | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
const stubGetWatchedCode = /getWatched\(\) \{.+?return \{\};.+?\}/s | ||
|
||
afterEach(() => { | ||
writeFileSync( | ||
resolve(__dirname, 'fixtures/watched/index.js'), | ||
"export const test = 'initial text'\n", | ||
) | ||
}) | ||
|
||
// watcher is unstable on windows | ||
describe.skipIf(process.platform === 'win32')('watcher configuration', () => { | ||
it("when watcher is disabled, editing files doesn't trigger watcher", async () => { | ||
describe('watcher configuration', () => { | ||
it('when watcher is disabled, return noop watcher', async () => { | ||
const server = await createServer({ | ||
server: { | ||
watch: null, | ||
}, | ||
}) | ||
server.watcher.on('change', () => { | ||
expect.unreachable() | ||
}) | ||
|
||
server.watcher.add(resolve(__dirname, 'fixtures/watched/index.js')) | ||
writeFileSync( | ||
resolve(__dirname, 'fixtures/watched/index.js'), | ||
'export const test = "new text"', | ||
) | ||
|
||
// make sure watcher doesn't trigger | ||
await new Promise((resolve) => setTimeout(resolve, 500)) | ||
expect(server.watcher.getWatched.toString()).toMatch(stubGetWatchedCode) | ||
}) | ||
|
||
it('when watcher is not disable, editing files triggers watcher', async () => { | ||
expect.assertions(1) | ||
it('when watcher is not disabled, return chokidar watcher', async () => { | ||
const server = await createServer({ | ||
server: { | ||
// "ready" event might not be triggered on macos otherwise | ||
watch: | ||
process.platform === 'darwin' | ||
? { | ||
useFsEvents: false, | ||
usePolling: false, | ||
} | ||
: {}, | ||
watch: {}, | ||
}, | ||
}) | ||
const filename = resolve(__dirname, 'fixtures/watched/index.js') | ||
|
||
return new Promise<void>((resolve) => { | ||
server.watcher.on('change', (e) => { | ||
expect(e).toMatch('/fixtures/watched/index.js') | ||
resolve() | ||
}) | ||
|
||
server.watcher.on('ready', () => { | ||
server.watcher.add(filename) | ||
writeFileSync(filename, 'export const test = "new text"') | ||
}) | ||
}) | ||
expect(server.watcher.getWatched.toString()).not.toMatch(stubGetWatchedCode) | ||
}) | ||
}) |