-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: full-reload only when file-routes.json is added/changed
Fixes: #2277
- Loading branch information
Showing
2 changed files
with
64 additions
and
3 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
58 changes: 58 additions & 0 deletions
58
packages/ts/file-router/test/vite-plugin/vite-plugin.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,58 @@ | ||
import { use } from '@esm-bundle/chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { FSWatcher } from 'chokidar'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import vitePluginFileSystemRouter from '../../src/vite-plugin'; | ||
|
||
use(chaiAsPromised); | ||
use(sinonChai); | ||
|
||
describe('@vaadin/hilla-file-router', () => { | ||
describe('vite-plugin', () => { | ||
const watcher = new FSWatcher(); | ||
const mockServer = { | ||
hot: { | ||
send: sinon.spy(), | ||
}, | ||
watcher, | ||
}; | ||
const plugin = vitePluginFileSystemRouter({ isDevMode: true }); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
plugin.configResolved({ | ||
logger: { info: sinon.spy() }, | ||
root: '/path/to/project', | ||
build: { outDir: '/path/to/project/dist' }, | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-expect-error | ||
plugin.configureServer(mockServer); | ||
|
||
beforeEach(() => { | ||
sinon.resetHistory(); | ||
}); | ||
|
||
it('should send full-reload only when file-routes.json is added', () => { | ||
sinon.assert.notCalled(mockServer.hot.send); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
mockServer.watcher.emit('add', '/path/to/generated/file-routes.json'); | ||
sinon.assert.calledWith(mockServer.hot.send, { type: 'full-reload' }); | ||
}); | ||
|
||
it('should send full-reload only when file-routes.json changes', () => { | ||
sinon.assert.notCalled(mockServer.hot.send); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
mockServer.watcher.emit('change', '/path/to/generated/file-routes.json'); | ||
sinon.assert.calledWith(mockServer.hot.send, { type: 'full-reload' }); | ||
}); | ||
|
||
it('should not send full-reload when other files change', () => { | ||
sinon.assert.notCalled(mockServer.hot.send); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
mockServer.watcher.emit('change', '/path/to/views/file.tsx'); | ||
sinon.assert.notCalled(mockServer.hot.send); | ||
}); | ||
}); | ||
}); |