test.mjs 947 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { createReadStream } from "fs";
  2. import { createInterface } from "readline";
  3. async function getPage(path) {
  4. return fetch(`http://localhost:8923${path}`)
  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.text());
  12. }
  13. (async () => {
  14. const fin = createReadStream("input.txt");
  15. const rl = createInterface({
  16. input: fin,
  17. crlfDelay: Infinity,
  18. });
  19. const resultSheet = {};
  20. let failed = false;
  21. for await (const line of rl) {
  22. console.log(line);
  23. const resp = await getPage(line);
  24. resultSheet[line] = {
  25. match: resp.includes(`GET ${line}`),
  26. line: resp.split("\n")[0],
  27. };
  28. }
  29. for (let [k, v] of Object.entries(resultSheet)) {
  30. if (!v.match) {
  31. failed = true;
  32. }
  33. console.debug({ path: k, results: v });
  34. }
  35. process.exit(failed ? 1 : 0);
  36. })();