-
-
Notifications
You must be signed in to change notification settings - Fork 477
fix: file reloading mechanism and add profile watch ignores #2112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZerGo0
wants to merge
9
commits into
wxt-dev:main
Choose a base branch
from
ZerGo0:fix/dev-watch-missed-reloads
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7354e74
fix: file reloading mechanism and add profile watch ignores
ZerGo0 0cf79bb
fix: file change detection and reloading logic
ZerGo0 41b2084
fix: keep createFileReloader out of the public API
ZerGo0 8767b01
fix: file reloading mechanism and add profile watch ignores
ZerGo0 4d0062d
fix: file change detection and reloading logic
ZerGo0 9e4d40d
fix: keep createFileReloader out of the public API
ZerGo0 d3c877f
Merge branch 'fix/dev-watch-missed-reloads' of github.com:ZerGo0/wxt …
ZerGo0 64889ee
fix: rebuild new entrypoints during dev reloads
ZerGo0 c5be896
Merge upstream/main into fix/dev-watch-missed-reloads
ZerGo0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,88 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { createFileReloader } from '../create-server'; | ||
| import { findEntrypoints, rebuild } from '../utils/building'; | ||
| import { | ||
| fakeBackgroundEntrypoint, | ||
| fakeBuildOutput, | ||
| fakeDevServer, | ||
| fakeOutputChunk, | ||
| setFakeWxt, | ||
| } from '../utils/testing/fake-objects'; | ||
|
|
||
| vi.mock('../utils/building', async () => { | ||
| const actual = | ||
| await vi.importActual<typeof import('../utils/building')>( | ||
| '../utils/building', | ||
| ); | ||
| return { | ||
| ...actual, | ||
| findEntrypoints: vi.fn(), | ||
| rebuild: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| describe('createFileReloader', () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| setFakeWxt({ | ||
| config: { | ||
| root: '/root', | ||
| dev: { | ||
| server: { | ||
| watchDebounce: 100, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| vi.mocked(findEntrypoints).mockResolvedValue([]); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it('should detect relevant file changes even when noisy file events happen first', async () => { | ||
| const relevantFile = '/root/src/entrypoints/background.ts'; | ||
| const noisyProfileFile = | ||
| '/root/private/.dev-profile/Default/Cache/Cache_Data/d573fa6484e43cf9_0'; | ||
| const backgroundEntrypoint = fakeBackgroundEntrypoint({ | ||
| inputPath: relevantFile, | ||
| }); | ||
| const currentOutput = fakeBuildOutput({ | ||
| steps: [ | ||
| { | ||
| entrypoints: backgroundEntrypoint, | ||
| chunks: [fakeOutputChunk({ moduleIds: [relevantFile] })], | ||
| }, | ||
| ], | ||
| publicAssets: [], | ||
| }); | ||
| const server = fakeDevServer({ | ||
| currentOutput, | ||
| reloadExtension: vi.fn(), | ||
| }); | ||
|
|
||
| vi.mocked(rebuild).mockResolvedValue({ | ||
| output: currentOutput, | ||
| manifest: currentOutput.manifest, | ||
| warnings: [], | ||
| }); | ||
|
|
||
| const reloadOnChange = createFileReloader(server); | ||
|
|
||
| const fixedFirst = reloadOnChange('change', noisyProfileFile); | ||
| await vi.advanceTimersByTimeAsync(50); | ||
| const fixedSecond = reloadOnChange('change', relevantFile); | ||
| await vi.advanceTimersByTimeAsync(500); | ||
| await Promise.all([fixedFirst, fixedSecond]); | ||
|
|
||
| expect(rebuild).toBeCalledTimes(1); | ||
| expect(rebuild).toBeCalledWith( | ||
| [], | ||
| [expect.objectContaining({ inputPath: relevantFile })], | ||
| expect.anything(), | ||
| ); | ||
| expect(server.reloadExtension).toBeCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.