Skip to content

Commit

Permalink
Show warning message.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Jul 2, 2020
1 parent 3ac8e59 commit f923f0b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
@@ -0,0 +1,41 @@
describe('blob-util 2.x', () => {
it('arrayBufferToBlob', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('Cypress 5+ uses `blob-util` 2.x')
})

Cypress.Blob.arrayBufferToBlob('1234').then((blob) => {
// it should fail.
})
})

it('base64StringToBlob', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('Cypress 5+ uses `blob-util` 2.x')
})

Cypress.Blob.base64StringToBlob('1234').then((blob) => {
// it should fail.
})
})

it('binaryStringToBlob', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('Cypress 5+ uses `blob-util` 2.x')
})

Cypress.Blob.binaryStringToBlob('0100101').then((blob) => {
// it should fail.
})
})

it('dataURLToBlob', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('Cypress 5+ uses `blob-util` 2.x')
})

Cypress.Blob.dataURLToBlob('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==').then((blob) => {
// it should fail.
})
})
})
3 changes: 2 additions & 1 deletion packages/driver/src/cypress.js
Expand Up @@ -34,6 +34,7 @@ const $scriptUtils = require('./cypress/script_utils')
const browserInfo = require('./cypress/browser')
const resolvers = require('./cypress/resolvers')
const debug = require('debug')('cypress:driver:cypress')
const { wrapBlobUtil } = require('./util/breaking_change_warning')

const jqueryProxyFn = function (...args) {
if (!this.cy) {
Expand Down Expand Up @@ -613,7 +614,7 @@ $Cypress.prototype.SelectorPlayground = $SelectorPlayground
$Cypress.prototype.utils = $utils
$Cypress.prototype._ = _
$Cypress.prototype.moment = moment
$Cypress.prototype.Blob = blobUtil
$Cypress.prototype.Blob = wrapBlobUtil(blobUtil)
$Cypress.prototype.Promise = Promise
$Cypress.prototype.minimatch = minimatch
$Cypress.prototype.sinon = sinon
Expand Down
7 changes: 7 additions & 0 deletions packages/driver/src/cypress/error_messages.js
Expand Up @@ -153,6 +153,13 @@ module.exports = {
},
},

breaking_change: {
blob_util2: {
message: 'Cypress 5+ uses `blob-util` 2.x. This function does not return `Promise` any more.',
docsUrl: 'https://docs.cypress.io/guides/references/migration-guide.html',
},
},

browser: {
invalid_arg: '{{prefix}} must be passed a string, object, or an array. You passed: `{{obj}}`',
},
Expand Down
30 changes: 30 additions & 0 deletions packages/driver/src/util/breaking_change_warning.ts
@@ -0,0 +1,30 @@
import $errUtil from '../cypress/error_utils'

export function wrapBlobUtil (blobUtil) {
const breakingChanges = [
'arrayBufferToBlob',
'base64StringToBlob',
'binaryStringToBlob',
'dataURLToBlob',
]

const obj = {}

Object.keys(blobUtil).forEach((key) => {
if (breakingChanges.includes(key)) {
obj[key] = function (...args) {
const val = blobUtil[key](...args)

val.then = function () {
$errUtil.throwErrByPath('breaking_change.blob_util2')
}

return val
}
} else {
obj[key] = blobUtil[key]
}
})

return obj
}

0 comments on commit f923f0b

Please sign in to comment.