|
1 | 1 | import { Buffer } from 'node:buffer' |
2 | 2 | import { |
| 3 | + appendFileSync, |
3 | 4 | mkdirSync, |
4 | 5 | mkdtempSync, |
5 | 6 | rmSync, |
@@ -1045,6 +1046,31 @@ describe('staticFileHandlerPlugin', () => { |
1045 | 1046 | expect(freshRes.status).toBe(304) |
1046 | 1047 | }) |
1047 | 1048 |
|
| 1049 | + it('never sends more bytes than content-length when the file grows after stat', async ({ |
| 1050 | + onTestFinished, |
| 1051 | + }) => { |
| 1052 | + const growingPath = path.join(rootDir, 'growing.txt') |
| 1053 | + const growingEmptyPath = path.join(rootDir, 'growing-empty.txt') |
| 1054 | + writeFileSync(growingPath, 'hello world') |
| 1055 | + writeFileSync(growingEmptyPath, '') |
| 1056 | + onTestFinished(() => { |
| 1057 | + rmSync(growingPath, { force: true }) |
| 1058 | + rmSync(growingEmptyPath, { force: true }) |
| 1059 | + }) |
| 1060 | + |
| 1061 | + const handler = new FetchRPCHandler({}, { plugins: [new StaticFileHandlerPlugin({ rootDir })] }) |
| 1062 | + |
| 1063 | + const served = await handler.handle(new Request('https://example.com/growing.txt')) |
| 1064 | + appendFileSync(growingPath, ' + appended') |
| 1065 | + expect(served.response!.headers.get('content-length')).toBe('11') |
| 1066 | + expect(await served.response!.text()).toBe('hello world') |
| 1067 | + |
| 1068 | + const servedEmpty = await handler.handle(new Request('https://example.com/growing-empty.txt')) |
| 1069 | + appendFileSync(growingEmptyPath, 'appended') |
| 1070 | + expect(servedEmpty.response!.headers.get('content-length')).toBe('0') |
| 1071 | + expect(await servedEmpty.response!.text()).toBe('') |
| 1072 | + }) |
| 1073 | + |
1048 | 1074 | describe('tracing', () => { |
1049 | 1075 | it('renames the active span to the mounted base path', async ({ onTestFinished }) => { |
1050 | 1076 | const span = { |
|
0 commit comments