Numerous Bug Fixes
Some checks failed
Automated Container Build / build-and-push (push) Failing after 8s
Some checks failed
Automated Container Build / build-and-push (push) Failing after 8s
This commit is contained in:
parent
02eefdac0e
commit
267d429122
959 changed files with 145571 additions and 221 deletions
79
frontend/node_modules/make-cancellable-promise/src/index.spec.ts
generated
vendored
Normal file
79
frontend/node_modules/make-cancellable-promise/src/index.spec.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import makeCancellablePromise from './index.js';
|
||||
|
||||
vi.useFakeTimers();
|
||||
|
||||
describe('makeCancellablePromise()', () => {
|
||||
function resolveInFiveSeconds(): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve('Success');
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
function rejectInFiveSeconds() {
|
||||
return new Promise((_resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
reject(new Error('Error'));
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
it('resolves promise if not cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise } = makeCancellablePromise(resolveInFiveSeconds());
|
||||
|
||||
vi.advanceTimersByTime(5000);
|
||||
await promise.then(resolve).catch(reject);
|
||||
|
||||
expect(resolve).toHaveBeenCalledWith('Success');
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects promise if not cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
|
||||
vi.runAllTimers();
|
||||
await promise.then(resolve).catch(reject);
|
||||
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).toHaveBeenCalledWith(expect.any(Error));
|
||||
});
|
||||
|
||||
it('does not resolve promise if cancelled', async () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise, cancel } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
promise.then(resolve).catch(reject);
|
||||
|
||||
vi.advanceTimersByTime(2500);
|
||||
cancel();
|
||||
vi.advanceTimersByTime(2500);
|
||||
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not reject promise if cancelled', () => {
|
||||
const resolve = vi.fn();
|
||||
const reject = vi.fn();
|
||||
|
||||
const { promise, cancel } = makeCancellablePromise(rejectInFiveSeconds());
|
||||
promise.then(resolve).catch(reject);
|
||||
|
||||
vi.advanceTimersByTime(2500);
|
||||
cancel();
|
||||
vi.advanceTimersByTime(2500);
|
||||
|
||||
expect(resolve).not.toHaveBeenCalled();
|
||||
expect(reject).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
19
frontend/node_modules/make-cancellable-promise/src/index.ts
generated
vendored
Normal file
19
frontend/node_modules/make-cancellable-promise/src/index.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export default function makeCancellablePromise<T>(promise: Promise<T>): {
|
||||
promise: Promise<T>;
|
||||
cancel(): void;
|
||||
} {
|
||||
let isCancelled = false;
|
||||
|
||||
const wrappedPromise: Promise<T> = new Promise((resolve, reject) => {
|
||||
promise
|
||||
.then((value) => !isCancelled && resolve(value))
|
||||
.catch((error) => !isCancelled && reject(error));
|
||||
});
|
||||
|
||||
return {
|
||||
promise: wrappedPromise,
|
||||
cancel() {
|
||||
isCancelled = true;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in a new issue