@jterrazz/test 6.2.0 → 6.3.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
@@ -592,6 +592,7 @@ var SpecificationBuilder = class {
592
592
  commandEnv = {};
593
593
  config;
594
594
  fixtures = [];
595
+ intercepts = [];
595
596
  label;
596
597
  mocks = [];
597
598
  projectName = null;
@@ -664,6 +665,28 @@ var SpecificationBuilder = class {
664
665
  return this;
665
666
  }
666
667
  /**
668
+ * Intercept an outgoing HTTP request and return a controlled response.
669
+ * Uses MSW under the hood. Intercepts are queued — multiple calls with the
670
+ * same trigger fire sequentially (first match consumed first).
671
+ *
672
+ * @param trigger - What to match (use openai.chat(), anthropic.messages(), http.get(), etc.)
673
+ * @param response - What to return (use openai.response(), http.json(), etc.)
674
+ *
675
+ * @example
676
+ * spec('pipeline')
677
+ * .intercept(openai.chat(), openai.response({ categories: ['TECH'] }))
678
+ * .intercept(openai.chat(), openai.response({ headline: 'AI News' }))
679
+ * .exec('process')
680
+ * .run();
681
+ */
682
+ intercept(trigger, response) {
683
+ this.intercepts.push({
684
+ trigger,
685
+ response
686
+ });
687
+ return this;
688
+ }
689
+ /**
667
690
  * Send a GET request to the server adapter.
668
691
  *
669
692
  * @example
@@ -757,9 +780,17 @@ var SpecificationBuilder = class {
757
780
  await db.seed(sql);
758
781
  }
759
782
  if (this.fixtures.length > 0 && workDir) for (const entry of this.fixtures) (0, node_fs.cpSync)((0, node_path.resolve)(this.testDir, "fixtures", entry.file), (0, node_path.resolve)(workDir, entry.file), { recursive: true });
760
- for (const entry of this.mocks) JSON.parse((0, node_fs.readFileSync)((0, node_path.resolve)(this.testDir, "mock", entry.file), "utf8"));
761
- if (hasHttpAction) return this.runHttpAction();
762
- return this.runCliAction(workDir);
783
+ let cleanupIntercepts = null;
784
+ if (this.intercepts.length > 0) {
785
+ const { registerIntercepts } = await Promise.resolve().then(() => require("./server.cjs"));
786
+ cleanupIntercepts = await registerIntercepts(this.intercepts);
787
+ }
788
+ try {
789
+ if (hasHttpAction) return await this.runHttpAction();
790
+ return await this.runCliAction(workDir);
791
+ } finally {
792
+ if (cleanupIntercepts) cleanupIntercepts();
793
+ }
763
794
  }
764
795
  resolveEnv(workDir) {
765
796
  const keys = Object.keys(this.commandEnv);