@jterrazz/test 6.5.0 → 7.0.0
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/dist/index.cjs +21 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/intercept.cjs +107 -104
- package/dist/intercept.cjs.map +1 -1
- package/dist/intercept.d.cts +26 -42
- package/dist/intercept.d.ts +26 -42
- package/dist/intercept.js +107 -104
- package/dist/intercept.js.map +1 -1
- package/dist/types.d.cts +7 -1
- package/dist/types.d.ts +7 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -670,18 +670,31 @@ var SpecificationBuilder = class {
|
|
|
670
670
|
* Uses MSW under the hood. Intercepts are queued — multiple calls with the
|
|
671
671
|
* same trigger fire sequentially (first match consumed first).
|
|
672
672
|
*
|
|
673
|
-
* @param trigger - What to match (use openai.
|
|
674
|
-
* @param response - What to return
|
|
673
|
+
* @param trigger - What to match (use openai.agent(), http.get(), etc.)
|
|
674
|
+
* @param response - What to return: an InterceptResponse object, or a filename
|
|
675
|
+
* from `intercepts/` (JSON loaded and auto-wrapped by the trigger).
|
|
675
676
|
*
|
|
676
677
|
* @example
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
678
|
+
* // With inline response
|
|
679
|
+
* .intercept(openai.agent({...}), openai.reply({ categories: ['TECH'] }))
|
|
680
|
+
*
|
|
681
|
+
* // With JSON fixture file (loaded from intercepts/ directory)
|
|
682
|
+
* .intercept(openai.agent({...}), 'ingest-tech.json')
|
|
683
|
+
* .intercept(http.get(url), 'world-news-tech.json')
|
|
682
684
|
*/
|
|
683
685
|
intercept(trigger, response) {
|
|
684
|
-
|
|
686
|
+
if (typeof response === "string") {
|
|
687
|
+
const filePath = (0, node_path.resolve)(this.testDir, "intercepts", response);
|
|
688
|
+
const data = JSON.parse((0, node_fs.readFileSync)(filePath, "utf8"));
|
|
689
|
+
const resolved = trigger.wrap ? trigger.wrap(data) : {
|
|
690
|
+
status: 200,
|
|
691
|
+
body: data
|
|
692
|
+
};
|
|
693
|
+
this.intercepts.push({
|
|
694
|
+
trigger,
|
|
695
|
+
response: resolved
|
|
696
|
+
});
|
|
697
|
+
} else this.intercepts.push({
|
|
685
698
|
trigger,
|
|
686
699
|
response
|
|
687
700
|
});
|