@teamkeel/testing-runtime 0.474.0 → 0.475.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamkeel/testing-runtime",
3
- "version": "0.474.0",
3
+ "version": "0.475.0",
4
4
  "description": "Internal package used by the generated @teamkeel/testing package",
5
5
  "exports": "./src/index.mjs",
6
6
  "typings": "src/index.d.ts",
package/src/Executor.mjs CHANGED
@@ -20,6 +20,15 @@ export class Executor {
20
20
  if (v !== undefined) {
21
21
  return v;
22
22
  }
23
+ // An executor must not look like a promise. Handing back a function for `then` makes
24
+ // `await executor` treat it as a thenable and dispatch an action called "then", which
25
+ // 404s and never settles the await. Symbols are never action names either.
26
+ // An executor must not look like a promise. Handing back a function for `then` makes
27
+ // `await executor` treat it as a thenable and dispatch an action called "then", which
28
+ // 404s and never settles the await. Symbols are never action names either.
29
+ if (prop === "then" || typeof prop === "symbol") {
30
+ return undefined;
31
+ }
23
32
  return target._execute.bind(target, prop);
24
33
  },
25
34
  });
package/src/index.test.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { expect, test } from "vitest";
2
2
  import "./index";
3
+ import { Executor } from "./Executor.mjs";
3
4
 
4
5
  test("toHaveAuthorizationError", async () => {
5
6
  const p = Promise.reject({
@@ -70,3 +71,31 @@ test("not.toHaveError", async () => {
70
71
  code: "ERR_INVALID_INPUT",
71
72
  });
72
73
  });
74
+
75
+ // An executor answers to any property with an action call, so it must explicitly refuse the ones
76
+ // the language itself reaches for. Answering `then` with a function makes `await executor` treat
77
+ // it as a thenable: it dispatches an action called "then" and never settles.
78
+ test("an executor is not a thenable", async () => {
79
+ const executor = new Executor({
80
+ apiBaseUrl: "http://localhost",
81
+ parseJsonResult: false,
82
+ });
83
+
84
+ expect(executor.then).toBeUndefined();
85
+
86
+ const resolved = await Promise.resolve(executor);
87
+ expect(resolved).toBe(executor);
88
+
89
+ const returned = await (async () => executor)();
90
+ expect(returned).toBe(executor);
91
+ });
92
+
93
+ test("an executor does not answer to symbols", () => {
94
+ const executor = new Executor({
95
+ apiBaseUrl: "http://localhost",
96
+ parseJsonResult: false,
97
+ });
98
+
99
+ expect(executor[Symbol.toPrimitive]).toBeUndefined();
100
+ expect(executor[Symbol.iterator]).toBeUndefined();
101
+ });