Skip to content

Commit

Permalink
fix: corrected typo of basic_replay_information event in W3GReplay (#64)
Browse files Browse the repository at this point in the history
Also added typings for W3GReplay events.
  • Loading branch information
PBug90 authored Oct 16, 2020
1 parent de29d08 commit 39515ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/W3GReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ export type ChatMessage = {
type Team = {
[key: number]: number[];
};

class W3GReplay extends EventEmitter {
export default interface W3GReplay {
on(event: "gamedatablock", listener: (block: GameDataBlock) => void): this;
on(
event: "basic_replay_information",
listener: (data: BasicReplayInformation) => void
): this;
}
export default class W3GReplay extends EventEmitter {
info: BasicReplayInformation;
players: { [key: string]: Player };
observers: string[];
Expand Down Expand Up @@ -90,7 +96,7 @@ class W3GReplay extends EventEmitter {
"basic_replay_information",
(information: BasicReplayInformation) => {
this.handleBasicReplayInformation(information);
this.emit("basic_replay_inforamtion", information);
this.emit("basic_replay_information", information);
}
);
this.parser.on("gamedatablock", (block) => {
Expand Down Expand Up @@ -419,5 +425,3 @@ class W3GReplay extends EventEmitter {
return root;
}
}

export default W3GReplay;
3 changes: 3 additions & 0 deletions test/replays/132/replays.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ it("parse is a promise that resolves with parser output", async () => {
const Parser = new W3GReplay();
const timeslotBlocks = [];
let completedAsyncDummyTask = false;
const metadataCallback = jest.fn();
Parser.on("basic_replay_information", metadataCallback);
Parser.on("gamedatablock", (block: GameDataBlock) => {
if (block.id === 0x1f) {
timeslotBlocks.push(block);
Expand All @@ -75,6 +77,7 @@ it("parse is a promise that resolves with parser output", async () => {
expect(test.players.length).toBe(2);
expect(test.players[0].name).toBe("HurricaneBo");
expect(test.players[1].name).toBe("SimplyHunteR");
expect(metadataCallback).toHaveBeenCalledTimes(1);
});

it("handles truncated player names in reforged replays", async () => {
Expand Down

0 comments on commit 39515ab

Please sign in to comment.