test.mjs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. async function fetchLanguages() {
  2. return fetch(
  3. "http://localhost:8923/.within.website/x/cmd/anubis/static/locales/manifest.json",
  4. )
  5. .then((resp) => {
  6. if (resp.status !== 200) {
  7. throw new Error(`wanted status 200, got status: ${resp.status}`);
  8. }
  9. return resp;
  10. })
  11. .then((resp) => resp.json());
  12. }
  13. async function getChallengePage(lang) {
  14. return fetch("http://localhost:8923/reqmeta", {
  15. headers: {
  16. "Accept-Language": lang,
  17. "User-Agent": "CHALLENGE",
  18. },
  19. })
  20. .then((resp) => {
  21. if (resp.status !== 200) {
  22. throw new Error(`wanted status 200, got status: ${resp.status}`);
  23. }
  24. return resp;
  25. })
  26. .then((resp) => resp.text());
  27. }
  28. (async () => {
  29. const languages = await fetchLanguages();
  30. console.log(languages);
  31. const { supportedLanguages } = languages;
  32. if (supportedLanguages.length === 0) {
  33. throw new Error(`no languages defined`);
  34. }
  35. const resultSheet = {};
  36. let failed = false;
  37. for (const lang of supportedLanguages) {
  38. console.log(`getting for ${lang}`);
  39. const page = await getChallengePage(lang);
  40. resultSheet[lang] = page.includes(`<html lang="${lang}">`);
  41. }
  42. for (const [lang, result] of Object.entries(resultSheet)) {
  43. if (!result) {
  44. failed = true;
  45. console.log(`${lang} did not show up in challenge page`);
  46. }
  47. }
  48. console.log(resultSheet);
  49. if (failed) {
  50. throw new Error("i18n smoke test failed");
  51. }
  52. process.exit(0);
  53. })();