Skip to content

Commit

Permalink
Add unit tests (#20)
Browse files Browse the repository at this point in the history
* start working on adding tests

* make tests work

* add 1.9-1.16 blocks and make them pass tests

* add github workflows

* make sure the file exists

* add a couple more tests
  • Loading branch information
mat-1 authored May 31, 2021
1 parent 55b06ff commit 19094f5
Show file tree
Hide file tree
Showing 2,202 changed files with 29,287 additions and 2,577 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build-push:
runs-on: ubuntu-latest
name: Compile Typescript
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14.15.0'
- run: npm install
- name: Compile Typescript
uses: FuLagann/tsc-build-push@v1
with:
user-name: "mat-1"
user-email: "github@matdoes.dev"
message: "Compiled TS into JS"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest
name: Run tests
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14.15.0'
- run: npm install

- name: Run tests
run: npm test
5 changes: 5 additions & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export declare const baseUrl = "https://raw.githubusercontent.com/skyblockstats/skyblock-assets/main";
export interface NBT {
ExtraAttributes?: {
id?: string;
Expand All @@ -14,5 +15,9 @@ export interface Options {
damage?: number;
nbt: NBT;
}
export declare let minecraftIds: {
[key: string]: string;
};
export declare function waitUntilReady(): Promise<void>;
/** Get the URL for the texture for a SkyBlock item */
export declare function getTextureUrl(options: Options): Promise<string>;
26 changes: 18 additions & 8 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTextureUrl = void 0;
exports.getTextureUrl = exports.waitUntilReady = exports.minecraftIds = exports.baseUrl = void 0;
const fs_1 = require("fs");
const path = __importStar(require("path"));
const baseUrl = 'https://raw.githubusercontent.com/skyblockstats/skyblock-assets/main';
exports.baseUrl = 'https://raw.githubusercontent.com/skyblockstats/skyblock-assets/main';
/** Read the contents of a json file */
async function readJsonFile(fileDir) {
const fileContents = await fs_1.promises.readFile(path.join(__dirname, fileDir), { encoding: 'utf8' });
Expand All @@ -43,10 +43,10 @@ async function readPacksMatchers() {
return matchers;
}
let matchers = {};
let minecraftIds = {};
exports.minecraftIds = {};
async function init() {
matchers = await readPacksMatchers();
minecraftIds = await readJsonFile('../data/minecraft_ids.json');
exports.minecraftIds = await readJsonFile('../data/minecraft_ids.json');
}
/** Check if all the values from checkerObj are the same in obj */
function objectsPartiallyMatch(obj, checkerObj) {
Expand Down Expand Up @@ -109,9 +109,9 @@ async function getTextures(options) {
// no matchers found, continue in 200ms because it'll probably have the matchers by then
await new Promise(resolve => setTimeout(resolve, 200));
}
if (minecraftIds[options.id.split(':')[0]]) {
if (exports.minecraftIds[options.id.split(':')[0]]) {
options.damage = parseInt(options.id.split(':')[1]);
options.id = minecraftIds[options.id.split(':')[0]];
options.id = exports.minecraftIds[options.id.split(':')[0]];
}
if (options.damage === undefined || isNaN(options.damage))
options.damage = 0;
Expand Down Expand Up @@ -142,9 +142,18 @@ async function getTextures(options) {
}
}
}
async function waitUntilReady() {
if (Object.keys(exports.minecraftIds).length === 0) {
// wait for it to init
while (Object.keys(exports.minecraftIds).length === 0)
await new Promise(resolve => setTimeout(resolve, 50));
}
}
exports.waitUntilReady = waitUntilReady;
/** Get the URL for the texture for a SkyBlock item */
async function getTextureUrl(options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
await waitUntilReady();
const textures = (_a = await getTextures(options)) !== null && _a !== void 0 ? _a : {};
const texturePath = (_j = (_h = (_g = (_f = (_e = (_d = (_c = (_b = textures.texture) !== null && _b !== void 0 ? _b : textures.layer0) !== null && _c !== void 0 ? _c : textures.fishing_rod) !== null && _d !== void 0 ? _d : textures.leather_boots_overlay) !== null && _e !== void 0 ? _e : textures.leather_chestplate_overlay) !== null && _f !== void 0 ? _f : textures.leather_helmet_overlay) !== null && _g !== void 0 ? _g : textures.leather_leggings_overlay) !== null && _h !== void 0 ? _h : textures.leather_layer_1) !== null && _j !== void 0 ? _j : textures.leather_layer_2;
// if it can't find a texture for this pack, just check using vanilla
Expand All @@ -155,8 +164,9 @@ async function getTextureUrl(options) {
});
}
if (!texturePath)
return null;
return baseUrl + '/' + texturePath.replace(/\\/g, '/');
return exports.baseUrl + '/renders/error.png';
else
return exports.baseUrl + '/' + texturePath.replace(/\\/g, '/');
}
exports.getTextureUrl = getTextureUrl;
init();
2 changes: 1 addition & 1 deletion data/minecraft_ids.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@
"2265": "minecraft:record_ward",
"2266": "minecraft:record_11",
"2267": "minecraft:record_wait"
}
}
68 changes: 67 additions & 1 deletion data/vanilla_damages.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@
"pink_tulip": "red_flower:7",
"oxeye_daisy": "red_flower:8",

