You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have described how to get rid of the global Cypress objects like cy, Cypress, assertion methods, and Mocha's functions in the blog post https://glebbahmutov.com/blog/local-cypress/ While looking at the types I have noticed a few weird things:
the cypress-global-vars.d.ts imports the EventEmitter types, thus including the type NodeEventEmitter, but that type is already used in cypress.d.ts without an explicit import
Also just noticed that our on Action type does not return the object, thus this code is invalid but runs just fine
// @ts-check/// <reference types="cypress" />Cypress.on('test:before:run',()=>{console.log('before running a test')}).on('test:after:run',()=>{console.log('after running a test')})
So we should fix the Action interface to return this I think
Proposal
Rejigger the type imports a little bit. The end-user will not notice a difference, but the types will actually make more sense and will be easier to work with if one wants to avoid global type clashes.
The code for this is done in cypress-io/cypress#14992, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
Cypress v6.4.0
I have described how to get rid of the global Cypress objects like
cy
,Cypress
, assertion methods, and Mocha's functions in the blog post https://glebbahmutov.com/blog/local-cypress/ While looking at the types I have noticed a few weird things:cypress-global-vars.d.ts
imports the EventEmitter types, thus including the typeNodeEventEmitter
, but that type is already used incypress.d.ts
without an explicit importThus, to work around these things I had to repeat a bunch of code from Cypress types, see https://github.com/bahmutov/local-cypress/blob/main/index.ts
Also just noticed that our
on
Action type does not return the object, thus this code is invalid but runs just fineSo we should fix the
Action
interface to returnthis
I thinkProposal
Rejigger the type imports a little bit. The end-user will not notice a difference, but the types will actually make more sense and will be easier to work with if one wants to avoid global type clashes.
Outside of the scope
We can merge the type in our code and have the
cy
be just of typecy
, same for the top-levelCypress
typeI have opened #15022 for this part
The text was updated successfully, but these errors were encountered: