test: Add expression transform tests (#5497) (no-changelog)

test: add expression transform tests
This commit is contained in:
Val
2023-03-14 15:22:52 +00:00
committed by GitHub
parent 332d50c5f1
commit 39c871d514
4 changed files with 278 additions and 69 deletions

View File

@@ -6,15 +6,13 @@ 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';
baseFixtures,
ExpressionTestEvaluation,
ExpressionTestTransform,
} from './ExpressionFixtures/base';
import { INodeExecutionData } from '@/Interfaces';
import { extendSyntax } from '@/Extensions/ExpressionExtension';
describe('Expression', () => {
describe('getParameterValue()', () => {
@@ -186,7 +184,9 @@ describe('Expression', () => {
continue;
}
test(t.expression, () => {
for (const test of t.tests.filter((test) => test.type === 'evaluation')) {
for (const test of t.tests.filter(
(test) => test.type === 'evaluation',
) as ExpressionTestEvaluation[]) {
expect(evaluate(t.expression, test.input.map((d) => ({ json: d })) as any)).toStrictEqual(
test.output,
);
@@ -194,4 +194,20 @@ describe('Expression', () => {
});
}
});
describe('Test all expression transform fixtures', () => {
for (const t of baseFixtures) {
if (!t.tests.some((test) => test.type === 'transform')) {
continue;
}
test(t.expression, () => {
for (const test of t.tests.filter(
(test) => test.type === 'transform',
) as ExpressionTestTransform[]) {
const expr = t.expression;
expect(extendSyntax(expr, test.forceTransform)).toEqual(test.result ?? expr);
}
});
}
});
});