1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Improve downloads tests (#17995)

This commit is contained in:
weizman 2023-03-07 02:00:52 +02:00 committed by GitHub
parent abff49561d
commit f46ce9f2bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 14 deletions

View File

@ -10,7 +10,7 @@ const FixtureBuilder = require('../fixture-builder');
const downloadsFolder = `${process.cwd()}/test-artifacts/downloads`; const downloadsFolder = `${process.cwd()}/test-artifacts/downloads`;
const backupExists = async () => { const getBackupJson = async () => {
const date = new Date(); const date = new Date();
const prependZero = (num, maxLength) => { const prependZero = (num, maxLength) => {
@ -31,9 +31,10 @@ const backupExists = async () => {
try { try {
const backup = `${downloadsFolder}/${userDataFileName}`; const backup = `${downloadsFolder}/${userDataFileName}`;
await fs.access(backup); await fs.access(backup);
return true; const contents = await fs.readFile(backup);
return JSON.parse(contents.toString());
} catch (e) { } catch (e) {
return false; return null;
} }
}; };
@ -78,12 +79,17 @@ describe('Backup and Restore', function () {
}); });
// Verify download // Verify download
let fileExists; let info;
await driver.wait(async () => { await driver.wait(async () => {
fileExists = await backupExists(); info = await getBackupJson();
return fileExists === true; return info !== null;
}, 10000); }, 10000);
assert.equal(fileExists, true); assert.notEqual(info, null);
// Verify Json
assert.equal(
info?.preferences?.frequentRpcListDetail[0].chainId,
'0x539',
);
}, },
); );
}); });

View File

@ -9,13 +9,14 @@ const FixtureBuilder = require('../fixture-builder');
const downloadsFolder = `${process.cwd()}/test-artifacts/downloads`; const downloadsFolder = `${process.cwd()}/test-artifacts/downloads`;
const stateLogsExist = async () => { const getStateLogsJson = async () => {
try { try {
const stateLogs = `${downloadsFolder}/MetaMask state logs.json`; const stateLogs = `${downloadsFolder}/MetaMask state logs.json`;
await fs.access(stateLogs); await fs.access(stateLogs);
return true; const contents = await fs.readFile(stateLogs);
return JSON.parse(contents.toString());
} catch (e) { } catch (e) {
return false; return null;
} }
}; };
@ -53,12 +54,19 @@ describe('State logs', function () {
}); });
// Verify download // Verify download
let fileExists; let info;
await driver.wait(async () => { await driver.wait(async () => {
fileExists = await stateLogsExist(); info = await getStateLogsJson();
return fileExists === true; return info !== null;
}, 10000); }, 10000);
assert.equal(fileExists, true); assert.notEqual(info, null);
// Verify Json
assert.equal(
info?.metamask?.identities[
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1'
].address,
'0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
);
}, },
); );
}); });