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 use to be compatible with Cypress 5.0 #215

Merged
merged 6 commits into from
Aug 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/file/getFileBlobAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
josephzidell marked this conversation as resolved.
Show resolved Hide resolved
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),
Expand Down