Skip to content

Commit

Permalink
adding console warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile committed May 13, 2022
1 parent 39f2825 commit 3c9c7ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/driver/cypress/integration/commands/cookies_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ describe('src/cy/commands/cookies', () => {
})
})

context('Cypress.cookies.defaults', () => {
context('Cypress.Cookies.defaults', () => {
it('throws error on use of renamed whitelist option', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include('`Cypress.Cookies.defaults` `whitelist` option has been renamed to `preserve`. Please rename `whitelist` to `preserve`.')
Expand All @@ -1266,5 +1266,21 @@ describe('src/cy/commands/cookies', () => {
whitelist: 'session_id',
})
})

it('logs deprecation warning', () => {
cy.stub(Cypress.utils, 'warning')

Cypress.Cookies.defaults({})
expect(Cypress.utils.warning).to.be.calledWith('`Cypress.Cookies.defaults()` has been deprecated and will be removed in a future release. Consider using `cy.session()` instead.\n\nhttps://on.cypress.io/session')
})
})

context('Cypress.Cookies.preserveOnce', () => {
it('logs deprecation warning', () => {
cy.stub(Cypress.utils, 'warning')

Cypress.Cookies.preserveOnce({})
expect(Cypress.utils.warning).to.be.calledWith('`Cypress.Cookies.preserveOnce()` has been deprecated and will be removed in a future release. Consider using `cy.session()` instead.\n\nhttps://on.cypress.io/session')
})
})
})
3 changes: 3 additions & 0 deletions packages/driver/src/cypress/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export const $Cookies = (namespace, domain) => {
},

preserveOnce (...keys) {
$errUtils.warnByPath('cookies.deprecated', { args: { cmd: 'Cypress.Cookies.preserveOnce' } })

return _.each(keys, (key) => {
return preserved[key] = true
})
Expand All @@ -140,6 +142,7 @@ export const $Cookies = (namespace, domain) => {
},

defaults (obj = {}) {
$errUtils.warnByPath('cookies.deprecated', { args: { cmd: 'Cypress.Cookies.defaults' } })
warnOnWhitelistRenamed(obj, 'Cypress.Cookies.defaults')

// merge obj into defaults
Expand Down
7 changes: 6 additions & 1 deletion packages/driver/src/cypress/error_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@ export default {
docsUrl: `https://on.cypress.io/${_.toLower(obj.cmd)}`,
}
},

deprecated (obj) {
return {
message: `${cmd(obj.cmd)} has been deprecated and will be removed in a future release. Consider using ${cmd('session')} instead.`,
docsUrl: 'https://on.cypress.io/session',
}
},
invalid_name (obj) {
return {
message: `${cmd('{{cmd}}')} must be passed an RFC-6265-compliant cookie name. You passed:\n\n\`{{name}}\``,
Expand Down

0 comments on commit 3c9c7ff

Please sign in to comment.