-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add stat enoent error test (#255)
* feature: add stat enoent error test * test
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/test-integration/test/PreviewProcessRangeRequestStatError.test.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,48 @@ | ||
import { expect, test } from '@jest/globals' | ||
import getPort from 'get-port' | ||
import { fileURLToPath } from 'url' | ||
import { connectToCdp } from '../src/parts/ConnectToCdp/ConnectToCdp.ts' | ||
import { createPreviewProcess } from '../src/parts/CreatePreviewProcess/CreatePreviewProcess.js' | ||
import { get } from '../src/parts/Get/Get.js' | ||
import { getRoot } from '../src/parts/GetRoot/GetRoot.js' | ||
import { mockModule } from '../src/parts/MockModule/MockModule.js' | ||
|
||
test('preview process - handles range request with stat ENOENT error', async () => { | ||
const debugPort = await getPort() | ||
const mockCdpImport = new URL('../src/mockCdpImport.js', import.meta.url).toString() | ||
const root = getRoot() | ||
const rootPath = fileURLToPath(root) | ||
const slash = process.platform === 'win32' ? '\\' : '/' | ||
const filePath = `${rootPath}${slash}any-file.txt` | ||
const previewProcess = createPreviewProcess({ | ||
execArgv: [`--inspect=localhost:${debugPort}`, '--experimental-strip-types', `--import=${mockCdpImport}`], | ||
}) | ||
|
||
const client = await connectToCdp(debugPort) | ||
|
||
await mockModule(client.Runtime, { | ||
moduleName: 'node:fs/promises', | ||
functionName: 'stat', | ||
filePath, | ||
errorMessage: 'File not found', | ||
errorCode: 'ENOENT', | ||
}) | ||
|
||
const id = 1 | ||
const port = await getPort() | ||
|
||
await previewProcess.invoke('WebViewServer.create', id) | ||
await previewProcess.invoke('WebViewServer.setHandler', id, '', root, '', '') | ||
await previewProcess.invoke('WebViewServer.start', id, port) | ||
|
||
const response = await get(`http://localhost:${port}/any-file.txt`, { | ||
headers: { | ||
Range: 'bytes=0-100', | ||
}, | ||
}) | ||
expect(response.status).toBe(404) | ||
expect(await response.text()).toBe('not found') | ||
|
||
await client[Symbol.dispose]() | ||
previewProcess[Symbol.dispose]() | ||
}) |