diff --git a/lib/file/getFileBlobAsync.js b/lib/file/getFileBlobAsync.js index 4c845d9..45c6c19 100644 --- a/lib/file/getFileBlobAsync.js +++ b/lib/file/getFileBlobAsync.js @@ -2,10 +2,23 @@ import { extname } from 'path'; import { ENCODING, FILE_EXTENSION } from './constants'; +const wrapBlob = blob => { + // Cypress version 5 assigns a function with a compatibility warning + // to blob.then, but that makes the Blob actually thenable. We have + // to remove that to Promise.resolve not treat it as thenable. + if (blob instanceof Cypress.Promise) { + return blob; + } + + // eslint-disable-next-line no-param-reassign + delete blob.then; + return Cypress.Promise.resolve(blob); +}; + const ENCODING_TO_BLOB_GETTER = { [ENCODING.ASCII]: fileContent => Cypress.Promise.resolve(fileContent), - [ENCODING.BASE64]: (fileContent, mimeType) => Cypress.Blob.base64StringToBlob(fileContent, mimeType), - [ENCODING.BINARY]: (fileContent, mimeType) => Cypress.Blob.binaryStringToBlob(fileContent, mimeType), + [ENCODING.BASE64]: (fileContent, mimeType) => wrapBlob(Cypress.Blob.base64StringToBlob(fileContent, mimeType)), + [ENCODING.BINARY]: (fileContent, mimeType) => wrapBlob(Cypress.Blob.binaryStringToBlob(fileContent, mimeType)), [ENCODING.HEX]: fileContent => Cypress.Promise.resolve(fileContent), [ENCODING.LATIN1]: fileContent => Cypress.Promise.resolve(fileContent), [ENCODING.UTF8]: fileContent => Cypress.Promise.resolve(fileContent),