Skip to content
Merged
Show file tree
Hide file tree
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: 2 additions & 13 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"registry": "https://registry.npmjs.org"
},
"dependencies": {
"cross-fetch": "^4.1.0",
"node-html-parser": "^9.0.0"
},
"devDependencies": {
Expand All @@ -67,7 +66,7 @@
"husky": "^9.1.7",
"lint-staged": "^17.2.0",
"prettier": "^3.9.6",
"quick-commitlint": "^0.1.0",
"quick-commitlint": "^0.1.1",
"rimraf": "^6.1.3",
"tsc-watch": "^7.2.1",
"typescript": "^6.0.3",
Expand Down
3 changes: 1 addition & 2 deletions src/clients/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'cross-fetch';
import { SoccerBotPlayer, SoccerBotResponse, SoccerBotTeam } from '../../shared/interfaces';

// see: https://www.whatismybrowser.com/guides/the-latest-user-agent/chrome
Expand Down Expand Up @@ -28,7 +27,7 @@ export abstract class SoccerBotClient {
const headers = {
'User-Agent': userAgent || this.userAgents[Math.floor(Math.random() * this.userAgents.length)]
};
const response = await fetch(url, { headers });
const response = await globalThis.fetch(url, { headers });
if (response.status >= 400 && response.status < 600) {
throw new Error(`Bad response ${response.status} for url: ${url}`);
}
Expand Down
7 changes: 3 additions & 4 deletions test/client/shared.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fetch from 'cross-fetch';
import { vi } from 'vitest';
import { SoccerBotClient, UserAgents } from '../../src/clients/shared';
import { SoccerBotPlayer, SoccerBotResponse, SoccerBotTeam } from '../../src/shared/interfaces';

vi.mock('cross-fetch', () => ({ default: vi.fn() }));

class TestClient extends SoccerBotClient {
public async league(): Promise<SoccerBotResponse<SoccerBotTeam[]>> {
return { ok: true, data: [] };
Expand All @@ -20,15 +17,17 @@ class TestClient extends SoccerBotClient {
}

describe('SoccerBotClient', () => {
const fetchMock = vi.mocked(fetch);
const fetchMock = vi.fn<typeof globalThis.fetch>();
let client: TestClient;

beforeEach(() => {
client = new TestClient();
fetchMock.mockReset();
vi.stubGlobal('fetch', fetchMock);
});

afterEach(() => {
vi.unstubAllGlobals();
vi.restoreAllMocks();
});

Expand Down