Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update blob-util to 2.0.2 #7795

Merged
merged 7 commits into from Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/package.json
Expand Up @@ -26,6 +26,7 @@
"@types/sinonjs__fake-timers": "6.0.1",
"@types/sizzle": "2.3.2",
"arch": "2.1.2",
"blob-util": "2.0.2",
"bluebird": "3.7.2",
"cachedir": "2.3.0",
"chalk": "4.1.0",
Expand Down Expand Up @@ -63,7 +64,6 @@
"@babel/preset-env": "7.9.5",
"@cypress/sinon-chai": "1.1.0",
"@packages/root": "*",
"@types/blob-util": "1.3.3",
"@types/bluebird": "3.5.29",
"@types/chai": "4.2.7",
"@types/chai-jquery": "1.1.40",
Expand Down
1 change: 0 additions & 1 deletion cli/scripts/utils.js
Expand Up @@ -4,7 +4,6 @@
* definition files that we will need to include with our NPM package.
*/
const includeTypes = [
'blob-util',
'bluebird',
'lodash',
'mocha',
Expand Down
2 changes: 1 addition & 1 deletion cli/types/cy-blob-util.d.ts
Expand Up @@ -3,7 +3,7 @@
// so that Cypress can get and use the Blob type

// tslint:disable-next-line:no-implicit-dependencies
import * as blobUtil from './blob-util'
import * as blobUtil from 'blob-util'

export = BlobUtil
export as namespace BlobUtil
Expand Down
@@ -0,0 +1,41 @@
describe('blob-util 2.x', () => {
it('arrayBufferToBlob', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('no longer returns a `Promise`')
})

Cypress.Blob.arrayBufferToBlob('1234').then((blob) => {
// it should fail.
})
})
Comment on lines +2 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A (done) callback parameter must be yielded to guarantee that the cy.on('fail', ...) hits accordingly otherwise the test can pass if the error handle is not invoked.

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', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('no longer returns a `Promise`')
})

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

it('binaryStringToBlob', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('no longer returns a `Promise`')
})

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

it('dataURLToBlob', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('no longer returns a `Promise`')
})

Cypress.Blob.dataURLToBlob('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==').then((blob) => {
// it should fail.
})
})
})
2 changes: 1 addition & 1 deletion packages/driver/package.json
Expand Up @@ -22,7 +22,7 @@
"angular": "1.8.0",
"backbone": "1.4.0",
"basic-auth": "2.0.1",
"blob-util": "1.3.0",
"blob-util": "2.0.2",
"bluebird": "3.5.3",
"body-parser": "1.19.0",
"bootstrap": "4.4.1",
Expand Down
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
9 changes: 9 additions & 0 deletions packages/driver/src/cypress/error_messages.js
Expand Up @@ -153,6 +153,15 @@ 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}}`',
},
Expand Down
34 changes: 34 additions & 0 deletions packages/driver/src/util/breaking_change_warning.ts
@@ -0,0 +1,34 @@
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
}
Expand Up @@ -18,13 +18,17 @@ Cypress.Commands.add 'setFile', { prevSubject: "element" }, (element, filePath)
return cy.fixture(filePath, "base64")

return fixtureOrReadFile(filePath).then (image) ->
return Blob.base64StringToBlob(image).then (blob) ->
return new Promise((resolve) =>
blob = Blob.base64StringToBlob(image)
elementNode = element[0]
file = new File([ blob ], filePath, type: mimeType)
dataTransfer = new DataTransfer
dataTransfer.items.add(file)
elementNode.files = dataTransfer.files
elementNode.dispatchEvent new Event("change", { bubbles: true })
result = elementNode.dispatchEvent new Event("change", { bubbles: true })

resolve(result)
)

describe "<form> submissions", ->
it "can submit a form correctly", ->
Expand Down
40 changes: 4 additions & 36 deletions yarn.lock
Expand Up @@ -3806,11 +3806,6 @@
dependencies:
"@babel/types" "^7.3.0"

"@types/blob-util@1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@types/blob-util/-/blob-util-1.3.3.tgz#adba644ae34f88e1dd9a5864c66ad651caaf628a"
integrity sha512-4ahcL/QDnpjWA2Qs16ZMQif7HjGP2cw3AGjHabybjw7Vm1EKu+cfQN1D78BaZbS1WJNa1opSMF5HNMztx7lR0w==

"@types/bluebird@*":
version "3.5.31"
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.31.tgz#d17fa0ec242b51c3db302481c557ce3813bf45cb"
Expand Down Expand Up @@ -6978,18 +6973,10 @@ black-hole-stream@0.0.1:
resolved "https://registry.yarnpkg.com/black-hole-stream/-/black-hole-stream-0.0.1.tgz#33b7a06b9f1e7453d6041b82974481d2152aea42"
integrity sha1-M7ega58edFPWBBuCl0SB0hUq6kI=

blob-util@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/blob-util/-/blob-util-1.3.0.tgz#dbb4e8caffd50b5720d347e1169b6369ba34fe95"
integrity sha512-cjmYgWj8BQwoX+95rKkWvITL6PiEhSr19sX8qLRu+O6J2qmWmgUvxqhqJn425RFAwLovdDNnsCQ64RRHXjsXSg==
dependencies:
blob "0.0.4"
native-or-lie "1.0.2"

blob@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.4.tgz#bcf13052ca54463f30f9fc7e95b9a47630a94921"
integrity sha1-vPEwUspURj8w+fx+lbmkdjCpSSE=
blob-util@2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/blob-util/-/blob-util-2.0.2.tgz#3b4e3c281111bb7f11128518006cdc60b403a1eb"
integrity sha512-T7JQa+zsXXEa6/8ZhHcQEW1UFfVM49Ts65uBkFL6fz2QmrElqmbajIDJvuA0tEhRe5eIjpV9ZF+0RfZR9voJFQ==

blob@0.0.5:
version "0.0.5"
Expand Down Expand Up @@ -14206,11 +14193,6 @@ image-size@0.8.3, image-size@^0.8.2:
dependencies:
queue "6.0.1"

immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=

immutable@3.7.6:
version "3.7.6"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.7.6.tgz#13b4d3cb12befa15482a26fe1b2ebae640071e4b"
Expand Down Expand Up @@ -16394,13 +16376,6 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

lie@*:
version "3.3.0"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a"
integrity sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==
dependencies:
immediate "~3.0.5"

liftoff@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/liftoff/-/liftoff-3.1.0.tgz#c9ba6081f908670607ee79062d700df062c52ed3"
Expand Down Expand Up @@ -18247,13 +18222,6 @@ napi-build-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"
integrity sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==

native-or-lie@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/native-or-lie/-/native-or-lie-1.0.2.tgz#c870ee0ba0bf0ff11350595d216cfea68a6d8086"
integrity sha1-yHDuC6C/D/ETUFldIWz+poptgIY=
dependencies:
lie "*"

native-promise-only@~0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/native-promise-only/-/native-promise-only-0.8.1.tgz#20a318c30cb45f71fe7adfbf7b21c99c1472ef11"
Expand Down