@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.d.cts CHANGED
@@ -266,17 +266,19 @@ declare class SpecificationBuilder {
266
266
  * Uses MSW under the hood. Intercepts are queued — multiple calls with the
267
267
  * same trigger fire sequentially (first match consumed first).
268
268
  *
269
- * @param trigger - What to match (use openai.chat(), anthropic.messages(), http.get(), etc.)
270
- * @param response - What to return (use openai.response(), http.json(), etc.)
269
+ * @param trigger - What to match (use openai.agent(), http.get(), etc.)
270
+ * @param response - What to return: an InterceptResponse object, or a filename
271
+ * from `intercepts/` (JSON loaded and auto-wrapped by the trigger).
271
272
  *
272
273
  * @example
273
- * spec('pipeline')
274
- * .intercept(openai.chat(), openai.response({ categories: ['TECH'] }))
275
- * .intercept(openai.chat(), openai.response({ headline: 'AI News' }))
276
- * .exec('process')
277
- * .run();
274
+ * // With inline response
275
+ * .intercept(openai.agent({...}), openai.reply({ categories: ['TECH'] }))
276
+ *
277
+ * // With JSON fixture file (loaded from intercepts/ directory)
278
+ * .intercept(openai.agent({...}), 'ingest-tech.json')
279
+ * .intercept(http.get(url), 'world-news-tech.json')
278
280
  */
279
- intercept(trigger: InterceptTrigger, response: InterceptResponse): this;
281
+ intercept(trigger: InterceptTrigger, response: InterceptResponse | string): this;
280
282
  /**
281
283
  * Send a GET request to the server adapter.
282
284
  *
package/dist/index.d.ts CHANGED
@@ -266,17 +266,19 @@ declare class SpecificationBuilder {
266
266
  * Uses MSW under the hood. Intercepts are queued — multiple calls with the
267
267
  * same trigger fire sequentially (first match consumed first).
268
268
  *
269
- * @param trigger - What to match (use openai.chat(), anthropic.messages(), http.get(), etc.)
270
- * @param response - What to return (use openai.response(), http.json(), etc.)
269
+ * @param trigger - What to match (use openai.agent(), http.get(), etc.)
270
+ * @param response - What to return: an InterceptResponse object, or a filename
271
+ * from `intercepts/` (JSON loaded and auto-wrapped by the trigger).
271
272
  *
272
273
  * @example
273
- * spec('pipeline')
274
- * .intercept(openai.chat(), openai.response({ categories: ['TECH'] }))
275
- * .intercept(openai.chat(), openai.response({ headline: 'AI News' }))
276
- * .exec('process')
277
- * .run();
274
+ * // With inline response
275
+ * .intercept(openai.agent({...}), openai.reply({ categories: ['TECH'] }))
276
+ *
277
+ * // With JSON fixture file (loaded from intercepts/ directory)
278
+ * .intercept(openai.agent({...}), 'ingest-tech.json')
279
+ * .intercept(http.get(url), 'world-news-tech.json')
278
280
  */
279
- intercept(trigger: InterceptTrigger, response: InterceptResponse): this;
281
+ intercept(trigger: InterceptTrigger, response: InterceptResponse | string): this;
280
282
  /**
281
283
  * Send a GET request to the server adapter.
282
284
  *
package/dist/index.js CHANGED
@@ -668,18 +668,32 @@ var SpecificationBuilder = class {
668
668
  * Uses MSW under the hood. Intercepts are queued — multiple calls with the
669
669
  * same trigger fire sequentially (first match consumed first).
670
670
  *
671
- * @param trigger - What to match (use openai.chat(), anthropic.messages(), http.get(), etc.)
672
- * @param response - What to return (use openai.response(), http.json(), etc.)
671
+ * @param trigger - What to match (use openai.agent(), http.get(), etc.)
672
+ * @param response - What to return: an InterceptResponse object, or a filename
673
+ * from `intercepts/` (JSON loaded and auto-wrapped by the trigger).
673
674
  *
674
675
  * @example
675
- * spec('pipeline')
676
- * .intercept(openai.chat(), openai.response({ categories: ['TECH'] }))
677
- * .intercept(openai.chat(), openai.response({ headline: 'AI News' }))
678
- * .exec('process')
679
- * .run();
676
+ * // With inline response
677
+ * .intercept(openai.agent({...}), openai.reply({ categories: ['TECH'] }))
678
+ *
679
+ * // With JSON fixture file (loaded from intercepts/ directory)
680
+ * .intercept(openai.agent({...}), 'ingest-tech.json')
681
+ * .intercept(http.get(url), 'world-news-tech.json')
680
682
  */
681
683
  intercept(trigger, response) {
682
- this.intercepts.push({
684
+ if (typeof response === "string") {
685
+ const slashIndex = response.indexOf("/");
686
+ if (slashIndex === -1) throw new Error(`.intercept(): file path must be 'adapter/filename.json' (e.g. 'openai/ingest-tech.json'), got '${response}'`);
687
+ const adapterName = response.slice(0, slashIndex);
688
+ if (adapterName !== trigger.adapter) throw new Error(`.intercept(): adapter mismatch - trigger uses '${trigger.adapter}' but file path starts with '${adapterName}/'`);
689
+ const filePath = resolve(this.testDir, "intercepts", response);
690
+ const data = JSON.parse(readFileSync(filePath, "utf8"));
691
+ const resolved = trigger.wrap(data);
692
+ this.intercepts.push({
693
+ trigger,
694
+ response: resolved
695
+ });
696
+ } else this.intercepts.push({
683
697
  trigger,
684
698
  response
685
699
  });