From 6a6b4c7c5ba08bc42d1e03995f014d4ba68bd55f Mon Sep 17 00:00:00 2001 From: PBug Date: Fri, 26 Apr 2019 17:24:47 +0200 Subject: [PATCH] fix: msElapsed is now reset to 0 between multiple parses (#21) --- src/ReplayParser.ts | 1 + test/replays.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/ReplayParser.ts b/src/ReplayParser.ts index 5741095..aacc370 100644 --- a/src/ReplayParser.ts +++ b/src/ReplayParser.ts @@ -33,6 +33,7 @@ class ReplayParser extends EventEmitter{ parse($buffer: string) { console.time('parse') + this.msElapsed = 0 this.buffer = readFileSync($buffer) this.buffer = this.buffer.slice(this.buffer.indexOf('Warcraft III recorded game')) this.filename = $buffer diff --git a/test/replays.test.ts b/test/replays.test.ts index eb3cad6..ab040f3 100644 --- a/test/replays.test.ts +++ b/test/replays.test.ts @@ -82,6 +82,14 @@ describe('Replay parsing tests', () => { validatorInstance.validate(test, schema, {throwError: true}) }) + it('resets elapsedMS instance property to 0 before parsing another replay', () => { + Parser.parse(`./replays/standard_130.w3g`) + const msElapsed = Parser.msElapsed + Parser.parse(`./replays/standard_130.w3g`) + const msElapsedTwo = Parser.msElapsed + expect(msElapsed).toEqual(msElapsedTwo) + }) + it('parses a standard 1.30.2 replay properly', () => { const test = Parser.parse(`./replays/standard_1302.w3g`) expect(test.version).toBe('1.30.2+')