Skip to content

Commit

Permalink
Remove thenability from Cypress.Blob >= 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emilong committed Aug 20, 2020
1 parent 45e3fc6 commit efa9358
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/file/getFileBlobAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import { extname } from 'path';

import { ENCODING, FILE_EXTENSION } from './constants';

let 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.
//
// eslint-disable-next-line no-param-reassign
delete blob.then;
return Cypress.Promise.resolve(blob);
};

if (Cypress.version < '5.0.0') {
wrapBlob = blob => blob;
}

const ENCODING_TO_BLOB_GETTER = {
[ENCODING.ASCII]: fileContent => Cypress.Promise.resolve(fileContent),
[ENCODING.BASE64]: (fileContent, mimeType) =>
Cypress.Promise.try(() => Cypress.Blob.base64StringToBlob(fileContent, mimeType)),
[ENCODING.BINARY]: (fileContent, mimeType) =>
Cypress.Promise.try(() => 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),
Expand Down

0 comments on commit efa9358

Please sign in to comment.