"dandelion": "yellow_flower:0",

"sandstone_slab": "stone_slab:1",
"cobblestone_slab": "stone_slab:3",
"brick_slab": "stone_slab:4",
"stone_brick_slab": "stone_slab:5",
"nether_brick_slab": "stone_slab:6",
"quartz_slab": "stone_slab:7",

"red_sandstone_slab": "stone_slab2:0",

"white_stained_glass": "stained_glass:0",
"orange_stained_glass": "stained_glass:1",
"magenta_stained_glass": "stained_glass:2",
Expand Down Expand Up @@ -220,5 +224,67 @@

"dead_bush": "deadbush",

"oak_fence": "fence"
"oak_fence": "fence",

"oak_door": "wooden_door",

"oak_fence_gate": "fence_gate",

"banner": "banner:0",
"black_banner": "banner:0",
"red_banner": "banner:1",
"green_banner": "banner:2",
"brown_banner": "banner:3",
"blue_banner": "banner:4",
"purple_banner": "banner:5",
"cyan_banner": "banner:6",
"light_gray_banner": "banner:7",
"gray_banner": "banner:8",
"pink_banner": "banner:9",
"lime_banner": "banner:10",
"yellow_banner": "banner:11",
"light_blue_banner": "banner:12",
"magenta_banner": "banner:13",
"orange_banner": "banner:14",
"white_banner": "banner:15",

"end_stone_bricks": "end_bricks",
"magma_block": "magma",
"red_nether_bricks": "red_nether_brick",

"light_gray_shulker_box": "silver_shulker_box",

"white_concrete": "concrete:0",
"orange_concrete": "concrete:1",
"magenta_concrete": "concrete:2",
"light_blue_concrete": "concrete:3",
"yellow_concrete": "concrete:4",
"lime_concrete": "concrete:5",
"pink_concrete": "concrete:6",
"gray_concrete": "concrete:7",
"light_gray_concrete": "concrete:8",
"cyan_concrete": "concrete:9",
"purple_concrete": "concrete:10",
"blue_concrete": "concrete:11",
"brown_concrete": "concrete:12",
"green_concrete": "concrete:13",
"red_concrete": "concrete:14",
"black_concrete": "concrete:15",

"white_concrete_powder": "concrete_powder:0",
"orange_concrete_powder": "concrete_powder:1",
"magenta_concrete_powder": "concrete_powder:2",
"light_blue_concrete_powder": "concrete_powder:3",
"yellow_concrete_powder": "concrete_powder:4",
"lime_concrete_powder": "concrete_powder:5",
"pink_concrete_powder": "concrete_powder:6",
"gray_concrete_powder": "concrete_powder:7",
"light_gray_concrete_powder": "concrete_powder:8",
"cyan_concrete_powder": "concrete_powder:9",
"purple_concrete_powder": "concrete_powder:10",
"blue_concrete_powder": "concrete_powder:11",
"brown_concrete_powder": "concrete_powder:12",
"green_concrete_powder": "concrete_powder:13",
"red_concrete_powder": "concrete_powder:14",
"black_concrete_powder": "concrete_powder:15"
}
Loading

0 comments on commit 19094f5

Please sign in to comment.