Team Ai
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 21d agoView on Hugging Face
0likes1.2kdownloads
abort.test.ts59 linesDownload Raw Back to unit
1import { isAbortError } from '$lib/utils/abort';2import { describe, expect, it } from 'vitest';3 4describe('isAbortError', () => {5	it('returns false for null, undefined and non-error values', () => {6		expect(isAbortError(null)).toBe(false);7		expect(isAbortError(undefined)).toBe(false);8		expect(isAbortError('string error')).toBe(false);9		expect(isAbortError({ name: 'AbortError' })).toBe(false);10		expect(isAbortError(42)).toBe(false);11	});12 13	it('returns true for DOMException with AbortError name', () => {14		const err = new DOMException('Operation was aborted', 'AbortError');15 16		expect(isAbortError(err)).toBe(true);17	});18 19	it('returns true for plain Error with AbortError name', () => {20		const err = new Error('aborted');21 22		err.name = 'AbortError';23		expect(isAbortError(err)).toBe(true);24	});25 26	it('returns false for unrelated Error instances', () => {27		expect(isAbortError(new Error('something failed'))).toBe(false);28		expect(isAbortError(new TypeError('not related'))).toBe(false);29		expect(isAbortError(new RangeError('out of range'))).toBe(false);30	});31 32	it('recognizes Firefox TypeError "Error in input stream" emitted at page unload', () => {33		expect(isAbortError(new TypeError('Error in input stream'))).toBe(true);34		expect(isAbortError(new TypeError('TypeError: Error in input stream'))).toBe(true);35	});36 37	it('recognizes Safari "The network connection was lost" during transient drop', () => {38		expect(isAbortError(new TypeError('The network connection was lost.'))).toBe(true);39	});40 41	it('recognizes Safari "Load failed" during page navigation', () => {42		expect(isAbortError(new TypeError('Load failed'))).toBe(true);43	});44 45	it('does NOT recognize generic TypeError messages as aborts', () => {46		// matching too broadly would hide real bugs, the predicate must stay conservative47		expect(isAbortError(new TypeError('Failed to fetch'))).toBe(false);48		expect(isAbortError(new TypeError('Cannot read property of undefined'))).toBe(false);49		expect(isAbortError(new TypeError('NetworkError when attempting to fetch resource'))).toBe(50			false51		);52	});53 54	it('is case insensitive on the matched substrings', () => {55		expect(isAbortError(new TypeError('error in INPUT STREAM'))).toBe(true);56		expect(isAbortError(new TypeError('the network connection WAS LOST'))).toBe(true);57	});58});59