Skip to content
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

fix(runtime-utils): devServer served html content didn't change after repacking. #5187

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/honest-cherries-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/runtime-utils': patch
---

fix(runtime-utils): FileReader#reset didn't clear storage as expected
fix(runtime-utils): FileReader#reset 没有按预期清除缓存的问题。
2 changes: 1 addition & 1 deletion packages/toolkit/runtime-utils/src/node/storer/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Storage<V = unknown> {
const keys = await this.keys?.();
await Promise.all(
keys?.map(async key => {
return this.delete(key);
return this.container.delete(key);
}) || [],
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tmp
30 changes: 30 additions & 0 deletions packages/toolkit/runtime-utils/tests/node/fileReader.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import * as FSModule from 'node:fs/promises';
import { fileReader } from '../../src/node/fileReader';

test('should fileReader work correctly', async () => {
Expand All @@ -16,3 +17,32 @@ test('should fileReader work correctly', async () => {
expect(res1).not.toBeNull();
expect(res).toMatch('modern');
});

describe('FileReader#cache', () => {
const tmpFile = path.resolve(__dirname, '../fixtures/fileReader/x.tmp');
const writeTmpFile = (content: string) =>
FSModule.writeFile(tmpFile, content);

const writeReadTmpFile = (content: string) =>
writeTmpFile(content).then(() => fileReader.readFile(tmpFile));

beforeEach(async () => {
await fileReader.reset();
// touch
await writeTmpFile('');
});
afterEach(async () => {
await FSModule.rm(tmpFile);
});

it('should read cached content first', async () => {
await expect(writeReadTmpFile('foo')).resolves.toBe('foo');
await expect(writeReadTmpFile('bar')).resolves.toBe('foo');
});

it('should read file again after FileReader reset', async () => {
await expect(writeReadTmpFile('foo2')).resolves.toBe('foo2');
await fileReader.reset();
await expect(writeReadTmpFile('bar2')).resolves.toBe('bar2');
});
});