Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

chore(refactor): Pull proxy logic out and add unit tests around it. #22

Merged
merged 12 commits into from
Jan 23, 2017

Conversation

heathkit
Copy link
Contributor

Note that this is based on #21 and should be reviewed after that's merged.

This pulls out the the proxy/wait behavior into a separate module so we can unit test it. The idea is that the proxy waits for promises from barriers (not married to the name, suggestions welcome) to resolve before proceeding.

@heathkit heathkit force-pushed the 2-webdriver-refactor branch 2 times, most recently from 5c04379 to 8dca8ae Compare January 23, 2017 20:40
@@ -1,6 +1,8 @@
/**
* Utilities for parsing WebDriver commands from HTTP Requests.
*/
import * as events from 'events';
import * as http from 'http';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think http is unused here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I'll turn on the no-unused-variable lint check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, rather, TypeScript 2.1 now has --noUnusedLocals

}
}

export interface WebDriverBarrier { onCommand(command: WebDriverCommand): Promise<void>; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line at eof

}, replyWithError);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class-level comment for WebDriverBarrier would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

this.barriers.push(barrier);
}

requestListener(originalRequest: http.IncomingMessage, response: http.ServerResponse) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming requestListener to request or handle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

response.end();
};

// TODO: What happens when barriers error? return a client error?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should reply to the initial response with a 500 and an error message chosen by the barrier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, if the barrier rejects its promise, we use that value as the error.

};

// TODO: What happens when barriers error? return a client error?
let barrierPromises = this.barriers.map((b) => b.onCommand(command));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could result in multiple barriers executing at once, which might confuse webdriver if for example two barriers are both calling executeScript. I think we should gate them to running one at a time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed.


it('should provide hooks when relaying commands',
() => {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

done();
});
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add newline at eof

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

let proxy: WebDriverProxy;

beforeEach(() => {
proxy = new WebDriverProxy(`http://localhost:4444/wd/hub`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nonsense url, right? Can we make that clearer, like http://test_webdriver_url?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@heathkit heathkit force-pushed the 2-webdriver-refactor branch from 8dca8ae to f3f81df Compare January 23, 2017 22:22
* A proxy that understands WebDriver commands. Users can add middleware (similar to middleware in
* express) that will be called before
* forwarding the request to WebDriver or forwarding the response to the client.
* A proxy that understands WebDriver commands. Users can add barriers * (similar to middleware in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra * made it into this line.

@juliemr
Copy link
Member

juliemr commented Jan 23, 2017

LGTM with one typo.

@heathkit heathkit merged commit e9e13ff into angular:master Jan 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants