@warp-drive/holodeck 0.0.0-alpha.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2023 EmberData and WarpDrive contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="1200pt" height="1200pt" version="1.1" viewBox="0 0 1200 1200" xmlns="http://www.w3.org/2000/svg">
3
+ <path fill="#0969da" d="m1096.3 402.82c-53.148-53.008-117.12-79.516-191.93-79.516-67.488 0-126.55 21.938-177.16 65.805-50.617 43.871-80.988 98.285-91.113 163.25l53.57 4.2188c14.625 0.28125 25.449 6.75 32.48 19.406h18.984c11.809 0 17.715 5.7617 17.715 17.293s-5.9062 17.293-17.715 17.293h-17.297c-6.75 14.344-18.137 21.797-34.168 22.359l-53.57 4.6406c10.125 64.68 40.496 118.95 91.113 162.82 50.617 43.871 109.68 65.805 177.16 65.805 74.805 0 138.78-26.574 191.93-79.723 53.152-53.148 79.727-116.98 79.727-191.51 0-75.086-26.574-139.13-79.727-192.14zm-79.422 185.27c0 2.9531 2.3906 5.3477 5.3438 5.3477 2.9531 0 5.3477-2.3945 5.3477-5.3477 0-2.9492-2.3945-5.3438-5.3477-5.3438-2.9531 0-5.3438 2.3945-5.3438 5.3438zm-104.54-111.07c0 2.9531 2.3945 5.3477 5.3438 5.3477 2.9531 0 5.3477-2.3945 5.3477-5.3477s-2.3945-5.3438-5.3477-5.3438c-2.9492 0-5.3438 2.3906-5.3438 5.3438zm-12.473 0c0 2.9531 2.3906 5.3477 5.3438 5.3477s5.3477-2.3945 5.3477-5.3477-2.3945-5.3438-5.3477-5.3438-5.3438 2.3906-5.3438 5.3438zm117.01 123.55c0 2.9492 2.3906 5.3438 5.3438 5.3438 2.9531 0 5.3477-2.3945 5.3477-5.3438 0-2.9531-2.3945-5.3477-5.3477-5.3477-2.9531 0-5.3438 2.3945-5.3438 5.3477zm-104.54 111.66c0 2.9531 2.3945 5.3477 5.3438 5.3477 2.9531 0 5.3477-2.3945 5.3477-5.3477s-2.3945-5.3438-5.3477-5.3438c-2.9492 0-5.3438 2.3906-5.3438 5.3438zm-12.473 0c0 2.9531 2.3906 5.3477 5.3438 5.3477s5.3477-2.3945 5.3477-5.3477-2.3945-5.3438-5.3477-5.3438-5.3438 2.3906-5.3438 5.3438zm-848-318.48c14.062-2.5312 30.934-4.5 50.621-5.9062l-46.402-0.84375zm499.86 169.15c-8.7188-2.25-18.141-8.7188-28.266-19.402l-101.23-103.35h-111.36l173.79 126.12v4.2188c21.652 6.1836 44.008 3.6562 67.07-7.5938zm47.664-148.48c-0.84375 3.3711-2.8125 6.6055-5.9062 9.6992h-5.0625l-6.3242-5.0625h-79.305v-4.6367zm-5.9062-16.031c3.0938 3.0938 5.0625 6.4688 5.9062 10.125h-96.598v-4.6406h79.305l6.3242-5.4844zm-541.62 397.78 4.2188 6.7461 46.402-0.84375c-22.5-2.2461-39.371-4.2148-50.621-5.9023zm499.86-169.15c-23.062-11.531-45.418-14.062-67.07-7.5938v4.2188l-173.79 126.12h111.36l101.23-103.77c10.406-10.684 19.828-17.012 28.266-18.98zm47.664 148.48h-96.598v-4.6406h79.305l6.3242-5.4805h5.0625c3.0938 3.6523 5.0625 7.0273 5.9062 10.121zm-5.9062 15.609h-5.0625l-6.3242-5.0625h-79.305v-4.6406h96.598c-0.84375 3.0938-2.8125 6.3281-5.9062 9.7031zm-102.5 9.6992c3.6562 1.4062 7.4531 2.1094 11.391 2.1094h64.961c24.746 0 37.121-8.4336 37.121-25.309 0-8.4375-4.6406-14.691-13.922-18.77-9.2773-4.0781-17.012-6.1172-23.199-6.1172h-64.961c-4.7812 0-8.5781 0.5625-11.391 1.6875h-333.66c-5.0625 0-28.543 1.6172-70.445 4.8516-41.902 3.2344-62.852 7.3828-62.852 12.441v11.812c0 4.5 20.949 8.5078 62.852 12.023 41.902 3.5156 65.383 5.2695 70.445 5.2695zm125.28-207.54h-42.602c-3.375 1.125-3.375 2.25 0 3.375h42.602zm-43.445 8.4375h-5.4844v-13.5h5.4844c17.152-6.1875 33.605-9.9844 49.352-11.391l4.6406-25.309 4.6406 0.42188c0.5625-4.2188 1.6875-10.262 3.375-18.137-28.684-0.5625-64.398 1.6875-107.14 6.75 3.6562 4.2148 7.4531 7.8711 11.391 10.965 4.7812 3.375 9.4219 5.625 13.918 6.75l12.656 2.9531-11.812 5.9062c-13.496 6.75-30.23 10.121-50.195 10.121-5.0625 0-8.5781-0.14062-10.547-0.42188-4.2188-0.5625-7.5898-1.1211-10.121-1.6836l-3.375-1.2656v-5.4844l-24.043-17.297c-41.34 5.625-69.32 8.5781-83.945 8.8594-31.496 0.28125-47.242 11.953-47.242 35.012 0 22.215 15.746 33.887 47.242 35.012 18.844 0.28125 46.824 3.2344 83.945 8.8594l24.043-17.297v-5.4844l3.375-1.2656c2.5312-0.84375 5.9023-1.4062 10.121-1.6875 1.9688-0.28125 5.4844-0.42187 10.547-0.42187 19.965 0 36.699 3.375 50.195 10.125l11.812 5.4844-12.656 3.375c-4.4961 0.84375-9.1367 3.0938-13.918 6.75-3.6562 2.2461-7.4531 5.7617-11.391 10.543 40.777 5.0625 76.492 7.4531 107.14 7.1719-1.6875-7.3125-2.8125-13.359-3.375-18.137h-4.6406l-4.6406-24.891c-17.434-2.25-33.887-6.043-49.352-11.387zm48.508-20.25c-12.652 1.6875-23.762 3.9375-33.324 6.75h29.105l3.7969-4.2188zm-4.2188 20.25h-29.105c9.5625 2.5312 20.672 4.7812 33.324 6.7461l-0.42188-2.5273zm136.67-8.4375c0-8.4375-4.2188-12.656-12.652-12.656h-21.516c-6.4688-12.652-16.59-18.98-30.371-18.98l-58.211-5.0625-5.9062 29.527-4.2188 5.0625v7.5938l4.2188 5.0625 5.9062 29.105 58.211-5.0625c15.469 0 26.012-7.3125 31.637-21.934h20.25c8.4336 0 12.652-4.2188 12.652-12.656zm-46.82 1.6875c0-11.531-5.9062-17.297-17.719-17.297-11.527 0-17.293 5.7656-17.293 17.297 0 11.812 5.7656 17.715 17.293 17.715 11.812 0 17.719-5.9023 17.719-17.715zm4.6406 0c0 14.902-7.4531 22.355-22.359 22.355-14.902 0-22.355-7.4531-22.355-22.355 0-14.906 7.4531-22.355 22.355-22.355 14.906 0 22.359 7.4492 22.359 22.355zm-13.922 0c0-5.625-2.8125-8.4375-8.4375-8.4375-5.3438 0-8.0156 2.8125-8.0156 8.4375s2.6719 8.4375 8.0156 8.4375c5.625 0 8.4375-2.8125 8.4375-8.4375zm4.6406 0c0 8.7188-4.3594 13.078-13.078 13.078-8.4375 0-12.652-4.3594-12.652-13.078s4.2148-13.078 12.652-13.078c8.7188 0 13.078 4.3594 13.078 13.078zm-43.871-2.1094v4.2188h-35.012v-4.2188zm258.58 2.1094c-0.5625-8.4375-4.7812-12.656-12.656-12.656-8.4336 0-12.652 4.2188-12.652 12.656s4.2188 12.656 12.652 12.656c8.4375 0 12.656-4.2188 12.656-12.656zm4.6406 0c0 11.531-5.7656 17.293-17.297 17.293-11.527 0-17.293-5.7617-17.293-17.293s5.7656-17.297 17.293-17.297c11.531 0 17.297 5.7656 17.297 17.297zm32.48 0c0-13.781-4.9219-25.59-14.766-35.434-9.5586-9.5625-21.23-14.344-35.012-14.344-15.184 0-31.777 5.7656-49.773 17.297-18.559 11.531-27.84 22.355-27.84 32.48 0 9.8438 9.2812 20.668 27.84 32.48 17.996 11.531 34.59 17.293 49.773 17.293 13.781 0 25.453-4.918 35.012-14.762 9.8438-9.5625 14.766-21.234 14.766-35.012zm5.0625 0c0 14.902-5.3438 27.699-16.031 38.387-10.684 10.684-23.621 16.027-38.809 16.027-15.746 0-33.18-6.0469-52.305-18.137-20.246-12.656-30.371-24.746-30.371-36.277s10.125-23.762 30.371-36.699c19.125-12.094 36.559-18.137 52.305-18.137 14.625 0 27.562 5.3398 38.809 16.027 10.688 10.969 16.031 23.902 16.031 38.809zm-54.418-29.105c-3.9336 0-10.262 1.6875-18.98 5.0625-7.875 3.9375-11.812 6.4648-11.812 7.5898v32.48c0 3.0938 3.9375 5.625 11.812 7.5938 7.875 3.375 14.203 5.0625 18.98 5.0625 19.406 0 29.391-9.2812 29.953-27.84 0-19.688-9.9844-29.668-29.953-29.949zm34.59 29.105v0.84375c0 21.371-11.527 32.34-34.59 32.902-4.4961 0-11.527-1.8281-21.09-5.4844-7.0312-3.9375-10.969-6.3281-11.809-7.1719-1.6875-1.4062-2.5312-3.0938-2.5312-5.0625v-32.48c0-1.4062 0.70312-2.9492 2.1094-4.6367 3.0898-2.8125 7.168-5.2031 12.23-7.1719 9-3.6562 16.031-5.4844 21.09-5.4844 22.5 0.28125 34.027 11.531 34.59 33.746zm-448.4-206.27h-333.66c-5.0625 0-28.543 1.6875-70.445 5.0625-41.902 3.375-62.852 7.5938-62.852 12.656v11.387c0 4.7812 20.949 8.8594 62.852 12.234 41.902 3.375 65.383 5.0625 70.445 5.0625h333.66c3.6562 1.4062 7.4531 2.1094 11.391 2.1094h64.961c5.3438 0 12.867-2.25 22.566-6.75 9.7031-4.5 14.555-10.547 14.555-18.137 0.28125-16.875-12.094-25.312-37.121-25.312h-64.961c-4.7812 0-8.5781 0.5625-11.391 1.6875z" fill-rule="evenodd"/>
4
+ </svg>
package/NCC-1701-a.svg ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="1200pt" height="1200pt" version="1.1" viewBox="0 0 1200 1200" xmlns="http://www.w3.org/2000/svg">
3
+ <path fill="#FFFFFF" d="m1096.3 402.82c-53.148-53.008-117.12-79.516-191.93-79.516-67.488 0-126.55 21.938-177.16 65.805-50.617 43.871-80.988 98.285-91.113 163.25l53.57 4.2188c14.625 0.28125 25.449 6.75 32.48 19.406h18.984c11.809 0 17.715 5.7617 17.715 17.293s-5.9062 17.293-17.715 17.293h-17.297c-6.75 14.344-18.137 21.797-34.168 22.359l-53.57 4.6406c10.125 64.68 40.496 118.95 91.113 162.82 50.617 43.871 109.68 65.805 177.16 65.805 74.805 0 138.78-26.574 191.93-79.723 53.152-53.148 79.727-116.98 79.727-191.51 0-75.086-26.574-139.13-79.727-192.14zm-79.422 185.27c0 2.9531 2.3906 5.3477 5.3438 5.3477 2.9531 0 5.3477-2.3945 5.3477-5.3477 0-2.9492-2.3945-5.3438-5.3477-5.3438-2.9531 0-5.3438 2.3945-5.3438 5.3438zm-104.54-111.07c0 2.9531 2.3945 5.3477 5.3438 5.3477 2.9531 0 5.3477-2.3945 5.3477-5.3477s-2.3945-5.3438-5.3477-5.3438c-2.9492 0-5.3438 2.3906-5.3438 5.3438zm-12.473 0c0 2.9531 2.3906 5.3477 5.3438 5.3477s5.3477-2.3945 5.3477-5.3477-2.3945-5.3438-5.3477-5.3438-5.3438 2.3906-5.3438 5.3438zm117.01 123.55c0 2.9492 2.3906 5.3438 5.3438 5.3438 2.9531 0 5.3477-2.3945 5.3477-5.3438 0-2.9531-2.3945-5.3477-5.3477-5.3477-2.9531 0-5.3438 2.3945-5.3438 5.3477zm-104.54 111.66c0 2.9531 2.3945 5.3477 5.3438 5.3477 2.9531 0 5.3477-2.3945 5.3477-5.3477s-2.3945-5.3438-5.3477-5.3438c-2.9492 0-5.3438 2.3906-5.3438 5.3438zm-12.473 0c0 2.9531 2.3906 5.3477 5.3438 5.3477s5.3477-2.3945 5.3477-5.3477-2.3945-5.3438-5.3477-5.3438-5.3438 2.3906-5.3438 5.3438zm-848-318.48c14.062-2.5312 30.934-4.5 50.621-5.9062l-46.402-0.84375zm499.86 169.15c-8.7188-2.25-18.141-8.7188-28.266-19.402l-101.23-103.35h-111.36l173.79 126.12v4.2188c21.652 6.1836 44.008 3.6562 67.07-7.5938zm47.664-148.48c-0.84375 3.3711-2.8125 6.6055-5.9062 9.6992h-5.0625l-6.3242-5.0625h-79.305v-4.6367zm-5.9062-16.031c3.0938 3.0938 5.0625 6.4688 5.9062 10.125h-96.598v-4.6406h79.305l6.3242-5.4844zm-541.62 397.78 4.2188 6.7461 46.402-0.84375c-22.5-2.2461-39.371-4.2148-50.621-5.9023zm499.86-169.15c-23.062-11.531-45.418-14.062-67.07-7.5938v4.2188l-173.79 126.12h111.36l101.23-103.77c10.406-10.684 19.828-17.012 28.266-18.98zm47.664 148.48h-96.598v-4.6406h79.305l6.3242-5.4805h5.0625c3.0938 3.6523 5.0625 7.0273 5.9062 10.121zm-5.9062 15.609h-5.0625l-6.3242-5.0625h-79.305v-4.6406h96.598c-0.84375 3.0938-2.8125 6.3281-5.9062 9.7031zm-102.5 9.6992c3.6562 1.4062 7.4531 2.1094 11.391 2.1094h64.961c24.746 0 37.121-8.4336 37.121-25.309 0-8.4375-4.6406-14.691-13.922-18.77-9.2773-4.0781-17.012-6.1172-23.199-6.1172h-64.961c-4.7812 0-8.5781 0.5625-11.391 1.6875h-333.66c-5.0625 0-28.543 1.6172-70.445 4.8516-41.902 3.2344-62.852 7.3828-62.852 12.441v11.812c0 4.5 20.949 8.5078 62.852 12.023 41.902 3.5156 65.383 5.2695 70.445 5.2695zm125.28-207.54h-42.602c-3.375 1.125-3.375 2.25 0 3.375h42.602zm-43.445 8.4375h-5.4844v-13.5h5.4844c17.152-6.1875 33.605-9.9844 49.352-11.391l4.6406-25.309 4.6406 0.42188c0.5625-4.2188 1.6875-10.262 3.375-18.137-28.684-0.5625-64.398 1.6875-107.14 6.75 3.6562 4.2148 7.4531 7.8711 11.391 10.965 4.7812 3.375 9.4219 5.625 13.918 6.75l12.656 2.9531-11.812 5.9062c-13.496 6.75-30.23 10.121-50.195 10.121-5.0625 0-8.5781-0.14062-10.547-0.42188-4.2188-0.5625-7.5898-1.1211-10.121-1.6836l-3.375-1.2656v-5.4844l-24.043-17.297c-41.34 5.625-69.32 8.5781-83.945 8.8594-31.496 0.28125-47.242 11.953-47.242 35.012 0 22.215 15.746 33.887 47.242 35.012 18.844 0.28125 46.824 3.2344 83.945 8.8594l24.043-17.297v-5.4844l3.375-1.2656c2.5312-0.84375 5.9023-1.4062 10.121-1.6875 1.9688-0.28125 5.4844-0.42187 10.547-0.42187 19.965 0 36.699 3.375 50.195 10.125l11.812 5.4844-12.656 3.375c-4.4961 0.84375-9.1367 3.0938-13.918 6.75-3.6562 2.2461-7.4531 5.7617-11.391 10.543 40.777 5.0625 76.492 7.4531 107.14 7.1719-1.6875-7.3125-2.8125-13.359-3.375-18.137h-4.6406l-4.6406-24.891c-17.434-2.25-33.887-6.043-49.352-11.387zm48.508-20.25c-12.652 1.6875-23.762 3.9375-33.324 6.75h29.105l3.7969-4.2188zm-4.2188 20.25h-29.105c9.5625 2.5312 20.672 4.7812 33.324 6.7461l-0.42188-2.5273zm136.67-8.4375c0-8.4375-4.2188-12.656-12.652-12.656h-21.516c-6.4688-12.652-16.59-18.98-30.371-18.98l-58.211-5.0625-5.9062 29.527-4.2188 5.0625v7.5938l4.2188 5.0625 5.9062 29.105 58.211-5.0625c15.469 0 26.012-7.3125 31.637-21.934h20.25c8.4336 0 12.652-4.2188 12.652-12.656zm-46.82 1.6875c0-11.531-5.9062-17.297-17.719-17.297-11.527 0-17.293 5.7656-17.293 17.297 0 11.812 5.7656 17.715 17.293 17.715 11.812 0 17.719-5.9023 17.719-17.715zm4.6406 0c0 14.902-7.4531 22.355-22.359 22.355-14.902 0-22.355-7.4531-22.355-22.355 0-14.906 7.4531-22.355 22.355-22.355 14.906 0 22.359 7.4492 22.359 22.355zm-13.922 0c0-5.625-2.8125-8.4375-8.4375-8.4375-5.3438 0-8.0156 2.8125-8.0156 8.4375s2.6719 8.4375 8.0156 8.4375c5.625 0 8.4375-2.8125 8.4375-8.4375zm4.6406 0c0 8.7188-4.3594 13.078-13.078 13.078-8.4375 0-12.652-4.3594-12.652-13.078s4.2148-13.078 12.652-13.078c8.7188 0 13.078 4.3594 13.078 13.078zm-43.871-2.1094v4.2188h-35.012v-4.2188zm258.58 2.1094c-0.5625-8.4375-4.7812-12.656-12.656-12.656-8.4336 0-12.652 4.2188-12.652 12.656s4.2188 12.656 12.652 12.656c8.4375 0 12.656-4.2188 12.656-12.656zm4.6406 0c0 11.531-5.7656 17.293-17.297 17.293-11.527 0-17.293-5.7617-17.293-17.293s5.7656-17.297 17.293-17.297c11.531 0 17.297 5.7656 17.297 17.297zm32.48 0c0-13.781-4.9219-25.59-14.766-35.434-9.5586-9.5625-21.23-14.344-35.012-14.344-15.184 0-31.777 5.7656-49.773 17.297-18.559 11.531-27.84 22.355-27.84 32.48 0 9.8438 9.2812 20.668 27.84 32.48 17.996 11.531 34.59 17.293 49.773 17.293 13.781 0 25.453-4.918 35.012-14.762 9.8438-9.5625 14.766-21.234 14.766-35.012zm5.0625 0c0 14.902-5.3438 27.699-16.031 38.387-10.684 10.684-23.621 16.027-38.809 16.027-15.746 0-33.18-6.0469-52.305-18.137-20.246-12.656-30.371-24.746-30.371-36.277s10.125-23.762 30.371-36.699c19.125-12.094 36.559-18.137 52.305-18.137 14.625 0 27.562 5.3398 38.809 16.027 10.688 10.969 16.031 23.902 16.031 38.809zm-54.418-29.105c-3.9336 0-10.262 1.6875-18.98 5.0625-7.875 3.9375-11.812 6.4648-11.812 7.5898v32.48c0 3.0938 3.9375 5.625 11.812 7.5938 7.875 3.375 14.203 5.0625 18.98 5.0625 19.406 0 29.391-9.2812 29.953-27.84 0-19.688-9.9844-29.668-29.953-29.949zm34.59 29.105v0.84375c0 21.371-11.527 32.34-34.59 32.902-4.4961 0-11.527-1.8281-21.09-5.4844-7.0312-3.9375-10.969-6.3281-11.809-7.1719-1.6875-1.4062-2.5312-3.0938-2.5312-5.0625v-32.48c0-1.4062 0.70312-2.9492 2.1094-4.6367 3.0898-2.8125 7.168-5.2031 12.23-7.1719 9-3.6562 16.031-5.4844 21.09-5.4844 22.5 0.28125 34.027 11.531 34.59 33.746zm-448.4-206.27h-333.66c-5.0625 0-28.543 1.6875-70.445 5.0625-41.902 3.375-62.852 7.5938-62.852 12.656v11.387c0 4.7812 20.949 8.8594 62.852 12.234 41.902 3.375 65.383 5.0625 70.445 5.0625h333.66c3.6562 1.4062 7.4531 2.1094 11.391 2.1094h64.961c5.3438 0 12.867-2.25 22.566-6.75 9.7031-4.5 14.555-10.547 14.555-18.137 0.28125-16.875-12.094-25.312-37.121-25.312h-64.961c-4.7812 0-8.5781 0.5625-11.391 1.6875z" fill-rule="evenodd"/>
4
+ </svg>
package/README.md ADDED
@@ -0,0 +1,301 @@
1
+ <p align="center">
2
+ <img
3
+ class="project-logo"
4
+ src="./NCC-1701-a-blue.svg#gh-light-mode-only"
5
+ alt="WarpDrive"
6
+ width="120px"
7
+ title="WarpDrive" />
8
+ <img
9
+ class="project-logo"
10
+ src="./NCC-1701-a.svg#gh-dark-mode-only"
11
+ alt="WarpDrive"
12
+ width="120px"
13
+ title="WarpDrive" />
14
+ </p>
15
+
16
+ <h3 align="center">⚡️ Simple, Fast HTTP Mocking</h3>
17
+ <p align="center">Ideal for Test Suites</p>
18
+
19
+ <p align="center">
20
+ <img
21
+ src="./pnpm-install-logo.png"
22
+ alt="WarpDrive Holodeck"
23
+ width="320px"
24
+ title="WarpDrive Holodeck" />
25
+ </p>
26
+
27
+
28
+ - ⚡️ Real network requests
29
+ - brotli compression
30
+ - http/2
31
+ - no CORS preflight requests
32
+ - 💜 Unparalleled DX
33
+ - debug real network requests
34
+ - every request is scoped to a test
35
+ - run as many tests as desired simultaneously
36
+ - 🔥 Blazing Fast Tests
37
+ - record your tests when you change them
38
+ - replays from cache until you change them again
39
+ - zero-work: setup work is skipped when in replay mode
40
+
41
+ ## Installation
42
+
43
+
44
+ ```json
45
+ pnpm install @warp-drive/holodeck
46
+ ```
47
+
48
+ **Tagged Releases**
49
+
50
+ - ![NPM Canary Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/canary?label=%40canary&color=FFBF00)
51
+ - ![NPM Beta Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/beta?label=%40beta&color=ff00ff)
52
+ - ![NPM Stable Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/latest?label=%40latest&color=90EE90)
53
+ - ![NPM LTS Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/lts?label=%40lts&color=0096FF)
54
+ - ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/lts-4-12?label=%40lts-4-12&color=bbbbbb)
55
+
56
+
57
+
58
+ ## Usage
59
+ #### Mocking from Within a Test
60
+
61
+ ```ts
62
+ import { GET } from '@warp-drive/holodeck/mock';
63
+
64
+ await GET(context, 'users/1', () => ({
65
+ data: {
66
+ id: '1',
67
+ type: 'user',
68
+ attributes: {
69
+ name: 'Chris Thoburn',
70
+ },
71
+ },
72
+
73
+ // set RECORD to false or remove
74
+ // the options hash entirely once the request
75
+ // has been recorded
76
+ }), { RECORD: true });
77
+ ```
78
+
79
+ ## Motivations
80
+
81
+ Comprehensive DX around data management should extend to testing.
82
+
83
+ ### ✨ Amazing Developer Experience
84
+
85
+ EmberData already understands your data schemas. Building a mocking utility with tight integration into your data usage patterns could bring enormous DX and test suite performance benefits.
86
+
87
+ Building a real mock server instead of intercepting requests in the browser or via ServiceWorker gives us out-of-the-box DX, better tunability, and greater ability to optimize test suite performance. Speed is the ultimate DX.
88
+
89
+ ### 🔥 Blazing Fast Tests
90
+
91
+ We've noticed test suites spending an enormous amount of time creating and tearing down mock state in between tests. To combat this, we want to provide
92
+ an approach built over `http/3` (`http/2` for now) utilizing aggressive caching
93
+ and `brotli` minification in a way that can be replayed over and over again.
94
+
95
+ Basically, pay the cost when you write the test. Forever after skip the cost until you need to edit the test again.
96
+
97
+ ## Setup
98
+
99
+ ### Use with WarpDrive
100
+
101
+ First, you will need to add the holodeck handler to the request manager chain prior to `Fetch` (or any equivalent handler that proceeds to network).
102
+
103
+ For instance:
104
+
105
+ ```ts
106
+ import RequestManager from '@ember-data/request';
107
+ import Fetch from '@ember-data/request/fetch';
108
+ import { MockServerHandler } from '@warp-drive/holodeck';
109
+
110
+ const manager = new RequestManager();
111
+ manager.use([new MockServerHandler(testContext), Fetch]);
112
+ ```
113
+
114
+ From within a test this might look like:
115
+
116
+ ```ts
117
+ import RequestManager from '@ember-data/request';
118
+ import Fetch from '@ember-data/request/fetch';
119
+ import { MockServerHandler } from '@warp-drive/holodeck';
120
+ import { module, test } from 'qunit';
121
+
122
+ module('my module', function() {
123
+ test('my test', async function() {
124
+ const manager = new RequestManager();
125
+ manager.use([new MockServerHandler(this), Fetch]);
126
+ });
127
+ });
128
+ ```
129
+
130
+ Next, you will need to configure holodeck to understand your tests contexts. For qunit and diagnostic
131
+ in a project using Ember this is typically done in `tests/test-helper.js`
132
+
133
+ #### With Diagnostic
134
+
135
+ ```ts
136
+ import { setupGlobalHooks } from '@warp-drive/diagnostic';
137
+ import { setConfig, setTestId } from '@warp-drive/holodeck';
138
+
139
+ // if not proxying the port / set port to the correct value here
140
+ const MockHost = `https://${window.location.hostname}:${Number(window.location.port) + 1}`;
141
+
142
+ setConfig({ host: MockHost });
143
+
144
+ setupGlobalHooks((hooks) => {
145
+ hooks.beforeEach(function (assert) {
146
+ setTestId(this, assert.test.testId);
147
+ });
148
+ hooks.afterEach(function () {
149
+ setTestId(this, null);
150
+ });
151
+ });
152
+ ```
153
+
154
+ #### With QUnit
155
+
156
+ ```ts
157
+ import * as QUnit from 'qunit';
158
+ import { setConfig, setTestId } from '@warp-drive/holodeck';
159
+
160
+ // if not proxying the port / set port to the correct value here
161
+ const MockHost = `https://${window.location.hostname}:${Number(window.location.port) + 1}`;
162
+
163
+ setConfig({ host: MockHost });
164
+
165
+ QUnit.hooks.beforeEach(function (assert) {
166
+ setTestId(assert.test.testId);
167
+ });
168
+ QUnit.hooks.afterEach(function (assert) {
169
+ setTestId(null);
170
+ });
171
+ ```
172
+
173
+ ### Testem
174
+
175
+ You can integrate holodeck with Testem using testem's [async config capability](https://github.com/testem/testem/blob/master/docs/config_file.md#returning-a-promise-from-testemjs):
176
+
177
+ ```ts
178
+ module.exports = async function () {
179
+ const holodeck = (await import('@warp-drive/holodeck')).default;
180
+ await holodeck.launchProgram({
181
+ port: 7373,
182
+ });
183
+
184
+ process.on('beforeExit', async () => {
185
+ await holodeck.endProgram();
186
+ });
187
+
188
+ return {
189
+ // ... testem config
190
+ };
191
+ };
192
+ ```
193
+
194
+ If you need the API mock to run on the same port as the test suite, you can use Testem's [API Proxy](https://github.com/testem/testem/tree/master?tab=readme-ov-file#api-proxy)
195
+
196
+ ```ts
197
+ module.exports = async function () {
198
+ const holodeck = (await import('@warp-drive/holodeck')).default;
199
+ await holodeck.launchProgram({
200
+ port: 7373,
201
+ });
202
+
203
+ process.on('beforeExit', async () => {
204
+ await holodeck.endProgram();
205
+ });
206
+
207
+ return {
208
+ "proxies": {
209
+ "/api": {
210
+ // holodeck always runs on https
211
+ // the proxy is transparent so this means /api/v1 will route to https://localhost:7373/api/v1
212
+ "target": "https://localhost:7373",
213
+ // "onlyContentTypes": ["xml", "json"],
214
+ // if test suite is on http, set this to false
215
+ // "secure": false,
216
+ },
217
+ }
218
+ };
219
+ };
220
+ ```
221
+
222
+ ### Diagnostic
223
+
224
+ holodeck can be launched and cleaned up using the lifecycle hooks in the launch config
225
+ for diagnostic in `diagnostic.js`:
226
+
227
+ ```ts
228
+ import launch from '@warp-drive/diagnostic/server/default-setup.js';
229
+ import holodeck from '@warp-drive/holodeck';
230
+
231
+ await launch({
232
+ async setup(options) {
233
+ await holodeck.launchProgram({
234
+ port: options.port + 1,
235
+ });
236
+ },
237
+ async cleanup() {
238
+ await holodeck.endProgram();
239
+ },
240
+ });
241
+ ```
242
+
243
+ ### ♥️ Credits
244
+
245
+ <details>
246
+ <summary>Brought to you with ♥️ love by <a href="https://emberjs.com" title="EmberJS">🐹 Ember</a></summary>
247
+
248
+ <style type="text/css">
249
+ img.project-logo {
250
+ padding: 0 5em 1em 5em;
251
+ width: 100px;
252
+ border-bottom: 2px solid #0969da;
253
+ margin: 0 auto;
254
+ display: block;
255
+ }
256
+ details > summary {
257
+ font-size: 1.1rem;
258
+ line-height: 1rem;
259
+ margin-bottom: 1rem;
260
+ }
261
+ details {
262
+ font-size: 1rem;
263
+ }
264
+ details > summary strong {
265
+ display: inline-block;
266
+ padding: .2rem 0;
267
+ color: #000;
268
+ border-bottom: 3px solid #0969da;
269
+ }
270
+
271
+ details > details {
272
+ margin-left: 2rem;
273
+ }
274
+ details > details > summary {
275
+ font-size: 1rem;
276
+ line-height: 1rem;
277
+ margin-bottom: 1rem;
278
+ }
279
+ details > details > summary strong {
280
+ display: inline-block;
281
+ padding: .2rem 0;
282
+ color: #555;
283
+ border-bottom: 2px solid #555;
284
+ }
285
+ details > details {
286
+ font-size: .85rem;
287
+ }
288
+
289
+ @media (prefers-color-scheme: dark) {
290
+ details > summary strong {
291
+ color: #fff;
292
+ }
293
+ }
294
+ @media (prefers-color-scheme: dark) {
295
+ details > details > summary strong {
296
+ color: #afaba0;
297
+ border-bottom: 2px solid #afaba0;
298
+ }
299
+ }
300
+ </style>
301
+ </details>
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
1
+ const TEST_IDS = new WeakMap();
2
+ let HOST = 'https://localhost:1135/';
3
+ function setConfig({
4
+ host
5
+ }) {
6
+ HOST = host.endsWith('/') ? host : `${host}/`;
7
+ }
8
+ function setTestId(context, str) {
9
+ if (str && TEST_IDS.has(context)) {
10
+ throw new Error(`MockServerHandler is already configured with a testId.`);
11
+ }
12
+ if (str) {
13
+ TEST_IDS.set(context, {
14
+ id: str,
15
+ request: 0,
16
+ mock: 0
17
+ });
18
+ } else {
19
+ TEST_IDS.delete(context);
20
+ }
21
+ }
22
+ let IS_RECORDING = false;
23
+ function setIsRecording(value) {
24
+ IS_RECORDING = Boolean(value);
25
+ }
26
+ function getIsRecording() {
27
+ return IS_RECORDING;
28
+ }
29
+ class MockServerHandler {
30
+ constructor(owner) {
31
+ this.owner = owner;
32
+ }
33
+ async request(context, next) {
34
+ const test = TEST_IDS.get(this.owner);
35
+ if (!test) {
36
+ throw new Error(`MockServerHandler is not configured with a testId. Use setTestId to set the testId for each test`);
37
+ }
38
+ const request = Object.assign({}, context.request);
39
+ const isRecording = request.url.endsWith('/__record');
40
+ const firstChar = request.url.includes('?') ? '&' : '?';
41
+ const queryForTest = `${firstChar}__xTestId=${test.id}&__xTestRequestNumber=${isRecording ? test.mock++ : test.request++}`;
42
+ request.url = request.url + queryForTest;
43
+ request.mode = 'cors';
44
+ request.credentials = 'omit';
45
+ request.referrerPolicy = '';
46
+ try {
47
+ const future = next(request);
48
+ context.setStream(future.getStream());
49
+ return await future;
50
+ } catch (e) {
51
+ if (e instanceof Error && !(e instanceof DOMException)) {
52
+ e.message = e.message.replace(queryForTest, '');
53
+ }
54
+ throw e;
55
+ }
56
+ }
57
+ }
58
+ async function mock(owner, generate, isRecording) {
59
+ const test = TEST_IDS.get(owner);
60
+ if (!test) {
61
+ throw new Error(`Cannot call "mock" before configuring a testId. Use setTestId to set the testId for each test`);
62
+ }
63
+ const testMockNum = test.mock++;
64
+ if (getIsRecording() || isRecording) {
65
+ const url = `${HOST}__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;
66
+ await fetch(url, {
67
+ method: 'POST',
68
+ body: JSON.stringify(generate()),
69
+ mode: 'cors',
70
+ credentials: 'omit',
71
+ referrerPolicy: ''
72
+ });
73
+ }
74
+ }
75
+
76
+ export { MockServerHandler, getIsRecording, mock, setConfig, setIsRecording, setTestId };
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Handler, NextFn, RequestContext, RequestInfo, StructuredDataDocument } from '@ember-data/request';\n\nimport type { ScaffoldGenerator } from './mock';\n\nconst TEST_IDS = new WeakMap<object, { id: string; request: number; mock: number }>();\n\nlet HOST = 'https://localhost:1135/';\nexport function setConfig({ host }: { host: string }) {\n HOST = host.endsWith('/') ? host : `${host}/`;\n}\n\nexport function setTestId(context: object, str: string | null) {\n if (str && TEST_IDS.has(context)) {\n throw new Error(`MockServerHandler is already configured with a testId.`);\n }\n if (str) {\n TEST_IDS.set(context, { id: str, request: 0, mock: 0 });\n } else {\n TEST_IDS.delete(context);\n }\n}\n\nlet IS_RECORDING = false;\nexport function setIsRecording(value: boolean) {\n IS_RECORDING = Boolean(value);\n}\nexport function getIsRecording() {\n return IS_RECORDING;\n}\n\nexport class MockServerHandler implements Handler {\n declare owner: object;\n constructor(owner: object) {\n this.owner = owner;\n }\n async request<T>(context: RequestContext, next: NextFn<T>): Promise<StructuredDataDocument<T>> {\n const test = TEST_IDS.get(this.owner);\n if (!test) {\n throw new Error(\n `MockServerHandler is not configured with a testId. Use setTestId to set the testId for each test`\n );\n }\n\n const request: RequestInfo = Object.assign({}, context.request);\n const isRecording = request.url!.endsWith('/__record');\n const firstChar = request.url!.includes('?') ? '&' : '?';\n const queryForTest = `${firstChar}__xTestId=${test.id}&__xTestRequestNumber=${\n isRecording ? test.mock++ : test.request++\n }`;\n request.url = request.url + queryForTest;\n\n request.mode = 'cors';\n request.credentials = 'omit';\n request.referrerPolicy = '';\n\n try {\n const future = next(request);\n context.setStream(future.getStream());\n return await future;\n } catch (e) {\n if (e instanceof Error && !(e instanceof DOMException)) {\n e.message = e.message.replace(queryForTest, '');\n }\n throw e;\n }\n }\n}\n\nexport async function mock(owner: object, generate: ScaffoldGenerator, isRecording?: boolean) {\n const test = TEST_IDS.get(owner);\n if (!test) {\n throw new Error(`Cannot call \"mock\" before configuring a testId. Use setTestId to set the testId for each test`);\n }\n const testMockNum = test.mock++;\n if (getIsRecording() || isRecording) {\n const port = window.location.port ? `:${window.location.port}` : '';\n const url = `${HOST}__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;\n await fetch(url, {\n method: 'POST',\n body: JSON.stringify(generate()),\n mode: 'cors',\n credentials: 'omit',\n referrerPolicy: '',\n });\n }\n}\n"],"names":["TEST_IDS","WeakMap","HOST","setConfig","host","endsWith","setTestId","context","str","has","Error","set","id","request","mock","delete","IS_RECORDING","setIsRecording","value","Boolean","getIsRecording","MockServerHandler","constructor","owner","next","test","get","Object","assign","isRecording","url","firstChar","includes","queryForTest","mode","credentials","referrerPolicy","future","setStream","getStream","e","DOMException","message","replace","generate","testMockNum","fetch","method","body","JSON","stringify"],"mappings":"AAIA,MAAMA,QAAQ,GAAG,IAAIC,OAAO,EAAyD,CAAA;AAErF,IAAIC,IAAI,GAAG,yBAAyB,CAAA;AAC7B,SAASC,SAASA,CAAC;AAAEC,EAAAA,IAAAA;AAAuB,CAAC,EAAE;AACpDF,EAAAA,IAAI,GAAGE,IAAI,CAACC,QAAQ,CAAC,GAAG,CAAC,GAAGD,IAAI,GAAI,CAAEA,EAAAA,IAAK,CAAE,CAAA,CAAA,CAAA;AAC/C,CAAA;AAEO,SAASE,SAASA,CAACC,OAAe,EAAEC,GAAkB,EAAE;EAC7D,IAAIA,GAAG,IAAIR,QAAQ,CAACS,GAAG,CAACF,OAAO,CAAC,EAAE;AAChC,IAAA,MAAM,IAAIG,KAAK,CAAE,CAAA,sDAAA,CAAuD,CAAC,CAAA;AAC3E,GAAA;AACA,EAAA,IAAIF,GAAG,EAAE;AACPR,IAAAA,QAAQ,CAACW,GAAG,CAACJ,OAAO,EAAE;AAAEK,MAAAA,EAAE,EAAEJ,GAAG;AAAEK,MAAAA,OAAO,EAAE,CAAC;AAAEC,MAAAA,IAAI,EAAE,CAAA;AAAE,KAAC,CAAC,CAAA;AACzD,GAAC,MAAM;AACLd,IAAAA,QAAQ,CAACe,MAAM,CAACR,OAAO,CAAC,CAAA;AAC1B,GAAA;AACF,CAAA;AAEA,IAAIS,YAAY,GAAG,KAAK,CAAA;AACjB,SAASC,cAAcA,CAACC,KAAc,EAAE;AAC7CF,EAAAA,YAAY,GAAGG,OAAO,CAACD,KAAK,CAAC,CAAA;AAC/B,CAAA;AACO,SAASE,cAAcA,GAAG;AAC/B,EAAA,OAAOJ,YAAY,CAAA;AACrB,CAAA;AAEO,MAAMK,iBAAiB,CAAoB;EAEhDC,WAAWA,CAACC,KAAa,EAAE;IACzB,IAAI,CAACA,KAAK,GAAGA,KAAK,CAAA;AACpB,GAAA;AACA,EAAA,MAAMV,OAAOA,CAAIN,OAAuB,EAAEiB,IAAe,EAAsC;IAC7F,MAAMC,IAAI,GAAGzB,QAAQ,CAAC0B,GAAG,CAAC,IAAI,CAACH,KAAK,CAAC,CAAA;IACrC,IAAI,CAACE,IAAI,EAAE;AACT,MAAA,MAAM,IAAIf,KAAK,CACZ,CAAA,gGAAA,CACH,CAAC,CAAA;AACH,KAAA;AAEA,IAAA,MAAMG,OAAoB,GAAGc,MAAM,CAACC,MAAM,CAAC,EAAE,EAAErB,OAAO,CAACM,OAAO,CAAC,CAAA;IAC/D,MAAMgB,WAAW,GAAGhB,OAAO,CAACiB,GAAG,CAAEzB,QAAQ,CAAC,WAAW,CAAC,CAAA;AACtD,IAAA,MAAM0B,SAAS,GAAGlB,OAAO,CAACiB,GAAG,CAAEE,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAA;IACxD,MAAMC,YAAY,GAAI,CAAEF,EAAAA,SAAU,aAAYN,IAAI,CAACb,EAAG,CACpDiB,sBAAAA,EAAAA,WAAW,GAAGJ,IAAI,CAACX,IAAI,EAAE,GAAGW,IAAI,CAACZ,OAAO,EACzC,CAAC,CAAA,CAAA;AACFA,IAAAA,OAAO,CAACiB,GAAG,GAAGjB,OAAO,CAACiB,GAAG,GAAGG,YAAY,CAAA;IAExCpB,OAAO,CAACqB,IAAI,GAAG,MAAM,CAAA;IACrBrB,OAAO,CAACsB,WAAW,GAAG,MAAM,CAAA;IAC5BtB,OAAO,CAACuB,cAAc,GAAG,EAAE,CAAA;IAE3B,IAAI;AACF,MAAA,MAAMC,MAAM,GAAGb,IAAI,CAACX,OAAO,CAAC,CAAA;MAC5BN,OAAO,CAAC+B,SAAS,CAACD,MAAM,CAACE,SAAS,EAAE,CAAC,CAAA;AACrC,MAAA,OAAO,MAAMF,MAAM,CAAA;KACpB,CAAC,OAAOG,CAAC,EAAE;MACV,IAAIA,CAAC,YAAY9B,KAAK,IAAI,EAAE8B,CAAC,YAAYC,YAAY,CAAC,EAAE;AACtDD,QAAAA,CAAC,CAACE,OAAO,GAAGF,CAAC,CAACE,OAAO,CAACC,OAAO,CAACV,YAAY,EAAE,EAAE,CAAC,CAAA;AACjD,OAAA;AACA,MAAA,MAAMO,CAAC,CAAA;AACT,KAAA;AACF,GAAA;AACF,CAAA;AAEO,eAAe1B,IAAIA,CAACS,KAAa,EAAEqB,QAA2B,EAAEf,WAAqB,EAAE;AAC5F,EAAA,MAAMJ,IAAI,GAAGzB,QAAQ,CAAC0B,GAAG,CAACH,KAAK,CAAC,CAAA;EAChC,IAAI,CAACE,IAAI,EAAE;AACT,IAAA,MAAM,IAAIf,KAAK,CAAE,CAAA,6FAAA,CAA8F,CAAC,CAAA;AAClH,GAAA;AACA,EAAA,MAAMmC,WAAW,GAAGpB,IAAI,CAACX,IAAI,EAAE,CAAA;AAC/B,EAAA,IAAIM,cAAc,EAAE,IAAIS,WAAW,EAAE;IAEnC,MAAMC,GAAG,GAAI,CAAA,EAAE5B,IAAK,CAAA,mBAAA,EAAqBuB,IAAI,CAACb,EAAG,CAAwBiC,sBAAAA,EAAAA,WAAY,CAAC,CAAA,CAAA;IACtF,MAAMC,KAAK,CAAChB,GAAG,EAAE;AACfiB,MAAAA,MAAM,EAAE,MAAM;MACdC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACN,QAAQ,EAAE,CAAC;AAChCV,MAAAA,IAAI,EAAE,MAAM;AACZC,MAAAA,WAAW,EAAE,MAAM;AACnBC,MAAAA,cAAc,EAAE,EAAA;AAClB,KAAC,CAAC,CAAA;AACJ,GAAA;AACF;;;;"}
package/dist/mock.js ADDED
@@ -0,0 +1,38 @@
1
+ import { mock, getIsRecording } from './index.js';
2
+
3
+ /**
4
+ * Sets up Mocking for a GET request on the mock server
5
+ * for the supplied url.
6
+ *
7
+ * The response body is generated by the supplied response function.
8
+ *
9
+ * Available options:
10
+ * - status: the status code to return (default: 200)
11
+ * - headers: the headers to return (default: {})
12
+ * - body: the body to match against for the request (default: null)
13
+ * - RECORD: whether to record the request (default: false)
14
+ *
15
+ * @param url the url to mock, relative to the mock server host (e.g. `users/1`)
16
+ * @param response a function which generates the response to return
17
+ * @param options status, headers for the response, body to match against for the request, and whether to record the request
18
+ * @return
19
+ */
20
+ function GET(owner, url, response, options) {
21
+ return mock(owner, () => ({
22
+ status: options?.status ?? 200,
23
+ statusText: options?.statusText ?? 'OK',
24
+ headers: options?.headers ?? {},
25
+ body: options?.body ?? null,
26
+ method: 'GET',
27
+ url,
28
+ response: response()
29
+ }), getIsRecording() || (options?.RECORD ?? false));
30
+ }
31
+ function POST() {}
32
+ function PUT() {}
33
+ function PATCH() {}
34
+ function DELETE() {}
35
+ function QUERY() {}
36
+
37
+ export { DELETE, GET, PATCH, POST, PUT, QUERY };
38
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.js","sources":["../src/mock.ts"],"sourcesContent":["import { getIsRecording, mock } from '.';\n\nexport interface Scaffold {\n status: number;\n statusText?: string;\n headers: Record<string, string>;\n body: Record<string, string> | string | null;\n method: string;\n url: string;\n response: Record<string, unknown>;\n}\n\nexport type ScaffoldGenerator = () => Scaffold;\nexport type ResponseGenerator = () => Record<string, unknown>;\n\n/**\n * Sets up Mocking for a GET request on the mock server\n * for the supplied url.\n *\n * The response body is generated by the supplied response function.\n *\n * Available options:\n * - status: the status code to return (default: 200)\n * - headers: the headers to return (default: {})\n * - body: the body to match against for the request (default: null)\n * - RECORD: whether to record the request (default: false)\n *\n * @param url the url to mock, relative to the mock server host (e.g. `users/1`)\n * @param response a function which generates the response to return\n * @param options status, headers for the response, body to match against for the request, and whether to record the request\n * @return\n */\nexport function GET(\n owner: object,\n url: string,\n response: ResponseGenerator,\n options?: Partial<Omit<Scaffold, 'response' | 'url' | 'method'>> & { RECORD?: boolean }\n): Promise<void> {\n return mock(\n owner,\n () => ({\n status: options?.status ?? 200,\n statusText: options?.statusText ?? 'OK',\n headers: options?.headers ?? {},\n body: options?.body ?? null,\n method: 'GET',\n url,\n response: response(),\n }),\n getIsRecording() || (options?.RECORD ?? false)\n );\n}\nexport function POST() {}\nexport function PUT() {}\nexport function PATCH() {}\nexport function DELETE() {}\nexport function QUERY() {}\n"],"names":["GET","owner","url","response","options","mock","status","statusText","headers","body","method","getIsRecording","RECORD","POST","PUT","PATCH","DELETE","QUERY"],"mappings":";;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,GAAGA,CACjBC,KAAa,EACbC,GAAW,EACXC,QAA2B,EAC3BC,OAAuF,EACxE;AACf,EAAA,OAAOC,IAAI,CACTJ,KAAK,EACL,OAAO;AACLK,IAAAA,MAAM,EAAEF,OAAO,EAAEE,MAAM,IAAI,GAAG;AAC9BC,IAAAA,UAAU,EAAEH,OAAO,EAAEG,UAAU,IAAI,IAAI;AACvCC,IAAAA,OAAO,EAAEJ,OAAO,EAAEI,OAAO,IAAI,EAAE;AAC/BC,IAAAA,IAAI,EAAEL,OAAO,EAAEK,IAAI,IAAI,IAAI;AAC3BC,IAAAA,MAAM,EAAE,KAAK;IACbR,GAAG;IACHC,QAAQ,EAAEA,QAAQ,EAAC;AACrB,GAAC,CAAC,EACFQ,cAAc,EAAE,KAAKP,OAAO,EAAEQ,MAAM,IAAI,KAAK,CAC/C,CAAC,CAAA;AACH,CAAA;AACO,SAASC,IAAIA,GAAG,EAAC;AACjB,SAASC,GAAGA,GAAG,EAAC;AAChB,SAASC,KAAKA,GAAG,EAAC;AAClB,SAASC,MAAMA,GAAG,EAAC;AACnB,SAASC,KAAKA,GAAG;;;;"}
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@warp-drive/holodeck",
3
+ "description": "⚡️ Simple, Fast HTTP Mocking for Tests",
4
+ "version": "0.0.0-alpha.101",
5
+ "license": "MIT",
6
+ "author": "Chris Thoburn <runspired@users.noreply.github.com>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+ssh://git@github.com:emberjs/data.git",
10
+ "directory": "packages/holodeck"
11
+ },
12
+ "homepage": "https://github.com/emberjs/data",
13
+ "bugs": "https://github.com/emberjs/data/issues",
14
+ "engines": {
15
+ "node": ">= 18.20.4"
16
+ },
17
+ "keywords": [
18
+ "http-mock"
19
+ ],
20
+ "volta": {
21
+ "extends": "../../package.json"
22
+ },
23
+ "dependencies": {
24
+ "@hono/node-server": "^1.11.1",
25
+ "chalk": "^5.3.0",
26
+ "hono": "^4.6.5"
27
+ },
28
+ "type": "module",
29
+ "files": [
30
+ "bin",
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE.md",
34
+ "server",
35
+ "NCC-1701-a.svg",
36
+ "NCC-1701-a-blue.svg"
37
+ ],
38
+ "bin": {
39
+ "ensure-cert": "./server/ensure-cert.js"
40
+ },
41
+ "scripts": {
42
+ "check:pkg-types": "tsc --noEmit",
43
+ "build:pkg": "vite build;",
44
+ "sync-hardlinks": "bun run sync-dependencies-meta-injected"
45
+ },
46
+ "peerDependencies": {
47
+ "@ember-data/request": "5.4.0-alpha.115",
48
+ "@warp-drive/core-types": "0.0.0-alpha.101"
49
+ },
50
+ "devDependencies": {
51
+ "@babel/core": "^7.24.5",
52
+ "@babel/plugin-transform-typescript": "^7.24.5",
53
+ "@babel/preset-env": "^7.24.5",
54
+ "@babel/preset-typescript": "^7.24.1",
55
+ "@babel/runtime": "^7.24.5",
56
+ "@ember-data/request": "5.4.0-alpha.115",
57
+ "@warp-drive/core-types": "0.0.0-alpha.101",
58
+ "@warp-drive/internal-config": "5.4.0-alpha.115",
59
+ "pnpm-sync-dependencies-meta-injected": "0.0.14",
60
+ "typescript": "^5.4.5",
61
+ "vite": "^5.2.11"
62
+ },
63
+ "exports": {
64
+ ".": {
65
+ "node": "./server/index.js",
66
+ "bun": "./server/index.js",
67
+ "deno": "./server/index.js",
68
+ "browser": {
69
+ "default": "./dist/index.js"
70
+ },
71
+ "import": {
72
+ "default": "./dist/index.js"
73
+ },
74
+ "default": "./server/index.js"
75
+ },
76
+ "./mock": {
77
+ "default": "./dist/mock.js"
78
+ }
79
+ },
80
+ "dependenciesMeta": {
81
+ "@ember-data/request": {
82
+ "injected": true
83
+ },
84
+ "@warp-drive/core-types": {
85
+ "injected": true
86
+ }
87
+ }
88
+ }
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import { homedir, userInfo } from 'os';
5
+ import path from 'path';
6
+
7
+ function getShellConfigFilePath() {
8
+ const shell = userInfo().shell;
9
+ switch (shell) {
10
+ case '/bin/zsh':
11
+ return path.join(homedir(), '.zshrc');
12
+ case '/bin/bash':
13
+ return path.join(homedir(), '.bashrc');
14
+ default:
15
+ throw Error(
16
+ `Unable to determine configuration file for shell: ${shell}. Manual SSL Cert Setup Required for Holodeck.`
17
+ );
18
+ }
19
+ }
20
+
21
+ function main() {
22
+ let CERT_PATH = process.env.HOLODECK_SSL_CERT_PATH;
23
+ let KEY_PATH = process.env.HOLODECK_SSL_KEY_PATH;
24
+ const configFilePath = getShellConfigFilePath();
25
+
26
+ if (!CERT_PATH || !KEY_PATH) {
27
+ console.log(`Environment variables not found, updating the environment config file...\n`);
28
+
29
+ if (!CERT_PATH) {
30
+ CERT_PATH = path.join(homedir(), 'holodeck-localhost.pem');
31
+ process.env.HOLODECK_SSL_CERT_PATH = CERT_PATH;
32
+ execSync(`echo '\nexport HOLODECK_SSL_CERT_PATH="${CERT_PATH}"' >> ${configFilePath}`);
33
+ console.log(`Added HOLODECK_SSL_CERT_PATH to ${configFilePath}`);
34
+ }
35
+
36
+ if (!KEY_PATH) {
37
+ KEY_PATH = path.join(homedir(), 'holodeck-localhost-key.pem');
38
+ process.env.HOLODECK_SSL_KEY_PATH = KEY_PATH;
39
+ execSync(`echo '\nexport HOLODECK_SSL_KEY_PATH="${KEY_PATH}"' >> ${configFilePath}`);
40
+ console.log(`Added HOLODECK_SSL_KEY_PATH to ${configFilePath}`);
41
+ }
42
+
43
+ console.log(
44
+ `\n*** Please restart your terminal session to apply the changes or run \`source ${configFilePath}\`. ***\n`
45
+ );
46
+ }
47
+
48
+ if (!fs.existsSync(CERT_PATH) || !fs.existsSync(KEY_PATH)) {
49
+ console.log('SSL certificate or key not found, generating new ones...');
50
+
51
+ execSync(`mkcert -install`);
52
+ execSync(`mkcert -key-file ${KEY_PATH} -cert-file ${CERT_PATH} localhost`);
53
+
54
+ console.log('SSL certificate and key generated.');
55
+ } else {
56
+ console.log('SSL certificate and key found, using existing.');
57
+ }
58
+
59
+ console.log(`Certificate path: ${CERT_PATH}`);
60
+ console.log(`Key path: ${KEY_PATH}`);
61
+ }
62
+
63
+ main();
@@ -0,0 +1,383 @@
1
+ /* global Bun */
2
+ import { serve } from '@hono/node-server';
3
+ import chalk from 'chalk';
4
+ import { Hono } from 'hono';
5
+ import { cors } from 'hono/cors';
6
+ import { HTTPException } from 'hono/http-exception';
7
+ import { logger } from 'hono/logger';
8
+ import crypto from 'node:crypto';
9
+ import fs from 'node:fs';
10
+ import http2 from 'node:http2';
11
+ import zlib from 'node:zlib';
12
+ import { homedir } from 'os';
13
+ import path from 'path';
14
+
15
+ /** @type {import('bun-types')} */
16
+ const isBun = typeof Bun !== 'undefined';
17
+ const DEBUG = process.env.DEBUG?.includes('holodeck') || process.env.DEBUG === '*';
18
+ const CURRENT_FILE = new URL(import.meta.url).pathname;
19
+
20
+ function getCertInfo() {
21
+ let CERT_PATH = process.env.HOLODECK_SSL_CERT_PATH;
22
+ let KEY_PATH = process.env.HOLODECK_SSL_KEY_PATH;
23
+
24
+ if (!CERT_PATH) {
25
+ CERT_PATH = path.join(homedir(), 'holodeck-localhost.pem');
26
+ process.env.HOLODECK_SSL_CERT_PATH = CERT_PATH;
27
+
28
+ console.log(
29
+ `HOLODECK_SSL_CERT_PATH was not found in the current environment. Setting it to default value of ${CERT_PATH}`
30
+ );
31
+ }
32
+
33
+ if (!KEY_PATH) {
34
+ KEY_PATH = path.join(homedir(), 'holodeck-localhost-key.pem');
35
+ process.env.HOLODECK_SSL_KEY_PATH = KEY_PATH;
36
+
37
+ console.log(
38
+ `HOLODECK_SSL_KEY_PATH was not found in the current environment. Setting it to default value of ${KEY_PATH}`
39
+ );
40
+ }
41
+
42
+ if (!fs.existsSync(CERT_PATH) || !fs.existsSync(KEY_PATH)) {
43
+ throw new Error('SSL certificate or key not found, you may need to run `pnpx @warp-drive/holodeck ensure-cert`');
44
+ }
45
+
46
+ return {
47
+ CERT_PATH,
48
+ KEY_PATH,
49
+ CERT: fs.readFileSync(CERT_PATH),
50
+ KEY: fs.readFileSync(KEY_PATH),
51
+ };
52
+ }
53
+
54
+ const DEFAULT_PORT = 1135;
55
+ const BROTLI_OPTIONS = {
56
+ params: {
57
+ [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
58
+ // brotli currently defaults to 11 but lets be explicit
59
+ [zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY,
60
+ },
61
+ };
62
+ function compress(code) {
63
+ return zlib.brotliCompressSync(code, BROTLI_OPTIONS);
64
+ }
65
+
66
+ /**
67
+ * removes the protocol, host, and port from a url
68
+ */
69
+ function getNiceUrl(url) {
70
+ const urlObj = new URL(url);
71
+ urlObj.searchParams.delete('__xTestId');
72
+ urlObj.searchParams.delete('__xTestRequestNumber');
73
+ return (urlObj.pathname + urlObj.searchParams.toString()).slice(1);
74
+ }
75
+
76
+ /*
77
+ {
78
+ projectRoot: string;
79
+ testId: string;
80
+ url: string;
81
+ method: string;
82
+ body: string;
83
+ testRequestNumber: number
84
+ }
85
+ */
86
+ function generateFilepath(options) {
87
+ const { body } = options;
88
+ const bodyHash = body ? crypto.createHash('md5').update(body).digest('hex') : null;
89
+ const cacheDir = generateFileDir(options);
90
+ return `${cacheDir}/${bodyHash ? `${bodyHash}-` : 'res'}`;
91
+ }
92
+ function generateFileDir(options) {
93
+ const { projectRoot, testId, url, method, testRequestNumber } = options;
94
+ return `${projectRoot}/.mock-cache/${testId}/${method}-${testRequestNumber}-${url}`;
95
+ }
96
+
97
+ function replayRequest(context, cacheKey) {
98
+ let meta;
99
+ try {
100
+ meta = fs.readFileSync(`${cacheKey}.meta.json`, 'utf-8');
101
+ } catch (e) {
102
+ context.header('Content-Type', 'application/vnd.api+json');
103
+ context.status(400);
104
+ return context.body(
105
+ JSON.stringify({
106
+ errors: [
107
+ {
108
+ status: '400',
109
+ code: 'MOCK_NOT_FOUND',
110
+ title: 'Mock not found',
111
+ detail: `No mock found for ${context.req.method} ${context.req.url}. You may need to record a mock for this request.`,
112
+ },
113
+ ],
114
+ })
115
+ );
116
+ }
117
+
118
+ const metaJson = JSON.parse(meta);
119
+ const bodyPath = `${cacheKey}.body.br`;
120
+
121
+ const headers = new Headers(metaJson.headers || {});
122
+ const bodyInit = metaJson.status !== 204 && metaJson.status < 500 ? fs.createReadStream(bodyPath) : '';
123
+ const response = new Response(bodyInit, {
124
+ status: metaJson.status,
125
+ statusText: metaJson.statusText,
126
+ headers,
127
+ });
128
+
129
+ if (metaJson.status > 400) {
130
+ throw new HTTPException(metaJson.status, { res: response, message: metaJson.statusText });
131
+ }
132
+
133
+ return response;
134
+ }
135
+
136
+ function createTestHandler(projectRoot) {
137
+ const TestHandler = async (context) => {
138
+ try {
139
+ const { req } = context;
140
+
141
+ const testId = req.query('__xTestId');
142
+ const testRequestNumber = req.query('__xTestRequestNumber');
143
+ const niceUrl = getNiceUrl(req.url);
144
+
145
+ if (!testId) {
146
+ context.header('Content-Type', 'application/vnd.api+json');
147
+ context.status(400);
148
+ return context.body(
149
+ JSON.stringify({
150
+ errors: [
151
+ {
152
+ status: '400',
153
+ code: 'MISSING_X_TEST_ID_HEADER',
154
+ title: 'Request to the http mock server is missing the `X-Test-Id` header',
155
+ detail:
156
+ "The `X-Test-Id` header is used to identify the test that is making the request to the mock server. This is used to ensure that the mock server is only used for the test that is currently running. If using @ember-data/request add import { MockServerHandler } from '@warp-drive/holodeck'; to your request handlers.",
157
+ source: { header: 'X-Test-Id' },
158
+ },
159
+ ],
160
+ })
161
+ );
162
+ }
163
+
164
+ if (!testRequestNumber) {
165
+ context.header('Content-Type', 'application/vnd.api+json');
166
+ context.status(400);
167
+ return context.body(
168
+ JSON.stringify({
169
+ errors: [
170
+ {
171
+ status: '400',
172
+ code: 'MISSING_X_TEST_REQUEST_NUMBER_HEADER',
173
+ title: 'Request to the http mock server is missing the `X-Test-Request-Number` header',
174
+ detail:
175
+ "The `X-Test-Request-Number` header is used to identify the request number for the current test. This is used to ensure that the mock server response is deterministic for the test that is currently running. If using @ember-data/request add import { MockServerHandler } from '@warp-drive/holodeck'; to your request handlers.",
176
+ source: { header: 'X-Test-Request-Number' },
177
+ },
178
+ ],
179
+ })
180
+ );
181
+ }
182
+
183
+ if (req.method === 'POST' || niceUrl === '__record') {
184
+ const payload = await req.json();
185
+ const { url, headers, method, status, statusText, body, response } = payload;
186
+ const cacheKey = generateFilepath({
187
+ projectRoot,
188
+ testId,
189
+ url,
190
+ method,
191
+ body: body ? JSON.stringify(body) : null,
192
+ testRequestNumber,
193
+ });
194
+ // allow Content-Type to be overridden
195
+ headers['Content-Type'] = headers['Content-Type'] || 'application/vnd.api+json';
196
+ // We always compress and chunk the response
197
+ headers['Content-Encoding'] = 'br';
198
+ // we don't cache since tests will often reuse similar urls for different payload
199
+ headers['Cache-Control'] = 'no-store';
200
+
201
+ const cacheDir = generateFileDir({
202
+ projectRoot,
203
+ testId,
204
+ url,
205
+ method,
206
+ testRequestNumber,
207
+ });
208
+
209
+ fs.mkdirSync(cacheDir, { recursive: true });
210
+ fs.writeFileSync(
211
+ `${cacheKey}.meta.json`,
212
+ JSON.stringify({ url, status, statusText, headers, method, requestBody: body }, null, 2)
213
+ );
214
+ fs.writeFileSync(`${cacheKey}.body.br`, compress(JSON.stringify(response)));
215
+ context.status(204);
216
+ return context.body(null);
217
+ } else {
218
+ const body = await req.text();
219
+ const cacheKey = generateFilepath({
220
+ projectRoot,
221
+ testId,
222
+ url: niceUrl,
223
+ method: req.method,
224
+ body,
225
+ testRequestNumber,
226
+ });
227
+ return replayRequest(context, cacheKey);
228
+ }
229
+ } catch (e) {
230
+ if (e instanceof HTTPException) {
231
+ throw e;
232
+ }
233
+ context.header('Content-Type', 'application/vnd.api+json');
234
+ context.status(500);
235
+ return context.body(
236
+ JSON.stringify({
237
+ errors: [
238
+ {
239
+ status: '500',
240
+ code: 'MOCK_SERVER_ERROR',
241
+ title: 'Mock Server Error during Request',
242
+ detail: e.message,
243
+ },
244
+ ],
245
+ })
246
+ );
247
+ }
248
+ };
249
+
250
+ return TestHandler;
251
+ }
252
+
253
+ /*
254
+ { port?: number, projectRoot: string }
255
+ */
256
+ export function createServer(options) {
257
+ const app = new Hono();
258
+ if (DEBUG) {
259
+ app.use('*', logger());
260
+ }
261
+ app.use(
262
+ '*',
263
+ cors({
264
+ origin: (origin) =>
265
+ origin.startsWith('http://localhost:') || origin.startsWith('https://localhost:') ? origin : '*',
266
+ allowHeaders: ['Accept', 'Content-Type'],
267
+ allowMethods: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'POST', 'DELETE', 'PATCH'],
268
+ exposeHeaders: ['Content-Length', 'Content-Type'],
269
+ maxAge: 60_000,
270
+ credentials: false,
271
+ })
272
+ );
273
+ app.all('*', createTestHandler(options.projectRoot));
274
+
275
+ const { CERT, KEY } = getCertInfo();
276
+
277
+ serve({
278
+ fetch: app.fetch,
279
+ createServer: (_, requestListener) => {
280
+ try {
281
+ return http2.createSecureServer(
282
+ {
283
+ key: KEY,
284
+ cert: CERT,
285
+ },
286
+ requestListener
287
+ );
288
+ } catch (e) {
289
+ console.log(chalk.yellow(`Failed to create secure server, falling back to http server. Error: ${e.message}`));
290
+ return http2.createServer(requestListener);
291
+ }
292
+ },
293
+ port: options.port ?? DEFAULT_PORT,
294
+ hostname: 'localhost',
295
+ // bun uses TLS options
296
+ // tls: {
297
+ // key: Bun.file(KEY_PATH),
298
+ // cert: Bun.file(CERT_PATH),
299
+ // },
300
+ });
301
+
302
+ console.log(
303
+ `\tMock server running at ${chalk.magenta('https://localhost:') + chalk.yellow(options.port ?? DEFAULT_PORT)}`
304
+ );
305
+ }
306
+
307
+ const servers = new Map();
308
+
309
+ export default {
310
+ async launchProgram(config = {}) {
311
+ const projectRoot = process.cwd();
312
+ const name = await import(path.join(projectRoot, 'package.json'), { with: { type: 'json' } }).then(
313
+ (pkg) => pkg.name
314
+ );
315
+ const options = { name, projectRoot, ...config };
316
+ console.log(
317
+ chalk.grey(
318
+ `\n\t@${chalk.greenBright('warp-drive')}/${chalk.magentaBright(
319
+ 'holodeck'
320
+ )} 🌅\n\t=================================\n`
321
+ ) +
322
+ chalk.grey(
323
+ `\n\tHolodeck Access Granted\n\t\tprogram: ${chalk.magenta(name)}\n\t\tsettings: ${chalk.green(JSON.stringify(config).split('\n').join(' '))}\n\t\tdirectory: ${chalk.cyan(projectRoot)}\n\t\tengine: ${chalk.cyan(
324
+ isBun ? 'bun@' + Bun.version : 'node'
325
+ )}`
326
+ )
327
+ );
328
+ console.log(chalk.grey(`\n\tStarting Subroutines (mode:${chalk.cyan(isBun ? 'bun' : 'node')})`));
329
+
330
+ if (isBun) {
331
+ const serverProcess = Bun.spawn(
332
+ ['node', '--experimental-default-type=module', CURRENT_FILE, JSON.stringify(options)],
333
+ {
334
+ env: process.env,
335
+ cwd: process.cwd(),
336
+ stdout: 'inherit',
337
+ stderr: 'inherit',
338
+ }
339
+ );
340
+ servers.set(projectRoot, serverProcess);
341
+ return;
342
+ }
343
+
344
+ if (servers.has(projectRoot)) {
345
+ throw new Error(`Holodeck is already running for project '${name}' at '${projectRoot}'`);
346
+ }
347
+
348
+ servers.set(projectRoot, createServer(options));
349
+ },
350
+ async endProgram() {
351
+ console.log(chalk.grey(`\n\tEnding Subroutines (mode:${chalk.cyan(isBun ? 'bun' : 'node')})`));
352
+ const projectRoot = process.cwd();
353
+
354
+ if (!servers.has(projectRoot)) {
355
+ const name = await import(path.join(projectRoot, 'package.json'), { with: { type: 'json' } }).then(
356
+ (pkg) => pkg.name
357
+ );
358
+ throw new Error(`Holodeck was not running for project '${name}' at '${projectRoot}'`);
359
+ }
360
+
361
+ if (isBun) {
362
+ const serverProcess = servers.get(projectRoot);
363
+ serverProcess.kill();
364
+ return;
365
+ }
366
+
367
+ servers.get(projectRoot).close();
368
+ servers.delete(projectRoot);
369
+ },
370
+ };
371
+
372
+ function main() {
373
+ const args = process.argv.slice();
374
+ if (!isBun && args.length) {
375
+ if (args[1] !== CURRENT_FILE) {
376
+ return;
377
+ }
378
+ const options = JSON.parse(args[2]);
379
+ createServer(options);
380
+ }
381
+ }
382
+
383
+ main();