Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
95% code test coverage (#51)
Browse files Browse the repository at this point in the history
* tests

* firesale

* fix

* im going to die

* fix

* fix

* Games

* Color

* misc change

* coco -> cocoa

* Rewrite Member Stats

* feat(getPlayer): add getplayer never logged in test

* Clean tests

* Check coverage

* fix

* better testing

* Meow

* code

* fix formatting

* Booster Test

* meow

* MeowWWW

* Test

* meow meow meow

* Testers

* fix

* feat(tests): add mock data for firesales

* 90% testers

* Change Data

* Move WatchdogStats

* fix idiot

* Bazaar

* Replace Usernames With UUID

* Move coverageCheck.ts

* Coverage Check change

* i hate my life. Please end it now fucking cunt

* update(skills): taming cap

* Tests

* Testersssszzszszszszsz 95% go brrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

* code i think

* Fix Urls

---------

Co-authored-by: Zickles <[email protected]>
  • Loading branch information
Kathund and Zickles authored Sep 7, 2024
1 parent d530b50 commit 0b9f9cd
Show file tree
Hide file tree
Showing 139 changed files with 17,543 additions and 2,455 deletions.
54 changes: 54 additions & 0 deletions .github/checkCoverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { parseString } from 'xml2js';
import { readFile } from 'fs';

function parseXMLFile(): Promise<any> {
return new Promise((resolve, reject) => {
readFile('.github/coverageData.xml', 'utf8', (err, data) => {
if (err) {
reject('File Dose not exist!');
return;
}

parseString(data, (err, result) => {
if (err) {
reject('Something Went wrong!');
return;
}

resolve(result);
});
});
});
}

const data = await parseXMLFile();
const codeStats = data.coverage.project[0].metrics[0].$;
const info = {
statements: Number(codeStats.statements),
coveredstatements: Number(codeStats.coveredstatements),
conditionals: Number(codeStats.conditionals),
coveredconditionals: Number(codeStats.coveredconditionals),
methods: Number(codeStats.methods),
coveredmethods: Number(codeStats.coveredmethods)
};

if (95 > (info.coveredstatements / info.statements) * 100) {
throw new Error('Statements is required to be 95% or higher');
}

if (95 > (info.coveredconditionals / info.conditionals) * 100) {
throw new Error('Conditionals is required to be 95% or higher');
}

if (95 > (info.coveredmethods / info.methods) * 100) {
throw new Error('Methods is required to be 95% or higher');
}

if (
95 >
((info.coveredstatements + info.coveredconditionals + info.coveredmethods) /
(info.statements + info.conditionals + info.methods)) *
100
) {
throw new Error('Everythng Combinded is required to be 95% or higher');
}
8 changes: 7 additions & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,10 @@ jobs:
- name: Check tests
env:
HYPIXEL_KEY: ${{ secrets.HYPIXEL_KEY }}
run: pnpm test
run: pnpm test:coverage

- name: Move Coverage Data
run: mv coverage/clover.xml .github/coverageData.xml

- name: Check Coverage
run: npx tsx .github/checkCoverage.ts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ oldreborn/
dist/
.eslintcache
coverage/
.github/coverageData.xml
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ oldreborn/
.eslintcache
.git
.gitignore
coverage/
coverage/
.github/coverageData.xml
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"prettier": "npx prettier --write src/",
"build": "npx tsc",
"test": "npx vitest run",
"test:coverage": "npx vitest --ui --coverage"
"test:coverage": "npx vitest run --coverage",
"test:ui": "npx vitest --ui --coverage"
},
"engines": {
"node": ">=20.16.0"
Expand Down Expand Up @@ -52,6 +53,7 @@
"@j4cobi/eslint-plugin-sort-imports": "^1.0.2",
"@types/eslint": "^9.6.1",
"@types/node": "^20.16.5",
"@types/xml2js": "^0.4.14",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/ui": "^2.0.5",
"dotenv": "^16.4.5",
Expand All @@ -61,6 +63,7 @@
"prettier": "^3.3.3",
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0",
"vitest": "^2.0.5"
"vitest": "^2.0.5",
"xml2js": "^0.6.2"
}
}
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions src/API/API.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export interface SkyblockRequestOptions extends RequestOptions {
garden?: boolean;
museum?: boolean;
}

export type GuildFetchOptions = 'id' | 'name' | 'player';
4 changes: 2 additions & 2 deletions src/API/getAchievements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { StaticGameNames } from '../typings';
import { expect, expectTypeOf, test } from 'vitest';

