Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/wxt/src/internal-utils/__tests__/network-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import * as dns from 'node:dns';
import { isOnline, fetchCached } from '../network-utils';
import { ResolvedConfig } from '../../types';
import consola from 'consola';

type DnsCallback = (err: NodeJS.ErrnoException | null) => void;

Expand All @@ -10,6 +11,12 @@ vi.mock('node:dns');
const fetchMock = vi.fn<typeof fetch>();
global.fetch = fetchMock;

vi.mock('consola', () => ({
default: {
error: vi.fn(),
},
}));

describe('Network utils', () => {
describe('isOnline', () => {
it('should return true when online', async () => {
Expand Down Expand Up @@ -43,6 +50,10 @@ describe('Network utils', () => {

const result = await isOnline();
expect(result).toBe(false);
expect(consola.error).toHaveBeenCalledWith(
'Error checking offline status:',
'Promise timed out after 1000ms',
);
});

it('should handle dns.resolve errors gracefully', async () => {
Expand All @@ -52,6 +63,10 @@ describe('Network utils', () => {

const result = await isOnline();
expect(result).toBe(false);
expect(consola.error).toHaveBeenCalledWith(
'Error checking offline status:',
expect.objectContaining({ message: 'DNS resolution failed' }),
);
});
});

Expand Down
Loading