Buckets:
| import { getModuleContext } from './context' | |
| import { validateURL } from '../utils' | |
| jest.mock('../utils', () => ({ | |
| ...jest.requireActual('../utils'), | |
| validateURL: jest.fn(jest.requireActual('../utils').validateURL), | |
| })) | |
| const mockedValidateURL = jest.mocked(validateURL) | |
| describe('Next.js sandbox Request constructor', () => { | |
| let moduleContext: any | |
| beforeEach(async () => { | |
| mockedValidateURL.mockClear() | |
| moduleContext = await getModuleContext({ | |
| moduleName: 'test-module', | |
| onError: () => {}, | |
| onWarning: () => {}, | |
| useCache: false, | |
| distDir: '/tmp', | |
| edgeFunctionEntry: { | |
| assets: [], | |
| wasm: [], | |
| env: {}, | |
| }, | |
| }) | |
| }) | |
| it('should preserve Request method when copying Request in Next.js context', () => { | |
| const { Request: NextRequest } = moduleContext.runtime.context | |
| const originalRequest = new NextRequest('https://example.com', { | |
| method: 'POST', | |
| }) | |
| expect(originalRequest.method).toBe('POST') | |
| const copiedRequest = new NextRequest(originalRequest) | |
| expect(copiedRequest.method).toBe('POST') | |
| expect(copiedRequest.url).toBe('https://example.com/') | |
| }) | |
| it('should validate URL is called during Request construction', () => { | |
| const { Request: NextRequest } = moduleContext.runtime.context | |
| new NextRequest('https://example.com') | |
| expect(mockedValidateURL).toHaveBeenCalledWith('https://example.com') | |
| }) | |
| it('should handle Request with body and headers correctly', () => { | |
| const { Request: NextRequest } = moduleContext.runtime.context | |
| const originalRequest = new NextRequest('https://example.com', { | |
| method: 'POST', | |
| body: 'test body', | |
| headers: { 'Content-Type': 'application/json' }, | |
| }) | |
| const copiedRequest = new NextRequest(originalRequest) | |
| expect(copiedRequest.method).toBe('POST') | |
| expect(copiedRequest.headers.get('Content-Type')).toBe('application/json') | |
| }) | |
| it('should throw Next.js specific error for relative URLs', () => { | |
| const { Request: NextRequest } = moduleContext.runtime.context | |
| expect(() => new NextRequest('/urls-b')).toThrow( | |
| 'Please use only absolute URLs' | |
| ) | |
| }) | |
| }) | |
Xet Storage Details
- Size:
- 2.19 kB
- Xet hash:
- 0967b670d08d0884d52cf0431deace7c4195e49c8b0ec94595ad20c85c7181aa
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.