@jterrazz/test 6.5.1 → 7.1.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 +22 -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 +22 -8
- package/dist/index.js.map +1 -1
- package/dist/intercept.cjs +143 -129
- package/dist/intercept.cjs.map +1 -1
- package/dist/intercept.d.cts +39 -53
- package/dist/intercept.d.ts +39 -53
- package/dist/intercept.js +143 -129
- package/dist/intercept.js.map +1 -1
- package/dist/types.d.cts +8 -1
- package/dist/types.d.ts +8 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -670,18 +670,32 @@ 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 slashIndex = response.indexOf("/");
|
|
688
|
+
if (slashIndex === -1) throw new Error(`.intercept(): file path must be 'adapter/filename.json' (e.g. 'openai/ingest-tech.json'), got '${response}'`);
|
|
689
|
+
const adapterName = response.slice(0, slashIndex);
|
|
690
|
+
if (adapterName !== trigger.adapter) throw new Error(`.intercept(): adapter mismatch - trigger uses '${trigger.adapter}' but file path starts with '${adapterName}/'`);
|
|
691
|
+
const filePath = (0, node_path.resolve)(this.testDir, "intercepts", response);
|
|
692
|
+
const data = JSON.parse((0, node_fs.readFileSync)(filePath, "utf8"));
|
|
693
|
+
const resolved = trigger.wrap(data);
|
|
694
|
+
this.intercepts.push({
|
|
695
|
+
trigger,
|
|
696
|
+
response: resolved
|
|
697
|
+
});
|
|
698
|
+
} else this.intercepts.push({
|
|
685
699
|
trigger,
|
|
686
700
|
response
|
|
687
701
|
});
|