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 header nav to new taxonomy #3178

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
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
41 changes: 41 additions & 0 deletions devTools/navigationTest/navigationTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Test all the slugs in the SiteNavigationStatic object and makes sure
// https://ourworldindata.org/{slug} returns a 200

import { SiteNavigationStatic } from "../../site/SiteNavigation.js"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using TypeScript's type annotations for SiteNavigationStatic to ensure type safety and clarity in the code.


const testSiteNavigation = async () => {
const slugs = SiteNavigationStatic.categories
.map((category) => {
const categorySlugs = category.entries
.map((entry) => entry.slug)
.concat(
(category.subcategories?.length &&
category.subcategories.flatMap((subcategory) =>
subcategory.entries.map((entry) => entry.slug)
)) ||
[]
)
return categorySlugs
})
.flat()

let promises = slugs.map((slug) => {
return fetch(`https://ourworldindata.org/${slug}`, {
method: "HEAD",
})
})

const responses: Response[] = await Promise.all(promises)
if (responses.some((response) => !response.ok)) {
console.error(
"❌ One or more fetches failed: ",
responses
.filter((response) => !response.ok)
.map((response) => response.url)
)
return
}
Comment on lines +28 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The error logging could be more informative by including the status code and status text.
  • Returning early from the function upon failure prevents any further processing or cleanup that might be necessary. Consider how this behavior integrates with the broader testing framework or CI/CD pipeline.

console.log("✅ All fetches completed")
}
Comment on lines +6 to +39
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The function testSiteNavigation lacks error handling for network issues or exceptions thrown by fetch. Wrap the fetch call in a try-catch block to handle these cases.
  • The function does not return any value indicating success or failure, which might be useful for automated testing or integration into a larger test suite.


testSiteNavigation()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invoking testSiteNavigation directly in the script makes it less modular and harder to integrate into automated testing environments. Consider exporting the function and moving the invocation to a separate script or test runner.

8 changes: 8 additions & 0 deletions devTools/navigationTest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfigs/tsconfig.base.json",
"compilerOptions": {
"outDir": "../../itsJustJavascript/devTools/navigationTest",
"rootDir": "."
},
"references": [{ "path": "../../site" }]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"testLint": "eslint .",
"testPrettierAll": "yarn prettier --check \"**/*.{tsx,ts,jsx,js,json,md,html,css,scss,yml}\"",
"testJest": "lerna run buildTests && jest",
"testSiteNavigation": "node --enable-source-maps ./itsJustJavascript/devTools/navigationTest/navigationTest.js",
"generateDbTypes": "npx @rmp135/sql-ts -c db/sql-ts/sql-ts-config.json"
},
"dependencies": {
Expand Down
Loading
Loading