primitive-functions 0.3.0-alpha.18 → 0.3.0-alpha.19
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/README.md +32 -3
- package/index.d.ts +467 -69
- package/package.json +10 -2
- package/testing-members.generated.js +502 -0
- package/testing.d.ts +239 -0
- package/testing.js +142 -0
package/README.md
CHANGED
|
@@ -19,6 +19,35 @@ The `latest` release's types leave out experimental `ctx.api` methods, which
|
|
|
19
19
|
production does not serve; the `alpha` release (`primitive-functions@alpha`)
|
|
20
20
|
has them.
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
Calling anything in the main entry outside a Primitive sandbox throws.
|
|
23
|
+
|
|
24
|
+
## Unit-testing a handler
|
|
25
|
+
|
|
26
|
+
`primitive-functions/testing` builds a `ctx` and a `step` for a unit test that
|
|
27
|
+
runs a handler's logic under Node. Install the package as a dev dependency and
|
|
28
|
+
override only the members the handler uses:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createTestContext, createTestStep } from "primitive-functions/testing";
|
|
32
|
+
|
|
33
|
+
const ctx = createTestContext({
|
|
34
|
+
runId: "run-1",
|
|
35
|
+
configVar: async () => "doc-1",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await archiveOrder({ orderId: "o1" }, ctx, createTestStep());
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The overrides are typed from `FunctionContext` and `FunctionStep`, so an
|
|
42
|
+
override that no longer matches its member fails the typecheck. A member the
|
|
43
|
+
test did not provide throws an `Error` named `TEST_MEMBER_NOT_PROVIDED`, whose
|
|
44
|
+
`member` is its path; `step.do` runs its body. A namespace override (`users`,
|
|
45
|
+
`api.groups`) is a plain object of the methods the test provides.
|
|
46
|
+
|
|
47
|
+
Keep the handler's logic in a module of its own that the function's entry
|
|
48
|
+
imports and passes to `defineFunction`, and import that module in the test.
|
|
49
|
+
Importing the entry runs its `defineFunction` call, which throws outside the
|
|
50
|
+
platform.
|
|
51
|
+
|
|
52
|
+
The module is for tests only: `primitive config push` refuses a function whose
|
|
53
|
+
bundle imports it.
|