Skip to content
Permalink
Browse files

Fix: `onHintEvent` race condition causing invalid `eventName`

  • Loading branch information...
antross committed Mar 14, 2019
1 parent 9a4172c commit 48b45ff6f5a94825f33cb83c4307e678b52da352
Showing with 4 additions and 3 deletions.
  1. +2 −1 packages/hint/src/lib/engine.ts
  2. +2 −2 packages/hint/tests/lib/engine.ts
@@ -229,6 +229,7 @@ export class Engine<E extends Events = Events> extends EventEmitter {
const urlsIgnoredForAll = that.ignoredUrls.get('all') || [];
const urlsIgnoredForHint = that.ignoredUrls.get(hintId) || [];
const urlsIgnored = urlsIgnoredForHint.concat(urlsIgnoredForAll);
const eventName = this.event; // eslint-disable-line no-invalid-this

if (that.isIgnored(urlsIgnored, (event as any).resource)) {
return null;
@@ -251,7 +252,7 @@ export class Engine<E extends Events = Events> extends EventEmitter {
}, that._timeout);

immediateId = setImmediate(async () => {
const result: any = await handler(event, this.event); // eslint-disable-line no-invalid-this
const result: any = await handler(event, eventName);

if (timeoutId) {
clearTimeout(timeoutId);
@@ -551,7 +551,7 @@ test(`If a hint is ignoring some url, it shouldn't run the event`, (t) => {

const Engine = loadScript(t.context);

new Engine({
const engine = new Engine({
browserslist: [],
connector: { name: 'connector' },
extends: [],
@@ -571,7 +571,7 @@ test(`If a hint is ignoring some url, it shouldn't run the event`, (t) => {

const eventHandler = t.context.eventemitter.EventEmitter2.prototype.on.args[0][1];

t.is(eventHandler({ resource: 'http://www.domain1.com/test' }), null);
t.is(eventHandler.call(engine, { resource: 'http://www.domain1.com/test' }), null);

t.context.eventemitter.EventEmitter2.prototype.on.restore();
});

0 comments on commit 48b45ff

Please sign in to comment.
You can’t perform that action at this time.