-
Notifications
You must be signed in to change notification settings - Fork 2.3k
chore(types): make plugins.ts more strongly-typed #3685
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import {By, error, ILocation, ISize, promise as wdpromise, WebDriver, WebElement | |
import {ElementHelper} from './browser'; | ||
import {ProtractorBrowser} from './browser'; | ||
import {IError} from './exitCodes'; | ||
import {Locator, ProtractorBy} from './locators'; | ||
import {Locator} from './locators'; | ||
import {Logger} from './logger'; | ||
|
||
let webdriver = require('selenium-webdriver'); | ||
|
@@ -1061,7 +1061,7 @@ export class ElementFinder extends WebdriverWebElement { | |
* @returns {ElementFinder} which identifies the located | ||
* {@link webdriver.WebElement} | ||
*/ | ||
export let build$ = (element: ElementHelper, by: ProtractorBy) => { | ||
export let build$ = (element: ElementHelper, by: typeof By) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's revert this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is this function is actually called with WebDriver's this.$ = build$(this.element, By);
this.$$ = build$$(this.element, By); Hence this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. I agree with the change. Thanks for this fix. |
||
return (selector: string) => { | ||
return element(by.css(selector)); | ||
}; | ||
|
@@ -1092,7 +1092,7 @@ export let build$ = (element: ElementHelper, by: ProtractorBy) => { | |
* @returns {ElementArrayFinder} which identifies the | ||
* array of the located {@link webdriver.WebElement}s. | ||
*/ | ||
export let build$$ = (element: ElementHelper, by: ProtractorBy) => { | ||
export let build$$ = (element: ElementHelper, by: typeof By) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
return (selector: string) => { | ||
return element.all(by.css(selector)); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.then(() => {})
This appears to not do anything. Should this be removed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. First of all, it doesn't do nothing, it converts
Promise<any[]>
toPromise<void>
, so that the return type ofProtractorBrowser#get
isPromise<void>
.onPageLoad
used to be typed simply asFunction
, but now that its type is inferred to be(...args: any[]) => webdriver.promise.Promise<any[]>
, it became apparent that the returned promise is resolved with an array (the result of the.all(...)
call inpluginFunFactory
), and this array seems to be totally useless. Moreover, the presence of this array can also have unexpected effects in run time. E.g. we may pass a function tothen
expecting that its argument would be undefined whereas in fact it'd get an array.That's why I'm thinking about moving
.then(() => {})
from here toPlugins#pluginFunFactory
, so that it generates functions of type(...args: any[]) => Promise<void>
. What are your thoughts on this? Are probably among those functions (setup
,onPrepare
, etc.) such whose resolved array value isn't meaningless?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I found that the array is meaningful for
waitForCondition
... It's used inbrowser.ts
:Which means
.then(() => {})
can't be moved topluginFunFactory
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the functions generated by
pluginFunFactory
are ever exposed to protractor users, so I'm not bothered by the fact that the promise resolves to something useless. Instead of this.then()
block - which is really only here for type checking - why not just cast this to a() => void
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions are exposed indirectly.
ProtractorBrowser#get
is exposed. The very line we're discussing now is its return statement. So it's not just type checking, it's public API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point 😄