Skip to content

Commit 2aa99f5

Browse files
committed
Add testcase
1 parent 4721615 commit 2aa99f5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

packages/next-plugin/src/__tests__/css-loader.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,33 @@ describe('devupUICssLoader', () => {
383383
server.close()
384384
})
385385

386+
it('should error when readCoordinatorPort throws', async () => {
387+
const portFile = `test-coordinator-throw.port`
388+
389+
existsSyncSpy.mockImplementation((p: unknown) => p === portFile)
390+
readFileSyncSpy.mockImplementation((p: unknown) => {
391+
if (p === portFile) throw new Error('EACCES: permission denied')
392+
return '{}'
393+
})
394+
395+
const error = await new Promise<Error>((resolve) => {
396+
const asyncCallback = mock((err: Error | null) => {
397+
if (err) resolve(err)
398+
})
399+
devupUICssLoader.bind({
400+
async: () => asyncCallback,
401+
addContextDependency: mock(),
402+
getOptions: () => ({
403+
...defaultOptions,
404+
coordinatorPortFile: portFile,
405+
}),
406+
resourcePath: 'devup-ui.css',
407+
} as any)(Buffer.from(''), '', '')
408+
})
409+
410+
expect(error.message).toBe('EACCES: permission denied')
411+
})
412+
386413
it('should error when coordinator connection fails', async () => {
387414
const portFile = `test-coordinator-conn-err.port`
388415

0 commit comments

Comments
 (0)