test('getAchievements (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getAchievements({ raw: true });
Expand All @@ -17,7 +17,7 @@ test('getAchievements (raw)', async () => {
});

test('getAchievements', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getAchievements();
Expand Down
8 changes: 4 additions & 4 deletions src/API/getActiveHouses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import House from '../structures/House';
import { expect, expectTypeOf, test } from 'vitest';

test('getActiveHouses (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getActiveHouses({ raw: true });
Expand All @@ -13,7 +13,7 @@ test('getActiveHouses (raw)', async () => {
});

test('getActiveHouses', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getActiveHouses();
Expand All @@ -30,9 +30,9 @@ test('getActiveHouses', async () => {
expect(house.owner).toBeDefined();
expectTypeOf(house.owner).toEqualTypeOf<string>();
expect(house.createdAtTimestamp).toBeDefined();
expectTypeOf(house.createdAtTimestamp).toEqualTypeOf<number>();
expectTypeOf(house.createdAtTimestamp).toEqualTypeOf<number | null>();
expect(house.createdAt).toBeDefined();
expectTypeOf(house.createdAt).toEqualTypeOf<Date>();
expectTypeOf(house.createdAt).toEqualTypeOf<Date | null>();
expect(house.players).toBeDefined();
expectTypeOf(house.players).toEqualTypeOf<number>();
expect(house.cookies).toBeDefined();
Expand Down
29 changes: 25 additions & 4 deletions src/API/getBoosters.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Booster from '../structures/Boosters/Booster';
import Client from '../Client';
import Game from '../structures/Game';
import Game, { GameCode, GameID, GameString } from '../structures/Game';
import { expect, expectTypeOf, test } from 'vitest';

test('getBoosters (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getBoosters({ raw: true });
Expand All @@ -14,7 +14,7 @@ test('getBoosters (raw)', async () => {
});

test('getBoosters', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getBoosters();
Expand All @@ -37,7 +37,28 @@ test('getBoosters', async () => {
expect(booster.activated).toBeDefined();
expectTypeOf(booster.activated).toEqualTypeOf<Date>();
expect(booster.game).toBeDefined();
expectTypeOf(booster.game).toEqualTypeOf<Game | null>();
expectTypeOf(booster.game).toEqualTypeOf<Game>();
expect(booster.game).toBeDefined();
expectTypeOf(booster.game).toEqualTypeOf<Game>();
expect(booster.game.game).toBeDefined();
expectTypeOf(booster.game.game).toEqualTypeOf<GameID | GameCode>();
expect(booster.game.id).toBeDefined();
expectTypeOf(booster.game.id).toEqualTypeOf<GameID | null>();
expect(booster.game.code).toBeDefined();
expectTypeOf(booster.game.code).toEqualTypeOf<GameCode | null>();
expect(booster.game.name).toBeDefined();
expectTypeOf(booster.game.name).toEqualTypeOf<GameString | null>();
expect(booster.game.found).toBeDefined();
expectTypeOf(booster.game.found).toEqualTypeOf<boolean>();
expect(booster.game.toString()).toBeDefined();
expect(booster.game.toString()).toBe(booster.game.name);
expectTypeOf(booster.game.toString()).toEqualTypeOf<GameString | null>();
expect(Game.IDS).toBeDefined();
expectTypeOf(Game.IDS).toEqualTypeOf<GameID[]>();
expect(Game.CODES).toBeDefined();
expectTypeOf(Game.CODES).toEqualTypeOf<GameCode[]>();
expect(Game.NAMES).toBeDefined();
expectTypeOf(Game.NAMES).toEqualTypeOf<GameString[]>();
expect(booster.isActive).toBeDefined();
expectTypeOf(booster.isActive).toEqualTypeOf<boolean>();
expect(booster.type).toBeDefined();
Expand Down
4 changes: 2 additions & 2 deletions src/API/getChallenges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StaticGameNames } from '../typings';
import { expect, expectTypeOf, test } from 'vitest';

test('getChallenges (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getChallenges({ raw: true });
Expand All @@ -15,7 +15,7 @@ test('getChallenges (raw)', async () => {
});

test('getChallenges', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getChallenges();
Expand Down
4 changes: 2 additions & 2 deletions src/API/getGameCounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import GameCounts from '../structures/GameCounts';
import { expect, expectTypeOf, test } from 'vitest';

test('getGameCounts (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getGameCounts({ raw: true });
Expand All @@ -13,7 +13,7 @@ test('getGameCounts (raw)', async () => {
});

test('getGameCounts', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const data = await client.getGameCounts();
Expand Down
Loading

0 comments on commit 0b9f9cd

Please sign in to comment.