Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

test(webv2): cover rejected deferred resource path

joshistoastb8432facbe65
diff --git a/invokeai/frontend/webv2/src/workbench/deferredResource.test.ts b/invokeai/frontend/webv2/src/workbench/deferredResource.test.ts
index 8085d533ea..3a702d3997 100644
--- a/invokeai/frontend/webv2/src/workbench/deferredResource.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/deferredResource.test.ts
@@ -26,6 +26,27 @@ describe('deferred resource', () => {
expect(resource.getStatus()).toBe('loaded');
});
+ it('marks the promise rejected with the reason so use() does not suspend on failure either', async () => {
+ const error = new Error('cold');
+ const resource = createDeferredResource(() => Promise.reject(error));
+ const promise = resource.load() as Promise<string> & { reason?: unknown; status?: string };
+
+ await expect(promise).rejects.toThrow('cold');
+
+ expect(promise.status).toBe('rejected');
+ expect(promise.reason).toBe(error);
+ });
+
+ it('keeps the settled fields on the promise handed to later callers', async () => {
+ const resource = createDeferredResource(() => Promise.resolve('value'));
+
+ await resource.load();
+ const again = resource.load() as Promise<string> & { status?: string; value?: string };
+
+ expect(again.status).toBe('fulfilled');
+ expect(again.value).toBe('value');
+ });
+
it('reports failure and lets retry start a fresh attempt', async () => {
let attempt = 0;
const resource = createDeferredResource(() => {