Adjust addrcheck timeouts (jest 27) (#353)

This commit is contained in:
Jaco
2021-05-31 15:16:45 +03:00
committed by GitHub
parent 3909583107
commit 95eee85d2e
5 changed files with 30 additions and 8 deletions
+1
View File
@@ -114,6 +114,7 @@
"polkadot-wallet.org": [ "polkadot-wallet.org": [
"12nGrKnQprcq19X8zdVevfXZPNgD4AoDnsAwxs6FoEeThudY", "12nGrKnQprcq19X8zdVevfXZPNgD4AoDnsAwxs6FoEeThudY",
"13dJM2sNwVQc8jsEazupzaqaFjTNJo492qL6RSVuT41SLLAY", "13dJM2sNwVQc8jsEazupzaqaFjTNJo492qL6RSVuT41SLLAY",
"14wHn5YYdrfeBibctXsctFAyDCWM6A9t38JyYVsnJGExmR5P",
"15izdazFKpSYg8ihRoS8opxWn5UA19UAQYdwRCodJ4Q9JNEd", "15izdazFKpSYg8ihRoS8opxWn5UA19UAQYdwRCodJ4Q9JNEd",
"15Mudzn4no9pY24o3mhbT4Gw3v5WYxMbzXre4MhVRPMFhcLX", "15Mudzn4no9pY24o3mhbT4Gw3v5WYxMbzXre4MhVRPMFhcLX",
"15Y9gquGY3dWENabfYRcWo4Bt45dPvUDhJy97dM1iR6DqrDp", "15Y9gquGY3dWENabfYRcWo4Bt45dPvUDhJy97dM1iR6DqrDp",
+1
View File
@@ -11,5 +11,6 @@ module.exports = {
'<rootDir>/packages/phishing/build' '<rootDir>/packages/phishing/build'
], ],
testEnvironment: 'jsdom', testEnvironment: 'jsdom',
testTimeout: 2 * 60 * 1000,
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)'] transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)']
}; };
+3 -3
View File
@@ -16,10 +16,10 @@
"build:release:ipfs": "node scripts/ipfsUpload.mjs", "build:release:ipfs": "node scripts/ipfsUpload.mjs",
"lint": "polkadot-dev-run-lint", "lint": "polkadot-dev-run-lint",
"clean": "polkadot-dev-clean-build", "clean": "polkadot-dev-clean-build",
"phishing:addrcheck": "polkadot-dev-run-test packages/phishing/src/addrcheck", "phishing:addrcheck": "polkadot-dev-run-test --runInBand --detectOpenHandles packages/phishing/src/addrcheck",
"phishing:crosscheck": "polkadot-dev-run-test packages/phishing/src/crosscheck", "phishing:crosscheck": "polkadot-dev-run-test --runInBand --detectOpenHandles packages/phishing/src/crosscheck",
"postinstall": "polkadot-dev-yarn-only", "postinstall": "polkadot-dev-yarn-only",
"test": "polkadot-dev-run-test --coverage --runInBand --testPathIgnorePatterns addrcheck --testPathIgnorePatterns crosscheck" "test": "polkadot-dev-run-test --coverage --runInBand --detectOpenHandles --testPathIgnorePatterns addrcheck --testPathIgnorePatterns crosscheck"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.14.3", "@babel/core": "^7.14.3",
+6 -1
View File
@@ -31,7 +31,12 @@ async function loopSome (site: string, matcher: () => Promise<string[] | null>):
// console.error(error); // console.error(error);
} }
await new Promise<boolean>((resolve) => setTimeout(() => resolve(true), Math.floor((Math.random() * 750) + 1000))); await new Promise<boolean>((resolve) =>
setTimeout(
() => resolve(true),
Math.floor((Math.random() * 750) + 1000)
)
);
} }
return [site, found]; return [site, found];
+19 -4
View File
@@ -6,10 +6,25 @@ import { fetch } from '@polkadot/x-fetch';
// a fetch with a 2s timeout // a fetch with a 2s timeout
export async function fetchWithTimeout (url: string, timeout = 2000): Promise<Response> { export async function fetchWithTimeout (url: string, timeout = 2000): Promise<Response> {
const controller = new AbortController(); const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout); let isAborted = false;
const response = await fetch(url, { signal: controller.signal }); const id = setTimeout((): void => {
console.log(`Timeout on ${url}`);
clearTimeout(id); isAborted = true;
controller.abort();
}, timeout);
return response; try {
const response = await fetch(url, { signal: controller.signal });
clearTimeout(id);
return response;
} catch (error) {
if (!isAborted) {
clearTimeout(id);
}
throw error;
}
} }