ci: Expand ESLint to tests in BE packages (no-changelog) (#6147)

* 🔧 Adjust base ESLint config

* 🔧 Adjust `lint` and `lintfix` in `nodes-base`

* 🔧 Include `test` and `utils` in `nodes-base`

* 📘 Convert JS tests to TS

* 👕 Apply lintfixes
This commit is contained in:
Iván Ovejero
2023-05-02 10:37:19 +02:00
committed by GitHub
parent c63181b317
commit 06fa6f1fb3
59 changed files with 390 additions and 307 deletions

View File

@@ -25,9 +25,7 @@ describe('Data Transformation Functions', () => {
{ value: 6, string: '6' },
{ value: { something: 'else' } }
].pluck("value") }}`),
).toEqual(
expect.arrayContaining([1, 2, 3, 4, 5, 6, { something: 'else' }]),
);
).toEqual(expect.arrayContaining([1, 2, 3, 4, 5, 6, { something: 'else' }]));
});
test('.pluck() should work correctly for multiple values', () => {
@@ -50,7 +48,10 @@ describe('Data Transformation Functions', () => {
}
].pluck("firstName", "lastName") }}`),
).toEqual(
expect.arrayContaining([["John", "Doe"],["Jane", "Doe"]]),
expect.arrayContaining([
['John', 'Doe'],
['Jane', 'Doe'],
]),
);
});
@@ -73,7 +74,7 @@ describe('Data Transformation Functions', () => {
{ value: 4, string: '4' },
{ value: 5, string: '5' },
{ value: 6, string: '6' },
{ value: { something: 'else' } }
{ value: { something: 'else' } },
]),
);
});
@@ -86,10 +87,8 @@ describe('Data Transformation Functions', () => {
test('.unique() should work on an arrays containing nulls, objects and arrays', () => {
expect(
evaluate(
'={{ [1, 2, 3, "as", {}, {}, 1, 2, [1,2], "[sad]", "[sad]", null].unique() }}',
),
).toEqual([1, 2, 3, "as", {}, [1,2], "[sad]", null]);
evaluate('={{ [1, 2, 3, "as", {}, {}, 1, 2, [1,2], "[sad]", "[sad]", null].unique() }}'),
).toEqual([1, 2, 3, 'as', {}, [1, 2], '[sad]', null]);
});
test('.isEmpty() should work correctly on an array', () => {
@@ -113,7 +112,7 @@ describe('Data Transformation Functions', () => {
evaluate(
'={{ [{ test1: 1, test2: 2 }, { test1: 1, test3: 3 }].merge([{ test1: 2, test3: 3 }, { test4: 4 }]) }}',
),
).toEqual({"test1": 1, "test2": 2, "test3": 3, "test4": 4});
).toEqual({ test1: 1, test2: 2, test3: 3, test4: 4 });
});
test('.merge() should work correctly without arguments', () => {
@@ -121,7 +120,7 @@ describe('Data Transformation Functions', () => {
evaluate(
'={{ [{ a: 1, some: null }, { a: 2, c: "something" }, 2, "asds", { b: 23 }, null, [1, 2]].merge() }}',
),
).toEqual({"a": 1, "some": null, "c": "something", "b": 23});
).toEqual({ a: 1, some: null, c: 'something', b: 23 });
});
test('.smartJoin() should work correctly on an array of objects', () => {
@@ -175,11 +174,14 @@ describe('Data Transformation Functions', () => {
});
test('.union() should work on an arrays containing nulls, objects and arrays', () => {
expect(
evaluate(
'={{ [1, 2, "dd", {}, null].union([1, {}, null, 3]) }}',
),
).toEqual([1, 2, "dd", {}, null, 3]);
expect(evaluate('={{ [1, 2, "dd", {}, null].union([1, {}, null, 3]) }}')).toEqual([
1,
2,
'dd',
{},
null,
3,
]);
});
test('.intersection() should work on an array of objects', () => {
@@ -191,11 +193,11 @@ describe('Data Transformation Functions', () => {
});
test('.intersection() should work on an arrays containing nulls, objects and arrays', () => {
expect(
evaluate(
'={{ [1, 2, "dd", {}, null].intersection([1, {}, null]) }}',
),
).toEqual([1, {}, null]);
expect(evaluate('={{ [1, 2, "dd", {}, null].intersection([1, {}, null]) }}')).toEqual([
1,
{},
null,
]);
});
test('.difference() should work on an array of objects', () => {
@@ -212,10 +214,8 @@ describe('Data Transformation Functions', () => {
test('.difference() should work on an arrays containing nulls, objects and arrays', () => {
expect(
evaluate(
'={{ [1, 2, "dd", {}, null, ["a", 1]].difference([1, {}, null, ["a", 1]]) }}',
),
).toEqual([2, "dd"]);
evaluate('={{ [1, 2, "dd", {}, null, ["a", 1]].difference([1, {}, null, ["a", 1]]) }}'),
).toEqual([2, 'dd']);
});
test('.compact() should work on an array', () => {

View File

@@ -61,7 +61,6 @@ describe('Data Transformation Functions', () => {
expect(evaluate('={{ DateTime.local(2023, 1, 20).extract() }}')).toEqual(3);
});
test('.format("yyyy LLL dd") should work correctly on a date', () => {
expect(evaluate('={{ DateTime.local(2023, 1, 16).format("yyyy LLL dd") }}')).toEqual(
'2023 Jan 16',
@@ -74,27 +73,29 @@ describe('Data Transformation Functions', () => {
});
test('.inBetween() should work on string and Date', () => {
expect(evaluate(`={{ $now.isBetween('2023-06-23'.toDate(), '2023-06-23') }}`)).toBeDefined();
expect(evaluate("={{ $now.isBetween('2023-06-23'.toDate(), '2023-06-23') }}")).toBeDefined();
});
test('.inBetween() should work on string and DateTime', () => {
expect(evaluate(`={{ $now.isBetween($now, '2023-06-23') }}`)).toBeDefined();
expect(evaluate("={{ $now.isBetween($now, '2023-06-23') }}")).toBeDefined();
});
test('.inBetween() should not work for invalid strings', () => {
expect(evaluate(`={{ $now.isBetween($now, 'invalid') }}`)).toBeUndefined();
expect(evaluate("={{ $now.isBetween($now, 'invalid') }}")).toBeUndefined();
});
test('.inBetween() should not work for numbers', () => {
expect(evaluate(`={{ $now.isBetween($now, 1) }}`)).toBeUndefined();
expect(evaluate('={{ $now.isBetween($now, 1) }}')).toBeUndefined();
});
test('.inBetween() should not work for a single argument', () => {
expect(() => evaluate(`={{ $now.isBetween($now) }}`)).toThrow();
expect(() => evaluate('={{ $now.isBetween($now) }}')).toThrow();
});
test('.inBetween() should not work for a more than two arguments', () => {
expect(() => evaluate(`={{ $now.isBetween($now, '2023-06-23', '2023-09-21'.toDate()) }}`)).toThrow();
expect(() =>
evaluate("={{ $now.isBetween($now, '2023-06-23', '2023-09-21'.toDate()) }}"),
).toThrow();
});
});
});

View File

@@ -2,6 +2,8 @@
* @jest-environment jsdom
*/
/* eslint-disable n8n-local-rules/no-interpolation-in-regular-string */
import { extendTransform } from '@/Extensions';
import { joinExpression, splitExpression } from '@/Extensions/ExpressionParser';
import { evaluate } from './Helpers';

View File

@@ -1,4 +1,5 @@
import { Expression, IDataObject, Workflow } from '../../src';
import type { IDataObject } from '../../src';
import { Expression, Workflow } from '../../src';
import * as Helpers from '../Helpers';
export const TEST_TIMEZONE = 'America/New_York';
@@ -20,7 +21,7 @@ export const workflow = new Workflow({
nodeTypes,
settings: {
timezone: TEST_TIMEZONE,
}
},
});
export const expression = new Expression(workflow);

View File

@@ -59,6 +59,7 @@ describe('Data Transformation Functions', () => {
describe('Multiple expressions', () => {
test('Basic multiple expressions', () => {
// eslint-disable-next-line n8n-local-rules/no-interpolation-in-regular-string
expect(evaluate('={{ "test abc".toSnakeCase() }} you have ${{ (100).format() }}.')).toEqual(
'test_abc you have $100.',
);

View File

@@ -37,8 +37,8 @@ describe('Data Transformation Functions', () => {
});
test('.removeFieldsContaining should not work for empty string', () => {
expect(
() => evaluate(
expect(() =>
evaluate(
'={{ ({ test1: "i exist", test2: "i should be removed", test3: "i should also be removed" }).removeFieldsContaining("") }}',
),
).toThrow();
@@ -65,8 +65,8 @@ describe('Data Transformation Functions', () => {
});
test('.keepFieldsContaining should not work for empty string', () => {
expect(
() => evaluate(
expect(() =>
evaluate(
'={{ ({ test1: "i exist", test2: "i should be removed", test3: "i should also be removed" }).keepFieldsContaining("") }}',
),
).toThrow();

View File

@@ -3,7 +3,6 @@
*/
import { stringExtensions } from '@/Extensions/StringExtensions';
import { dateExtensions } from '@/Extensions/DateExtensions';
import { evaluate } from './Helpers';
describe('Data Transformation Functions', () => {
@@ -157,13 +156,29 @@ describe('Data Transformation Functions', () => {
'={{ "I am a test with a url: https://example.net/ and I am a test with an email: test@example.org".extractUrl() }}',
),
).toEqual('https://example.net/');
expect(evaluate('={{ "Check this out: https://subdomain.example.com:3000/path?q=1#hash".extractUrl() }}')).toEqual('https://subdomain.example.com:3000/path?q=1#hash');
expect(
evaluate(
'={{ "Check this out: https://subdomain.example.com:3000/path?q=1#hash".extractUrl() }}',
),
).toEqual('https://subdomain.example.com:3000/path?q=1#hash');
expect(evaluate('={{ "Invalid URL: http:///example.com".extractUrl() }}')).toEqual(undefined);
expect(evaluate('={{ "Mixed content: https://www.example.com and http://www.example.org".extractUrl() }}')).toEqual('https://www.example.com');
expect(evaluate('={{ "Text without URL: This is just a simple text".extractUrl() }}')).toEqual(undefined);
expect(evaluate('={{ "URL with Unicode: http://www.xn--80aswg.xn--j1amh".extractUrl() }}')).toEqual('http://www.xn--80aswg.xn--j1amh');
expect(evaluate('={{ "Localhost URL: http://localhost:8080/test?x=1".extractUrl() }}')).toEqual('http://localhost:8080/test?x=1');
expect(evaluate('={{ "IP URL: http://192.168.1.1:8000/path?q=value#frag".extractUrl() }}')).toEqual('http://192.168.1.1:8000/path?q=value#frag');
expect(
evaluate(
'={{ "Mixed content: https://www.example.com and http://www.example.org".extractUrl() }}',
),
).toEqual('https://www.example.com');
expect(
evaluate('={{ "Text without URL: This is just a simple text".extractUrl() }}'),
).toEqual(undefined);
expect(
evaluate('={{ "URL with Unicode: http://www.xn--80aswg.xn--j1amh".extractUrl() }}'),
).toEqual('http://www.xn--80aswg.xn--j1amh');
expect(
evaluate('={{ "Localhost URL: http://localhost:8080/test?x=1".extractUrl() }}'),
).toEqual('http://localhost:8080/test?x=1');
expect(
evaluate('={{ "IP URL: http://192.168.1.1:8000/path?q=value#frag".extractUrl() }}'),
).toEqual('http://192.168.1.1:8000/path?q=value#frag');
});
test('.extractDomain should work on a string', () => {
@@ -175,24 +190,46 @@ describe('Data Transformation Functions', () => {
expect(evaluate('={{ "google.com".extractDomain() }}')).toEqual('google.com');
expect(evaluate('={{ "www.example.net".extractDomain() }}')).toEqual('www.example.net');
expect(evaluate('={{ "//example.com".extractDomain() }}')).toEqual('example.com');
expect(evaluate('={{ "mailto:john.doe@example.com".extractDomain() }}')).toEqual('example.com');
expect(evaluate('={{ "mailto:john.doe@example.com".extractDomain() }}')).toEqual(
'example.com',
);
expect(evaluate('={{ "tel:+1-555-123-4567".extractDomain() }}')).toEqual(undefined);
expect(evaluate('={{ "jane.doe@example.org".extractDomain() }}')).toEqual('example.org');
expect(evaluate('={{ "name+tag@example.com".extractDomain() }}')).toEqual('example.com');
expect(evaluate('={{ "first.last@example.co.uk".extractDomain() }}')).toEqual('example.co.uk');
expect(evaluate('={{ "user@subdomain.example.com".extractDomain() }}')).toEqual('subdomain.example.com');
expect(evaluate('={{ "www.example.net?test=1213".extractDomain() }}')).toEqual('www.example.net');
expect(evaluate('={{ "first.last@example.co.uk".extractDomain() }}')).toEqual(
'example.co.uk',
);
expect(evaluate('={{ "user@subdomain.example.com".extractDomain() }}')).toEqual(
'subdomain.example.com',
);
expect(evaluate('={{ "www.example.net?test=1213".extractDomain() }}')).toEqual(
'www.example.net',
);
expect(evaluate('={{ "www.example.net?test".extractDomain() }}')).toEqual('www.example.net');
expect(evaluate('={{ "www.example.net#tesdt123".extractDomain() }}')).toEqual('www.example.net');
expect(evaluate('={{ "https://www.example.net?test=1213".extractDomain() }}')).toEqual('www.example.net');
expect(evaluate('={{ "https://www.example.net?test".extractDomain() }}')).toEqual('www.example.net');
expect(evaluate('={{ "https://www.example.net#tesdt123".extractDomain() }}')).toEqual('www.example.net');
expect(evaluate('={{ "www.example.net#tesdt123".extractDomain() }}')).toEqual(
'www.example.net',
);
expect(evaluate('={{ "https://www.example.net?test=1213".extractDomain() }}')).toEqual(
'www.example.net',
);
expect(evaluate('={{ "https://www.example.net?test".extractDomain() }}')).toEqual(
'www.example.net',
);
expect(evaluate('={{ "https://www.example.net#tesdt123".extractDomain() }}')).toEqual(
'www.example.net',
);
expect(evaluate('={{ "https://192.168.1.1".extractDomain() }}')).toEqual('192.168.1.1');
expect(evaluate('={{ "http://www.xn--80aswg.xn--j1amh".extractDomain() }}')).toEqual('www.xn--80aswg.xn--j1amh');
expect(evaluate('={{ "http://www.xn--80aswg.xn--j1amh".extractDomain() }}')).toEqual(
'www.xn--80aswg.xn--j1amh',
);
expect(evaluate('={{ "https://localhost".extractDomain() }}')).toEqual('localhost');
expect(evaluate('={{ "https://localhost?test=123".extractDomain() }}')).toEqual('localhost');
expect(evaluate('={{ "https://www.example_with_underscore.com".extractDomain() }}')).toEqual('www.example_with_underscore.com');
expect(evaluate('={{ "https://www.example.com:8080".extractDomain() }}')).toEqual('www.example.com');
expect(evaluate('={{ "https://www.example_with_underscore.com".extractDomain() }}')).toEqual(
'www.example_with_underscore.com',
);
expect(evaluate('={{ "https://www.example.com:8080".extractDomain() }}')).toEqual(
'www.example.com',
);
expect(evaluate('={{ "https://example.space".extractDomain() }}')).toEqual('example.space');
});