-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add TypeScript support for Cypress action events #1187
feat: Add TypeScript support for Cypress action events #1187
Conversation
cli/types/index.d.ts
Outdated
@@ -2934,6 +2942,130 @@ declare namespace Cypress { | |||
(fn: (currentSubject: Subject) => void): Chainable<Subject> | |||
} | |||
|
|||
/** | |||
* These events come from the application currently under test (your application). These are the most useful events for you to listen to. | |||
* @see https://docs.cypress.io/api/events/catalog-of-events.html#App-Events |
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.
One thing we REALLY do not want is to put direct urls to any resource, because these are likely to change. The same url should go through our on.cypress.io
redirect service. Usually it is just document title, this url would be https://on.cypress.io/catalog-of-events#App-Events
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.
Oh. Thanks. That was one of my review comments. I was trying to figure out what the redirect URL was
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.
Updated the URLs. Is there a conventions for those URL redirects? I tried a few including https://on.cypress.io/events/catalog-of-events#App-Events
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.
All good except for direct documentation url
cli/types/index.d.ts
Outdated
* // failing the test | ||
* return false | ||
* }) | ||
* @see https://docs.cypress.io/api/events/catalog-of-events.html#App-Events |
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.
Should there be linkability to individual events? Right now this will jump to the table of actions. Also I don't know if that is the official URL. I noticed the Cypress team use a redirect URL for Cypress commands. I couldn't find anything that matched that pattern (on.cypress.io/...
) that redirected to the correct page. Feel free to suggest a redirect URL.
cli/types/index.d.ts
Outdated
* }) | ||
* @see https://docs.cypress.io/api/events/catalog-of-events.html#App-Events | ||
*/ | ||
(action: 'uncaught:exception', fn: (error: Error, runnable: Mocha.IRunnable) => false | void): 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.
The docs said it is the mocha runnable. I'm assuming this is the interface the docs meant
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.
I included an example only in this action. This action at least gives an template for other actions to have examples added.
cli/types/index.d.ts
Outdated
* Fires before the test and all **before** and **beforeEach** hooks run. | ||
* @see https://docs.cypress.io/api/events/catalog-of-events.html#App-Events | ||
*/ | ||
(action: 'test:before:run', fn: (attributes: ObjectLike, test: Mocha.ITest) => void): 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.
It was hard to tell what this object might look like. I couldn't find a clear emitter of this event. I found emitting of the :async
version referenced in socket.coffee
. Feel free to reference a file for more clear typing. Right now ObjectLike
says there can by any key in the object that has a value of any
. Object
or object
won't work because then it is an object with no properties.
(action: 'test:after:run', fn: (attributes: ObjectLike, test: Mocha.ITest) => void): void | ||
} | ||
|
||
// $CommandQueue from `command_queue.coffee` - a lot to type. Might be more useful if it was written in TS |
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.
I didn't spend too much time fleshing out this entire interface. There is some implicit method definitions that come straight from lodash. I don't know if it is worth the effort before $CommandQueue
is written in TypeScript. I added methods I thought might be important. Feel free to chime in if there are specific methods or properties that should be important to an external developers using the the command action event callbacks
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.
absolutely, looks good
@@ -2960,6 +3092,14 @@ declare namespace Cypress { | |||
expiry?: string | |||
} | |||
|
|||
interface EnqueuedCommand { | |||
name: string | |||
args: any[] |
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.
I think any
is all that we can guarantee. There could be a lot of work to create an interface of internal mapping of named commands like select
with argument shapes. I don't know if that is worthwhile right now. It would make more sense if command implementations are written in TypeScript. This at least won't give any errors. I consider these events pretty advanced and will probably require an understanding of the source code anyways. any
could always be cast to a more specific type in that case.
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.
yes
args: any[] | ||
type: string | ||
chainerId: string | ||
fn(...args: any[]): any |
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.
I didn't dig far enough to find out what the shape of this was
@@ -2994,6 +3134,11 @@ declare namespace Cypress { | |||
whitelist: (xhr: any) => boolean | |||
} | |||
|
|||
interface Viewport { |
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.
I found this in window.coffee
I'll look into that unit test failure. |
Just add |
I updated and could reproduce the issue. I set the tslint.json setting and now only have a TypeScript error on |
It was suggested maybe this PR broke it? microsoft/TypeScript#17912 |
Yes I just put single and ignore for that particular line
…Sent from my iPhone
On Jan 11, 2018, at 15:54, Nicholas Boll ***@***.***> wrote:
I updated and could reproduce the issue. I set the tslint.json setting and now only have a TypeScript error on ***@***.*** around the Omit implementation. This is probably a bug in TypeScript that will get resolved since there is otherwise no way of omitting properties of an interface.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I added a fix. The TypeScript team has filed an issue: microsoft/TypeScript#21148 I hope they will have a solution before TypeScript 2.7 comes out (either fixed or a workaround provided to library authors). Right now it works. I guess we'll see what happens later. Worst thing for the Cypress type definitions is changing |
It looks like the error will be fixed before TypeScript 2.7 ships: microsoft/TypeScript#21156 |
Released in |
Fixes #1186
Cypress.on
andcy.on