test(core): Add basic expression tests (no-changelog) (#5439)

* test(core): add basic expression tests

* test: fix $if test not working properly
This commit is contained in:
Valya
2023-02-10 09:05:34 +00:00
committed by GitHub
parent 5b1e3a3fd3
commit 287fa9cd06
4 changed files with 725 additions and 8 deletions

View File

@@ -6,6 +6,15 @@ import { DateTime, Duration, Interval } from 'luxon';
import { Expression } from '@/Expression';
import { Workflow } from '@/Workflow';
import * as Helpers from './Helpers';
import { baseFixtures } from './ExpressionFixtures/base';
import {
IConnections,
IExecuteData,
INode,
INodeExecutionData,
IRunExecutionData,
ITaskData,
} from '@/Interfaces';
describe('Expression', () => {
describe('getParameterValue()', () => {
@@ -147,4 +156,42 @@ describe('Expression', () => {
expect(evaluate('={{Symbol(1).toString()}}')).toEqual(Symbol(1).toString());
});
});
describe('Test all expression value fixtures', () => {
const nodeTypes = Helpers.NodeTypes();
const workflow = new Workflow({
nodes: [
{
name: 'node',
typeVersion: 1,
type: 'test.set',
id: 'uuid-1234',
position: [0, 0],
parameters: {},
},
],
connections: {},
active: false,
nodeTypes,
});
const expression = new Expression(workflow);
const evaluate = (value: string, data: INodeExecutionData[]) => {
return expression.getParameterValue(value, null, 0, 0, 'node', data, 'manual', '', {});
};
for (const t of baseFixtures) {
if (!t.tests.some((test) => test.type === 'evaluation')) {
continue;
}
test(t.expression, () => {
for (const test of t.tests.filter((test) => test.type === 'evaluation')) {
expect(evaluate(t.expression, test.input.map((d) => ({ json: d })) as any)).toStrictEqual(
test.output,
);
}
});
}
});
});