diff --git a/package.json b/package.json index a5b92db..6e770ad 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "test": "npm-run-all test:data test:js", "test:data": "node scripts/test-communities.js && node scripts/test-conferences.js", "test:js": "jest", + "test:data:url": "node scripts/test-communities-check-url.mjs", "watch": "npm-run-all build:communities build:conferences build:conferences-ics -p dev" }, "jest": { diff --git a/scripts/test-communities-check-url.mjs b/scripts/test-communities-check-url.mjs new file mode 100644 index 0000000..b70b9d9 --- /dev/null +++ b/scripts/test-communities-check-url.mjs @@ -0,0 +1,24 @@ +import path from 'path'; +import fs from 'fs'; + +const communitiesDir = path.resolve(import.meta.dirname, '../communities/'); + +const communitiesPath = fs + .readdirSync(communitiesDir) + .filter(file => file.endsWith('.json')) + .map(file => path.join(communitiesDir, file)); + +const communities = communitiesPath + .map(file => fs.readFileSync(file).toString()) + .map(fileContent => JSON.parse(fileContent)); + +const fetchCommunities = communities.map(community => fetch(community.url)); + +const failedURL = (await Promise.all(fetchCommunities)) + .filter(communityResponse => !communityResponse.ok) + .map(communityResponse => communityResponse.url); + +if (failedURL.length > 0) { + console.log(failedURL); + process.exit(1); +}