@schmock/core 2.2.3 → 2.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.
Files changed (45) hide show
  1. package/dist/binary.d.ts +8 -0
  2. package/dist/binary.d.ts.map +1 -0
  3. package/dist/binary.js +9 -0
  4. package/dist/builder.d.ts.map +1 -1
  5. package/dist/builder.js +60 -29
  6. package/dist/http-helpers.d.ts +15 -3
  7. package/dist/http-helpers.d.ts.map +1 -1
  8. package/dist/http-helpers.js +24 -6
  9. package/dist/index.d.ts +90 -27
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -0
  12. package/dist/interceptor.d.ts.map +1 -1
  13. package/dist/interceptor.js +71 -20
  14. package/dist/plugin-pipeline.d.ts +11 -4
  15. package/dist/plugin-pipeline.d.ts.map +1 -1
  16. package/dist/plugin-pipeline.js +98 -35
  17. package/dist/response-parser.d.ts.map +1 -1
  18. package/dist/response-parser.js +47 -17
  19. package/package.json +5 -3
  20. package/src/binary.test.ts +126 -0
  21. package/src/binary.ts +11 -0
  22. package/src/builder.ts +82 -35
  23. package/src/http-helpers.test.ts +39 -0
  24. package/src/http-helpers.ts +46 -10
  25. package/src/index.ts +1 -0
  26. package/src/interceptor.test.ts +197 -0
  27. package/src/interceptor.ts +215 -128
  28. package/src/parser.property.test.ts +91 -55
  29. package/src/plugin-pipeline.ts +150 -45
  30. package/src/plugin-system.test.ts +95 -0
  31. package/src/response-parser.ts +58 -19
  32. package/src/server.test.ts +81 -12
  33. package/src/steps/async-support.steps.ts +29 -8
  34. package/src/steps/audit-onerror-tuple.steps.ts +14 -30
  35. package/src/steps/error-handling.steps.ts +463 -253
  36. package/src/steps/fetch-interceptor.steps.ts +457 -0
  37. package/src/steps/http-methods.steps.ts +19 -8
  38. package/src/steps/lifecycle-events.steps.ts +50 -43
  39. package/src/steps/performance-reliability.steps.ts +78 -411
  40. package/src/steps/plugin-integration.steps.ts +54 -0
  41. package/src/steps/request-history.steps.ts +412 -230
  42. package/src/steps/standalone-server.steps.ts +7 -13
  43. package/src/steps/state-concurrency.steps.ts +142 -714
  44. package/src/steps/interceptor.steps.ts +0 -260
  45. package/src/steps/stateful-workflows.steps.ts +0 -353
@@ -7,7 +7,6 @@ const feature = await loadFeature("../../features/audit-onerror-tuple.feature");
7
7
  describeFeature(feature, ({ Scenario }) => {
8
8
  let mock: Schmock.CallableMockInstance;
9
9
  let response: Awaited<ReturnType<Schmock.CallableMockInstance["handle"]>>;
10
- let thrownError: unknown;
11
10
 
12
11
  Scenario(
13
12
  "2-element tuple from onError recovers with correct status and body",
@@ -21,20 +20,13 @@ describeFeature(feature, ({ Scenario }) => {
21
20
  process: (_ctx, _response) => {
22
21
  throw new Error("simulated failure");
23
22
  },
24
- onError: (_error, _ctx) => {
25
- return [503, { error: "recovered" }] as [number, unknown];
26
- },
23
+ onError: () => [503, { error: "recovered" }],
27
24
  });
28
25
  },
29
26
  );
30
27
 
31
28
  When('I handle a request to "GET /fail"', async () => {
32
- thrownError = undefined;
33
- try {
34
- response = await mock.handle("GET", "/fail");
35
- } catch (err) {
36
- thrownError = err;
37
- }
29
+ response = await mock.handle("GET", "/fail");
38
30
  });
39
31
 
40
32
  Then("the response status is 503", () => {
@@ -44,10 +36,6 @@ describeFeature(feature, ({ Scenario }) => {
44
36
  And('the response body is \'{"error":"recovered"}\'', () => {
45
37
  expect(response.body).toEqual({ error: "recovered" });
46
38
  });
47
-
48
- And("no error is thrown", () => {
49
- expect(thrownError).toBeUndefined();
50
- });
51
39
  },
52
40
  );
53
41
 
@@ -63,24 +51,17 @@ describeFeature(feature, ({ Scenario }) => {
63
51
  process: (_ctx, _response) => {
64
52
  throw new Error("simulated failure with headers");
65
53
  },
66
- onError: (_error, _ctx) => {
67
- return [
68
- 503,
69
- { error: "recovered with headers" },
70
- { "x-recovery": "true" },
71
- ] as [number, unknown, Record<string, string>];
72
- },
54
+ onError: () => [
55
+ 503,
56
+ { error: "recovered with headers" },
57
+ { "x-recovery": "true" },
58
+ ],
73
59
  });
74
60
  },
75
61
  );
76
62
 
77
63
  When('I handle a request to "GET /fail-with-headers"', async () => {
78
- thrownError = undefined;
79
- try {
80
- response = await mock.handle("GET", "/fail-with-headers");
81
- } catch (err) {
82
- thrownError = err;
83
- }
64
+ response = await mock.handle("GET", "/fail-with-headers");
84
65
  });
85
66
 
86
67
  Then("the response status is 503", () => {
@@ -91,9 +72,12 @@ describeFeature(feature, ({ Scenario }) => {
91
72
  expect(response.body).toEqual({ error: "recovered with headers" });
92
73
  });
93
74
 
94
- And("no error is thrown", () => {
95
- expect(thrownError).toBeUndefined();
96
- });
75
+ And(
76
+ "the response header {string} is {string}",
77
+ (_, header: string, value: string) => {
78
+ expect(response.headers[header]).toBe(value);
79
+ },
80
+ );
97
81
  },
98
82
  );
99
83
  });