test(Spreadsheet File Node): Unit tests (no-changelog) (#5385)

* ️test setup

* ️fix  'testData' implicitly has an 'any' type.

*  test github action file binary data reading

*  checking for output binary equality

*  writing files to different formats

*  reading spreadsheet with different options

* ️improve workflow file path replacement

* 🐛 fixing string.at() not supported in node 14.

* 🐛 trying to fix github action test error

*  fix for empty binary

*  switch for binary test

* ️test helpers now return/compare json and binary (if not empty))

*  removed commented console log

---------

Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
Marcus
2023-02-09 09:00:29 +01:00
committed by GitHub
parent 94f2b2a26f
commit 74fc1414d7
5 changed files with 449 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
import { readFileSync, readdirSync } from 'fs';
import { Credentials, loadClassInIsolation } from 'n8n-core';
import { readFileSync, readdirSync, mkdtempSync } from 'fs';
import { BinaryDataManager, Credentials, loadClassInIsolation } from 'n8n-core';
import {
ICredentialDataDecryptedObject,
ICredentialsHelper,
@@ -27,6 +27,8 @@ import {
import { executeWorkflow } from './ExecuteWorkflow';
import { WorkflowTestData } from './types';
import path from 'path';
import { tmpdir } from 'os';
import { isEmpty } from 'lodash';
export class CredentialsHelper extends ICredentialsHelper {
async authenticate(
@@ -156,6 +158,17 @@ const loadKnownNodes = (): Record<string, LoadingDetails> => {
return knownNodes!;
};
export async function initBinaryDataManager(mode: 'default' | 'filesystem' = 'default') {
const temporaryDir = mkdtempSync(path.join(tmpdir(), 'n8n'));
await BinaryDataManager.init({
mode,
availableModes: mode,
localStoragePath: temporaryDir,
binaryDataTTL: 1,
persistedBinaryDataTTL: 1,
});
}
export function setup(testData: Array<WorkflowTestData> | WorkflowTestData) {
if (!Array.isArray(testData)) {
testData = [testData];
@@ -204,7 +217,11 @@ export function getResultNodeData(result: IRun, testData: WorkflowTestData) {
if (nodeData.data === undefined) {
return null;
}
return nodeData.data.main[0]!.map((entry) => entry.json);
return nodeData.data.main[0]!.map((entry) => {
if (entry.binary && isEmpty(entry.binary)) delete entry.binary;
delete entry.pairedItem;
return entry;
});
});
return {
nodeName,
@@ -241,7 +258,7 @@ export const workflowToTests = (workflowFiles: string[]) => {
}
const nodeData = Object.keys(workflowData.pinData).reduce(
(acc, key) => {
const data = (workflowData.pinData[key] as IDataObject[]).map((item) => item.json);
const data = workflowData.pinData[key] as IDataObject[];
acc[key] = [data as IDataObject[]];
return acc;
},