@prismatic-io/spectral 10.3.2 → 10.3.3
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/testing.d.ts +20 -3
- package/dist/testing.js +28 -1
- package/package.json +1 -1
package/dist/testing.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* information on unit testing, check out our docs:
|
|
5
5
|
* https://prismatic.io/docs/custom-components/writing-custom-components/#testing-a-component
|
|
6
6
|
*/
|
|
7
|
-
import { TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component,
|
|
8
|
-
import { ActionContext, ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceType, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection } from "./types";
|
|
7
|
+
import { ActionPerformReturn as ServerActionPerformReturn, TriggerPayload, TriggerResult, ConnectionValue, ActionLogger, Component, DataSourceResult, DataSourceContext } from "./serverTypes";
|
|
8
|
+
import { ActionContext, ConnectionDefinition, ActionDefinition, TriggerDefinition, Inputs, ActionInputParameters, DataSourceDefinition, ActionPerformReturn as InvokeActionPerformReturn, TriggerResult as InvokeTriggerResult, DataSourceType, DataSourceResult as InvokeDataSourceResult, TriggerEventFunctionReturn, Flow, ConfigVarResultCollection, ComponentManifest } from "./types";
|
|
9
9
|
export declare const createConnection: <T extends ConnectionDefinition>({ key }: T, values: Record<string, unknown>, tokenValues?: Record<string, unknown>) => ConnectionValue;
|
|
10
10
|
export declare const defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
|
|
11
11
|
export declare const connectionValue: (envVarKey?: string) => ConnectionValue;
|
|
@@ -14,6 +14,23 @@ export declare const connectionValue: (envVarKey?: string) => ConnectionValue;
|
|
|
14
14
|
* See https://prismatic.io/docs/custom-components/writing-custom-components/#verifying-correct-logging-in-action-tests for information on testing correct logging behavior in your custom component.
|
|
15
15
|
*/
|
|
16
16
|
export declare const loggerMock: () => ActionLogger;
|
|
17
|
+
/**
|
|
18
|
+
* Creates basic component mocks based on the CNI's component registry.
|
|
19
|
+
* You may pass mock overrides in the second argument, e.g.:
|
|
20
|
+
*
|
|
21
|
+
* createMockContextComponents(myManifest, {
|
|
22
|
+
* actions: {
|
|
23
|
+
* myComponentName: {
|
|
24
|
+
* myComponentAction: () => Promise.resolve({ data: "my test data "}),
|
|
25
|
+
* }
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
export declare const createMockContextComponents: <TMockAction extends () => Promise<any>>(registry: Record<string, {
|
|
30
|
+
actions: ComponentManifest["actions"];
|
|
31
|
+
}>, mocks?: {
|
|
32
|
+
actions: Record<string, Record<string, TMockAction>>;
|
|
33
|
+
}) => Record<string, Record<string, TMockAction>>;
|
|
17
34
|
/**
|
|
18
35
|
* The type of data returned by an `invoke()` function used for unit testing component actions and triggers.
|
|
19
36
|
*/
|
|
@@ -64,7 +81,7 @@ export declare class ComponentTestHarness<TComponent extends Component> {
|
|
|
64
81
|
trigger<TConfigVars extends ConfigVarResultCollection>(key: string, payload?: TriggerPayload, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<TriggerResult>;
|
|
65
82
|
triggerOnInstanceDeploy<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<TriggerEventFunctionReturn | void>;
|
|
66
83
|
triggerOnInstanceDelete<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<TriggerEventFunctionReturn | void>;
|
|
67
|
-
action<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<
|
|
84
|
+
action<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<ActionContext<TConfigVars>>): Promise<ServerActionPerformReturn>;
|
|
68
85
|
dataSource<TConfigVars extends ConfigVarResultCollection>(key: string, params?: Record<string, unknown>, context?: Partial<DataSourceContext<TConfigVars>>): Promise<DataSourceResult>;
|
|
69
86
|
}
|
|
70
87
|
export declare const createHarness: <TComponent extends Component>(component: TComponent) => ComponentTestHarness<TComponent>;
|
package/dist/testing.js
CHANGED
|
@@ -15,7 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.createHarness = exports.ComponentTestHarness = exports.invokeFlow = exports.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.loggerMock = exports.connectionValue = exports.defaultConnectionValueEnvironmentVariable = exports.createConnection = void 0;
|
|
18
|
+
exports.createHarness = exports.ComponentTestHarness = exports.invokeFlow = exports.invokeDataSource = exports.invokeTrigger = exports.defaultTriggerPayload = exports.invoke = exports.createMockContextComponents = exports.loggerMock = exports.connectionValue = exports.defaultConnectionValueEnvironmentVariable = exports.createConnection = void 0;
|
|
19
19
|
const jest_mock_1 = require("jest-mock");
|
|
20
20
|
const createConnection = ({ key }, values, tokenValues) => ({
|
|
21
21
|
configVarKey: "",
|
|
@@ -53,6 +53,33 @@ function invokeFlowTest(flowName, data, config) {
|
|
|
53
53
|
return Promise.resolve({});
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates basic component mocks based on the CNI's component registry.
|
|
58
|
+
* You may pass mock overrides in the second argument, e.g.:
|
|
59
|
+
*
|
|
60
|
+
* createMockContextComponents(myManifest, {
|
|
61
|
+
* actions: {
|
|
62
|
+
* myComponentName: {
|
|
63
|
+
* myComponentAction: () => Promise.resolve({ data: "my test data "}),
|
|
64
|
+
* }
|
|
65
|
+
* },
|
|
66
|
+
* });
|
|
67
|
+
*/
|
|
68
|
+
const createMockContextComponents = (registry, mocks = { actions: {} }) => {
|
|
69
|
+
const components = Object.keys(registry).reduce((accum, componentKey) => {
|
|
70
|
+
var _a;
|
|
71
|
+
const mockActions = Object.keys(registry[componentKey].actions).reduce((actionAccum, actionKey) => {
|
|
72
|
+
actionAccum[actionKey] = (() => {
|
|
73
|
+
return Promise.resolve({ data: null });
|
|
74
|
+
});
|
|
75
|
+
return actionAccum;
|
|
76
|
+
}, {});
|
|
77
|
+
accum[componentKey] = Object.assign(Object.assign({}, mockActions), ((_a = mocks.actions[componentKey]) !== null && _a !== void 0 ? _a : {}));
|
|
78
|
+
return accum;
|
|
79
|
+
}, {});
|
|
80
|
+
return components;
|
|
81
|
+
};
|
|
82
|
+
exports.createMockContextComponents = createMockContextComponents;
|
|
56
83
|
const createActionContext = (context) => {
|
|
57
84
|
return Object.assign({ logger: (0, exports.loggerMock)(), instanceState: {}, crossFlowState: {}, executionState: {}, integrationState: {}, configVars: {}, components: {}, stepId: "mockStepId", executionId: "mockExecutionId", webhookUrls: {
|
|
58
85
|
"Flow 1": "https://example.com",
|