Skip to content
Permalink
Browse files

New: Enhance `can-evaluate::script` event

  • Loading branch information...
molant committed Oct 19, 2019
1 parent 4c54796 commit 214ad668983747424311cc7fb33e145c30ad1994
@@ -282,7 +282,10 @@ export default class JSDOMConnector implements IConnector {

this._document = htmlDocument;

const evaluateEvent: Event = { resource: this.finalHref };
const evaluateEvent = {
document: htmlDocument,
resource: this.finalHref
};

await this.server.emitAsync('can-evaluate::script', evaluateEvent);

@@ -48,7 +48,6 @@ import { JSDOM } from 'jsdom';
import { contentType, dom, fs, HTMLDocument, HTMLElement, logger, network } from '@hint/utils';

import {
CanEvaluateScript,
Engine,
Event,
FetchEnd,
@@ -151,7 +150,7 @@ export default class LocalConnector implements IConnector {
};
}

private async getGitIgnore () {
private async getGitIgnore() {
try {
const rawList = await readFileAsync(path.join(cwd(), '.gitignore'));
const splitList = rawList.split('\n');
@@ -316,7 +315,12 @@ export default class LocalConnector implements IConnector {

await traverse(this._document, this.engine, event.resource);

await this.engine.emitAsync('can-evaluate::script', { resource: this._href } as CanEvaluateScript);
const canEvaluateEvent = {
document: this._document,
resource: this._href
};

await this.engine.emitAsync('can-evaluate::script', canEvaluateEvent);
}

/*
@@ -265,8 +265,6 @@ export default class PuppeteerConnector implements IConnector {
private async processTarget() {
await this.waitForTarget();

const event = { resource: this._finalHref };

// QUESTION: Even if the content is blank we will receive a minimum HTML with this. Are we OK with the behavior?

const html = await this._page.content();
@@ -288,6 +286,11 @@ export default class PuppeteerConnector implements IConnector {
if (this._targetBody) {
await traverse(this._dom, this._engine, this._page.url());

const event = {
document: this._dom,
resource: this._finalHref
};

await this._engine.emitAsync('can-evaluate::script', event);
}
}
@@ -99,7 +99,12 @@ export default class WebExtensionConnector implements IConnector {
* Evaluate after the traversing, just in case something goes wrong
* in any of the evaluation and some scripts are left in the DOM.
*/
await this._engine.emitAsync('can-evaluate::script', { resource });
const event = {
document: this._document,
resource
};

await this._engine.emitAsync('can-evaluate::script', event);

this._onComplete(null, resource);

@@ -1,4 +1,4 @@
import { HTMLElement } from '@hint/utils/dist/src/dom/html';
import { HTMLElement, HTMLDocument } from '@hint/utils/dist/src/dom/html';
import { Event } from './event';
import { ElementEvents } from './element-events';
import { Problem } from '@hint/utils/dist/src/types/problems';
@@ -60,7 +60,9 @@ export type TraverseDown = Event & {
};

/** The object emitted by a connector on `can-evaluate` */
export type CanEvaluateScript = Event;
export type CanEvaluateScript = Event & {
document: HTMLDocument;
};

export type PrintEvent = Event & {
problems: Problem[];

0 comments on commit 214ad66

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