@jterrazz/test 6.5.1 → 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 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.chat(), anthropic.messages(), http.get(), etc.)
674
- * @param response - What to return (use openai.response(), http.json(), etc.)
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
- * spec('pipeline')
678
- * .intercept(openai.chat(), openai.response({ categories: ['TECH'] }))
679
- * .intercept(openai.chat(), openai.response({ headline: 'AI News' }))
680
- * .exec('process')
681
- * .run();
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
- this.intercepts.push({
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
  });