mapping-entry-test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { assert } from "chai";
  2. import { getAbsoluteMappingEntries } from "../src/mapping-entry";
  3. import { join } from "path";
  4. describe("mapping-entry", () => {
  5. it("should change to absolute paths and sort in longest prefix order", () => {
  6. const result = getAbsoluteMappingEntries(
  7. "/absolute/base/url",
  8. {
  9. "*": ["/foo1", "/foo2"],
  10. "longest/pre/fix/*": ["/foo2/bar"],
  11. "pre/fix/*": ["/foo3"]
  12. },
  13. true
  14. );
  15. assert.deepEqual(result, [
  16. {
  17. pattern: "longest/pre/fix/*",
  18. paths: [join("/absolute", "base", "url", "foo2", "bar")]
  19. },
  20. {
  21. pattern: "pre/fix/*",
  22. paths: [join("/absolute", "base", "url", "foo3")]
  23. },
  24. {
  25. pattern: "*",
  26. paths: [
  27. join("/absolute", "base", "url", "foo1"),
  28. join("/absolute", "base", "url", "foo2")
  29. ]
  30. }
  31. ]);
  32. });
  33. it("should should add a match-all pattern when requested", () => {
  34. let result = getAbsoluteMappingEntries("/absolute/base/url", {}, true);
  35. assert.deepEqual(result, [
  36. {
  37. pattern: "*",
  38. paths: [join("/absolute", "base", "url", "*")]
  39. }
  40. ]);
  41. result = getAbsoluteMappingEntries("/absolute/base/url", {}, false);
  42. assert.deepEqual(result, []);
  43. });
  44. });