Skip to content

Commit

Permalink
New: Add event fetch::start::target
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvaje authored and alrra committed May 15, 2018
1 parent 78565b9 commit 2bc0d99
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Connector implements IConnector {
return;
}

const eventName: string = 'fetch::start';
const eventName: string = this._href === requestUrl ? 'fetch::start::target' : 'fetch::start';

debug(`About to start fetching ${cutString(requestUrl)}`);

Expand Down
2 changes: 1 addition & 1 deletion packages/sonarwhal/src/lib/connectors/jsdom/jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export default class JSDOMConnector implements IConnector {
return new Promise(async (resolve, reject) => {

debug(`About to start fetching ${href}`);
await this._server.emitAsync('fetch::start', initialEvent);
await this._server.emitAsync('fetch::start::target', initialEvent);

try {
this._targetNetworkData = await this.fetchContent(target);
Expand Down
2 changes: 1 addition & 1 deletion packages/sonarwhal/src/lib/connectors/local/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default class LocalConnector implements IConnector {
let files;

if (isFile(pathString)) {
await this.sonarwhal.emitAsync('fetch::start', initialEvent);
await this.sonarwhal.emitAsync('fetch::start::target', initialEvent);
files = [pathString];
} else {
// TODO: the current @types/globby doesn't support gitignore. Remove "as any" when possible
Expand Down
2 changes: 1 addition & 1 deletion packages/sonarwhal/tests/lib/connectors/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { IConnector, IConnectorConstructor } from '../../../src/lib/types';
/** The minimum set of events the connectors need to implement. */
const events = [
['scan::start', { resource: 'http://localhost/' }],
['fetch::start', { resource: 'http://localhost/' }],
['fetch::start::target', { resource: 'http://localhost/' }],
['fetch::end::html', {
resource: 'http://localhost/',
request: { url: 'http://localhost/' },
Expand Down
8 changes: 4 additions & 4 deletions packages/sonarwhal/tests/lib/connectors/local/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.beforeEach((t) => {
t.context.misc = { isFile() { } };
});

test(`If target is a file, it should emit 'fetch::start' event`, async (t) => {
test(`If target is a file, it should emit 'fetch::start::target' event`, async (t) => {
const fileUri = getAsUri(path.join(__dirname, 'fixtures', 'no-watch', 'script.js'));

const sandbox = sinon.createSandbox();
Expand All @@ -41,7 +41,7 @@ test(`If target is a file, it should emit 'fetch::start' event`, async (t) => {

t.is(t.context.sonarwhal.emitAsync.callCount, 4);
t.is(t.context.sonarwhal.emitAsync.args[0][0], 'scan::start');
t.is(t.context.sonarwhal.emitAsync.args[1][0], 'fetch::start');
t.is(t.context.sonarwhal.emitAsync.args[1][0], 'fetch::start::target');
t.is(t.context.sonarwhal.emitAsync.args[2][0], 'fetch::end::script');

sandbox.restore();
Expand All @@ -61,7 +61,7 @@ test(`If target is a html file, it should emit 'fetch::end::html' event instead

t.is(t.context.sonarwhal.emitAsync.callCount, 4);
t.is(t.context.sonarwhal.emitAsync.args[0][0], 'scan::start');
t.is(t.context.sonarwhal.emitAsync.args[1][0], 'fetch::start');
t.is(t.context.sonarwhal.emitAsync.args[1][0], 'fetch::start::target');
t.is(t.context.sonarwhal.emitAsync.args[2][0], 'fetch::end::html');

sandbox.restore();
Expand Down Expand Up @@ -127,7 +127,7 @@ test(`If target is an image, 'content' is empty`, async (t) => {
sandbox.restore();
});

test(`If target is a directory, shouldn't emit the event 'fetch::start'`, async (t) => {
test(`If target is a directory, shouldn't emit the event 'fetch::start::target'`, async (t) => {
const directoryUri = getAsUri(path.join(__dirname, 'fixtures', 'no-watch'));

const sandbox = sinon.createSandbox();
Expand Down

0 comments on commit 2bc0d99

Please sign in to comment.