diff --git a/packages/driver/cypress/integration/util/blob_spec.js b/packages/driver/cypress/integration/util/blob_spec.js new file mode 100644 index 000000000000..7446e6ee0183 --- /dev/null +++ b/packages/driver/cypress/integration/util/blob_spec.js @@ -0,0 +1,32 @@ +describe('blob-util 2.x', () => { + const { Blob, Promise } = Cypress + + // https://github.com/cypress-io/cypress/issues/8365 + ;[ + ['arrayBufferToBlob', '1234'], + ['base64StringToBlob', '1234'], + ['binaryStringToBlob', '0100101'], + ['dataURLToBlob', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='], + ].forEach(([method, value]) => { + it(`Cypress.Blob.${method} does not error when wrapped by Promise methods`, () => { + return Promise.all([ + Promise.resolve(Blob[method](value)), + Promise.try(() => Blob[method](value)), + ]) + }) + + it(`Cypress.Blob.${method} does not error with 5.0.0 workaround`, () => { + // this is the 5.0.0 workaround that the cypress-file-upload plugin uses + const wrapBlob = (blob) => { + delete blob.then + + return Cypress.Promise.resolve(blob) + } + + return Promise.all([ + Promise.resolve(wrapBlob(Blob[method](value))), + Promise.try(() => wrapBlob(Blob[method](value))), + ]) + }) + }) +}) diff --git a/packages/driver/cypress/integration/util/breaking_change_warnings_spec.js b/packages/driver/cypress/integration/util/breaking_change_warnings_spec.js deleted file mode 100644 index 5d3acf47228d..000000000000 --- a/packages/driver/cypress/integration/util/breaking_change_warnings_spec.js +++ /dev/null @@ -1,45 +0,0 @@ -describe('blob-util 2.x', () => { - it('arrayBufferToBlob', (done) => { - cy.on('fail', (err) => { - expect(err.message).to.include('no longer returns a `Promise`') - done() - }) - - Cypress.Blob.arrayBufferToBlob('1234').then((blob) => { - // it should fail. - }) - }) - - it('base64StringToBlob', (done) => { - cy.on('fail', (err) => { - expect(err.message).to.include('no longer returns a `Promise`') - done() - }) - - Cypress.Blob.base64StringToBlob('1234').then((blob) => { - // it should fail. - }) - }) - - it('binaryStringToBlob', (done) => { - cy.on('fail', (err) => { - expect(err.message).to.include('no longer returns a `Promise`') - done() - }) - - Cypress.Blob.binaryStringToBlob('0100101').then((blob) => { - // it should fail. - }) - }) - - it('dataURLToBlob', (done) => { - cy.on('fail', (err) => { - expect(err.message).to.include('no longer returns a `Promise`') - done() - }) - - 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 280803024402..a9661fe8cacf 100644 --- a/packages/driver/src/cypress.js +++ b/packages/driver/src/cypress.js @@ -34,7 +34,6 @@ 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) { @@ -646,7 +645,7 @@ $Cypress.prototype.SelectorPlayground = $SelectorPlayground $Cypress.prototype.utils = $utils $Cypress.prototype._ = _ $Cypress.prototype.moment = moment -$Cypress.prototype.Blob = wrapBlobUtil(blobUtil) +$Cypress.prototype.Blob = 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 1436bc622c31..8671a5521cf0 100644 --- a/packages/driver/src/cypress/error_messages.js +++ b/packages/driver/src/cypress/error_messages.js @@ -153,15 +153,6 @@ module.exports = { }, }, - breaking_change: { - blob_util2 (obj) { - return { - message: `\`${obj.functionName}()\` no longer returns a \`Promise\`. Update the use of \`${obj.functionName}()\` to expect a returned \`Blob\`.`, - docsUrl: 'https://on.cypress.io/migration-guide', - } - }, - }, - browser: { invalid_arg: '{{prefix}} must be passed a string, object, or an array. You passed: `{{obj}}`', }, @@ -385,9 +376,9 @@ module.exports = { not_scrollable: { message: stripIndent`\ ${cmd('{{cmd}}')} failed because this element is not scrollable: - + \`{{node}}\` - + Make sure you're targeting the correct element or use \`{ensureScrollable: false}\` to disable the scrollable check.`, docsUrl: 'https://on.cypress.io/scrollto', }, @@ -893,8 +884,8 @@ module.exports = { it('{{title}}', { retries: {{numRetries}} }, () => { ... }) - \`\`\` - + \`\`\` + https://on.cypress.io/test-retries `, manually_set_retries_suite: stripIndent`\ @@ -906,8 +897,8 @@ module.exports = { describe('{{title}}', { retries: {{numRetries}} }, () => { ... }) - \`\`\` - + \`\`\` + https://on.cypress.io/test-retries `, @@ -1856,9 +1847,9 @@ module.exports = { timed_out: { message: stripIndent` ${cmd('wrap')} timed out waiting \`{{timeout}}ms\` to complete. - + You called \`cy.wrap()\` with a promise that never resolved. - + To increase the timeout, use \`{ timeout: number }\` `, docsUrl: 'https://on.cypress.io/wrap', diff --git a/packages/driver/src/util/breaking_change_warning.ts b/packages/driver/src/util/breaking_change_warning.ts deleted file mode 100644 index 61671c661611..000000000000 --- a/packages/driver/src/util/breaking_change_warning.ts +++ /dev/null @@ -1,34 +0,0 @@ -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', { - args: { - functionName: key, - }, - }) - } - - return val - } - } else { - obj[key] = blobUtil[key] - } - }) - - return obj -}