@jterrazz/test 6.1.0 → 6.2.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
@@ -56,7 +56,7 @@ interface ServerResponse {
56
56
  */
57
57
  interface ServerPort {
58
58
  /** Send an HTTP request and return the parsed response. */
59
- request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
59
+ request(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<ServerResponse>;
60
60
  }
61
61
  //#endregion
62
62
  //#region src/builder/directory-accessor.d.ts
@@ -214,6 +214,7 @@ declare class SpecificationBuilder {
214
214
  private mocks;
215
215
  private projectName;
216
216
  private request;
217
+ private requestHeaders;
217
218
  private seeds;
218
219
  private spawnConfig;
219
220
  private testDir;
@@ -244,6 +245,13 @@ declare class SpecificationBuilder {
244
245
  * spec("...").env({ HOME: "$WORKDIR", TZ: "UTC" }).exec("status").run();
245
246
  */
246
247
  env(env: CommandEnv): this;
248
+ /**
249
+ * Set HTTP headers for the request. Multiple calls merge.
250
+ *
251
+ * @example
252
+ * spec("french").headers({ 'Accept-Language': 'fr' }).get("/articles").run();
253
+ */
254
+ headers(headers: Record<string, string>): this;
247
255
  /**
248
256
  * Send a GET request to the server adapter.
249
257
  *
@@ -440,8 +448,8 @@ declare class Orchestrator {
440
448
  }
441
449
  //#endregion
442
450
  //#region src/runner/targets.d.ts
451
+ /** Any object with a request method compatible with Hono's app.request(). */
443
452
  type HonoApp$1 = {
444
- fetch: (...args: any[]) => any;
445
453
  request: (path: string, init?: RequestInit) => Promise<Response> | Response;
446
454
  };
447
455
  /** Services map passed to the app factory after infrastructure starts. */
@@ -582,7 +590,7 @@ declare class ExecAdapter implements CommandPort {
582
590
  declare class FetchAdapter implements ServerPort {
583
591
  private baseUrl;
584
592
  constructor(url: string);
585
- request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
593
+ request(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<ServerResponse>;
586
594
  }
587
595
  //#endregion
588
596
  //#region src/adapters/hono.adapter.d.ts
@@ -595,7 +603,7 @@ declare class HonoAdapter implements ServerPort {
595
603
  constructor(app: {
596
604
  request: (path: string, init?: RequestInit) => Promise<Response> | Response;
597
605
  });
598
- request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
606
+ request(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<ServerResponse>;
599
607
  }
600
608
  //#endregion
601
609
  //#region src/runner/integration.d.ts
package/dist/index.d.ts CHANGED
@@ -56,7 +56,7 @@ interface ServerResponse {
56
56
  */
57
57
  interface ServerPort {
58
58
  /** Send an HTTP request and return the parsed response. */
59
- request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
59
+ request(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<ServerResponse>;
60
60
  }
61
61
  //#endregion
62
62
  //#region src/builder/directory-accessor.d.ts
@@ -214,6 +214,7 @@ declare class SpecificationBuilder {
214
214
  private mocks;
215
215
  private projectName;
216
216
  private request;
217
+ private requestHeaders;
217
218
  private seeds;
218
219
  private spawnConfig;
219
220
  private testDir;
@@ -244,6 +245,13 @@ declare class SpecificationBuilder {
244
245
  * spec("...").env({ HOME: "$WORKDIR", TZ: "UTC" }).exec("status").run();
245
246
  */
246
247
  env(env: CommandEnv): this;
248
+ /**
249
+ * Set HTTP headers for the request. Multiple calls merge.
250
+ *
251
+ * @example
252
+ * spec("french").headers({ 'Accept-Language': 'fr' }).get("/articles").run();
253
+ */
254
+ headers(headers: Record<string, string>): this;
247
255
  /**
248
256
  * Send a GET request to the server adapter.
249
257
  *
@@ -440,8 +448,8 @@ declare class Orchestrator {
440
448
  }
441
449
  //#endregion
442
450
  //#region src/runner/targets.d.ts
451
+ /** Any object with a request method compatible with Hono's app.request(). */
443
452
  type HonoApp$1 = {
444
- fetch: (...args: any[]) => any;
445
453
  request: (path: string, init?: RequestInit) => Promise<Response> | Response;
446
454
  };
447
455
  /** Services map passed to the app factory after infrastructure starts. */
@@ -582,7 +590,7 @@ declare class ExecAdapter implements CommandPort {
582
590
  declare class FetchAdapter implements ServerPort {
583
591
  private baseUrl;
584
592
  constructor(url: string);
585
- request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
593
+ request(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<ServerResponse>;
586
594
  }
587
595
  //#endregion
588
596
  //#region src/adapters/hono.adapter.d.ts
@@ -595,7 +603,7 @@ declare class HonoAdapter implements ServerPort {
595
603
  constructor(app: {
596
604
  request: (path: string, init?: RequestInit) => Promise<Response> | Response;
597
605
  });
598
- request(method: string, path: string, body?: unknown): Promise<ServerResponse>;
606
+ request(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<ServerResponse>;
599
607
  }
600
608
  //#endregion
601
609
  //#region src/runner/integration.d.ts
package/dist/index.js CHANGED
@@ -113,22 +113,25 @@ var FetchAdapter = class {
113
113
  constructor(url) {
114
114
  this.baseUrl = url.replace(/\/$/, "");
115
115
  }
116
- async request(method, path, body) {
116
+ async request(method, path, body, headers) {
117
117
  const init = {
118
118
  method,
119
- headers: { "Content-Type": "application/json" }
119
+ headers: {
120
+ "Content-Type": "application/json",
121
+ ...headers
122
+ }
120
123
  };
121
124
  if (body !== void 0) init.body = JSON.stringify(body);
122
125
  const response = await fetch(`${this.baseUrl}${path}`, init);
123
126
  const responseBody = await response.json().catch(() => null);
124
- const headers = {};
127
+ const responseHeaders = {};
125
128
  response.headers.forEach((value, key) => {
126
- headers[key] = value;
129
+ responseHeaders[key] = value;
127
130
  });
128
131
  return {
129
132
  status: response.status,
130
133
  body: responseBody,
131
- headers
134
+ headers: responseHeaders
132
135
  };
133
136
  }
134
137
  };
@@ -143,22 +146,25 @@ var HonoAdapter = class {
143
146
  constructor(app) {
144
147
  this.app = app;
145
148
  }
146
- async request(method, path, body) {
149
+ async request(method, path, body, headers) {
147
150
  const init = {
148
151
  method,
149
- headers: { "Content-Type": "application/json" }
152
+ headers: {
153
+ "Content-Type": "application/json",
154
+ ...headers
155
+ }
150
156
  };
151
157
  if (body !== void 0) init.body = JSON.stringify(body);
152
158
  const response = await this.app.request(path, init);
153
159
  const responseBody = await response.json().catch(() => null);
154
- const headers = {};
160
+ const responseHeaders = {};
155
161
  response.headers.forEach((value, key) => {
156
- headers[key] = value;
162
+ responseHeaders[key] = value;
157
163
  });
158
164
  return {
159
165
  status: response.status,
160
166
  body: responseBody,
161
- headers
167
+ headers: responseHeaders
162
168
  };
163
169
  }
164
170
  };
@@ -588,6 +594,7 @@ var SpecificationBuilder = class {
588
594
  mocks = [];
589
595
  projectName = null;
590
596
  request = null;
597
+ requestHeaders = {};
591
598
  seeds = [];
592
599
  spawnConfig = null;
593
600
  testDir;
@@ -642,6 +649,19 @@ var SpecificationBuilder = class {
642
649
  return this;
643
650
  }
644
651
  /**
652
+ * Set HTTP headers for the request. Multiple calls merge.
653
+ *
654
+ * @example
655
+ * spec("french").headers({ 'Accept-Language': 'fr' }).get("/articles").run();
656
+ */
657
+ headers(headers) {
658
+ this.requestHeaders = {
659
+ ...this.requestHeaders,
660
+ ...headers
661
+ };
662
+ return this;
663
+ }
664
+ /**
645
665
  * Send a GET request to the server adapter.
646
666
  *
647
667
  * @example
@@ -762,7 +782,8 @@ var SpecificationBuilder = class {
762
782
  if (!this.config.server) throw new Error("HTTP actions require a server adapter (use integration() or e2e())");
763
783
  let body;
764
784
  if (this.request.bodyFile) body = JSON.parse(readFileSync(resolve(this.testDir, "requests", this.request.bodyFile), "utf8"));
765
- const response = await this.config.server.request(this.request.method, this.request.path, body);
785
+ const headers = Object.keys(this.requestHeaders).length > 0 ? this.requestHeaders : void 0;
786
+ const response = await this.config.server.request(this.request.method, this.request.path, body, headers);
766
787
  return new SpecificationResult({
767
788
  config: this.config,
768
789
  requestInfo: {