fix: add prefer-blob-reading-methods rule (#5118)

This commit is contained in:
LongYinan 2023-11-29 04:44:10 +00:00
parent cb2c659f52
commit eadf8a085b
No known key found for this signature in database
GPG Key ID: 30B1140CE1C07C99
2 changed files with 5 additions and 12 deletions

View File

@ -212,6 +212,7 @@ const config = {
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/no-typeof-undefined': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-new-array': 'error',

View File

@ -368,18 +368,10 @@ test('can sync svg between different browsers', async ({ page, browser }) => {
expect(src).not.toBeNull();
// fetch the src resource in the browser
const svg2 = await page2.evaluate(async src => {
async function blobToString(blob: Blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsText(blob);
});
}
const blob = fetch(src!).then(res => res.blob());
return blobToString(await blob);
const svg2 = await page2.evaluate(src => {
return fetch(src!)
.then(res => res.blob())
.then(blob => blob.text());
}, src);
// turn the blob into string and check if it contains the svg