chore: linter and test
This commit is contained in:
parent
e5f5d887e3
commit
83edc1fbc7
@ -43,22 +43,55 @@ describe('LocalOAIEngine', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should load model correctly', async () => {
|
it('should load model correctly', async () => {
|
||||||
const model: Model = { engine: 'testProvider', file_path: 'path/to/model' } as any
|
const model: ModelFile = { engine: 'testProvider', file_path: 'path/to/model' } as any
|
||||||
|
const modelFolder = 'path/to'
|
||||||
|
const systemInfo = { os: 'testOS' }
|
||||||
|
const res = { error: null }
|
||||||
|
|
||||||
expect(engine.loadModel(model)).toBeTruthy()
|
;(dirName as jest.Mock).mockResolvedValue(modelFolder)
|
||||||
|
;(systemInformation as jest.Mock).mockResolvedValue(systemInfo)
|
||||||
|
;(executeOnMain as jest.Mock).mockResolvedValue(res)
|
||||||
|
|
||||||
|
await engine.loadModel(model)
|
||||||
|
|
||||||
|
expect(dirName).toHaveBeenCalledWith(model.file_path)
|
||||||
|
expect(systemInformation).toHaveBeenCalled()
|
||||||
|
expect(executeOnMain).toHaveBeenCalledWith(
|
||||||
|
engine.nodeModule,
|
||||||
|
engine.loadModelFunctionName,
|
||||||
|
{ modelFolder, model },
|
||||||
|
systemInfo
|
||||||
|
)
|
||||||
|
expect(events.emit).toHaveBeenCalledWith(ModelEvent.OnModelReady, model)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle load model error', async () => {
|
||||||
|
const model: any = { engine: 'testProvider', file_path: 'path/to/model' } as any
|
||||||
|
const modelFolder = 'path/to'
|
||||||
|
const systemInfo = { os: 'testOS' }
|
||||||
|
const res = { error: 'load error' }
|
||||||
|
|
||||||
|
;(dirName as jest.Mock).mockResolvedValue(modelFolder)
|
||||||
|
;(systemInformation as jest.Mock).mockResolvedValue(systemInfo)
|
||||||
|
;(executeOnMain as jest.Mock).mockResolvedValue(res)
|
||||||
|
|
||||||
|
await expect(engine.loadModel(model)).rejects.toEqual('load error')
|
||||||
|
|
||||||
|
expect(events.emit).toHaveBeenCalledWith(ModelEvent.OnModelFail, { error: res.error })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should unload model correctly', async () => {
|
it('should unload model correctly', async () => {
|
||||||
const model: Model = { engine: 'testProvider' } as any
|
const model: Model = { engine: 'testProvider' } as any
|
||||||
|
|
||||||
expect(engine.unloadModel(model)).toBeTruthy()
|
await engine.unloadModel(model)
|
||||||
|
|
||||||
|
expect(executeOnMain).toHaveBeenCalledWith(engine.nodeModule, engine.unloadModelFunctionName)
|
||||||
|
expect(events.emit).toHaveBeenCalledWith(ModelEvent.OnModelStopped, {})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not unload model if engine does not match', async () => {
|
it('should not unload model if engine does not match', async () => {
|
||||||
const model: Model = { engine: 'otherProvider' } as any
|
const model: Model = { engine: 'otherProvider' } as any
|
||||||
|
|
||||||
await engine.unloadModel(model)
|
await engine.unloadModel(model)
|
||||||
|
|
||||||
expect(executeOnMain).not.toHaveBeenCalled()
|
expect(executeOnMain).not.toHaveBeenCalled()
|
||||||
expect(events.emit).not.toHaveBeenCalledWith(ModelEvent.OnModelStopped, {})
|
expect(events.emit).not.toHaveBeenCalledWith(ModelEvent.OnModelStopped, {})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -88,8 +88,7 @@ const EventListenerWrapper = ({ children }: PropsWithChildren) => {
|
|||||||
if (state.downloadType !== 'extension') {
|
if (state.downloadType !== 'extension') {
|
||||||
state.downloadState = 'end'
|
state.downloadState = 'end'
|
||||||
setDownloadState(state)
|
setDownloadState(state)
|
||||||
if (state.percent !== 0)
|
if (state.percent !== 0) removeDownloadingModel(state.modelId)
|
||||||
removeDownloadingModel(state.modelId)
|
|
||||||
}
|
}
|
||||||
events.emit(ModelEvent.OnModelsUpdate, {})
|
events.emit(ModelEvent.OnModelsUpdate, {})
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user