capture.test.js 862 B

12345678910111213141516171819202122232425262728
  1. const assert = require("node:assert/strict");
  2. const test = require("node:test");
  3. const { screenshotFilename } = require("./capture");
  4. test("generates a Windows-safe filename for the root URL", () => {
  5. assert.equal(screenshotFilename("http://localhost:5287"), "localhost_5287.png");
  6. });
  7. test("preserves the route in the screenshot filename", () => {
  8. assert.equal(
  9. screenshotFilename("http://localhost:5287/visualise/topology"),
  10. "localhost_5287_visualise_topology.png"
  11. );
  12. });
  13. test("omits the default HTTPS port", () => {
  14. assert.equal(
  15. screenshotFilename("https://example.com:443/a/b"),
  16. "example.com_a_b.png"
  17. );
  18. });
  19. test("removes filesystem-unsafe characters", () => {
  20. const filename = screenshotFilename("http://[::1]:5287/a?b=c");
  21. assert.equal(filename, "___1__5287_a.png");
  22. assert.doesNotMatch(filename, /[\\/:*?"<>|]/);
  23. });