diff --git a/packages/driver/cypress/integration/util/breaking_change_warnings_spec.js b/packages/driver/cypress/integration/util/breaking_change_warnings_spec.js new file mode 100644 index 000000000000..52ce0067b3c6 --- /dev/null +++ b/packages/driver/cypress/integration/util/breaking_change_warnings_spec.js @@ -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. + }) + }) +}) diff --git a/packages/driver/src/cypress.js b/packages/driver/src/cypress.js index c17771339627..7adf60b03ff0 100644 --- a/packages/driver/src/cypress.js +++ b/packages/driver/src/cypress.js @@ -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) { @@ -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 diff --git a/packages/driver/src/cypress/error_messages.js b/packages/driver/src/cypress/error_messages.js index c5ae4f08f1cc..5ba0f468eff5 100644 --- a/packages/driver/src/cypress/error_messages.js +++ b/packages/driver/src/cypress/error_messages.js @@ -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}}`', }, diff --git a/packages/driver/src/util/breaking_change_warning.ts b/packages/driver/src/util/breaking_change_warning.ts new file mode 100644 index 000000000000..b1932414d27d --- /dev/null +++ b/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 +}