fix(actions-core): Added testContext for action testing.

This commit is contained in:
Sandile 2022-02-11 10:58:58 +02:00
parent 25b656f115
commit 2f6189b640
4 changed files with 77 additions and 0 deletions

2
.pnp.cjs generated
View File

@ -2792,7 +2792,9 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
"packageLocation": "./packages/plugins/actions/actions-core/",
"packageDependencies": [
["@lowdefy/actions-core", "workspace:packages/plugins/actions/actions-core"],
["@lowdefy/engine", "workspace:packages/engine"],
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
["@lowdefy/operators", "workspace:packages/operators"],
["@swc/cli", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.1.55"],
["@swc/core", "npm:1.2.135"],
["@swc/jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.17"],

View File

@ -49,6 +49,8 @@
"@lowdefy/helpers": "4.0.0-alpha.6"
},
"devDependencies": {
"@lowdefy/engine": "4.0.0-alpha.6",
"@lowdefy/operators": "4.0.0-alpha.6",
"@swc/cli": "0.1.55",
"@swc/core": "1.2.135",
"@swc/jest": "0.2.17",

View File

@ -0,0 +1,71 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { WebParser } from '@lowdefy/operators';
import { Actions } from '@lowdefy/engine';
import { Blocks } from '@lowdefy/engine';
import { Requests } from '@lowdefy/engine';
import { State } from '@lowdefy/engine';
const testContext = async ({ lowdefy, operators, rootBlock, initState = {} }) => {
const testLowdefy = {
inputs: { test: {} },
urlQuery: {},
...lowdefy,
_internal: {
displayMessage: () => () => undefined,
updateBlock: () => {},
...lowdefy._internal,
},
};
const ctx = {
id: 'test',
pageId: rootBlock.blockId,
eventLog: [],
requests: {},
state: {},
_internal: {
lowdefy: testLowdefy,
rootBlock,
},
};
const _internal = ctx._internal;
_internal.parser = new WebParser({ context: ctx, contexts: {}, operators: operators || {} });
await _internal.parser.init();
_internal.State = new State(ctx);
_internal.Actions = new Actions(ctx);
_internal.Requests = new Requests(ctx);
_internal.RootBlocks = new Blocks({
areas: _internal.rootBlock.areas,
context: ctx,
});
_internal.RootBlocks.init();
_internal.update = () => {
_internal.RootBlocks.update();
};
if (initState) {
Object.keys(initState).forEach((key) => {
_internal.State.set(key, initState[key]);
});
_internal.RootBlocks.reset();
}
_internal.update();
_internal.State.freezeState();
return ctx;
};
export default testContext;

View File

@ -1956,7 +1956,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@lowdefy/actions-core@workspace:packages/plugins/actions/actions-core"
dependencies:
"@lowdefy/engine": 4.0.0-alpha.6
"@lowdefy/helpers": 4.0.0-alpha.6
"@lowdefy/operators": 4.0.0-alpha.6
"@swc/cli": 0.1.55
"@swc/core": 1.2.135
"@swc/jest": 0.2.17