mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Spreadsheet File Node): Improve CSV parsing (#7448)
This adds support for 1. custom delimiters 2. reading offsets to avoid having to read a large CSV all at once 3. excluding byte-order-mark NODE-861 #7443
This commit is contained in:
committed by
GitHub
parent
d8531a53b9
commit
79f23fb939
@@ -1,24 +1,28 @@
|
||||
import path from 'path';
|
||||
import type { IWorkflowBase } from 'n8n-workflow';
|
||||
import * as Helpers from '@test/nodes/Helpers';
|
||||
import type { WorkflowTestData } from '@test/nodes/types';
|
||||
|
||||
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
|
||||
import path from 'path';
|
||||
|
||||
describe('Execute Spreadsheet File Node', () => {
|
||||
beforeEach(async () => {
|
||||
await Helpers.initBinaryDataService();
|
||||
});
|
||||
|
||||
// replace workflow json 'Read Binary File' node's filePath to local file
|
||||
const workflow = Helpers.readJsonFileSync('nodes/SpreadsheetFile/test/workflow.json');
|
||||
const node = workflow.nodes.find((n: any) => n.name === 'Read Binary File');
|
||||
node.parameters.filePath = path.join(__dirname, 'spreadsheet.csv');
|
||||
const loadWorkflow = (fileName: string, csvName: string) => {
|
||||
const workflow = Helpers.readJsonFileSync<IWorkflowBase>(
|
||||
`nodes/SpreadsheetFile/test/${fileName}`,
|
||||
);
|
||||
const node = workflow.nodes.find((n) => n.name === 'Read Binary File');
|
||||
node!.parameters.fileSelector = path.join(__dirname, csvName);
|
||||
return workflow;
|
||||
};
|
||||
|
||||
const tests: WorkflowTestData[] = [
|
||||
{
|
||||
description: 'execute workflow.json',
|
||||
input: {
|
||||
workflowData: workflow,
|
||||
workflowData: loadWorkflow('workflow.json', 'spreadsheet.csv'),
|
||||
},
|
||||
output: {
|
||||
nodeData: {
|
||||
@@ -78,6 +82,7 @@ describe('Execute Spreadsheet File Node', () => {
|
||||
},
|
||||
],
|
||||
],
|
||||
'Read CSV with Row Limit': [[{ json: { A: '1', B: '2', C: '3' } }]],
|
||||
'Write To File CSV': [
|
||||
[
|
||||
{
|
||||
@@ -149,6 +154,18 @@ describe('Execute Spreadsheet File Node', () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: 'execute workflow.bom.json',
|
||||
input: {
|
||||
workflowData: loadWorkflow('workflow.bom.json', 'bom.csv'),
|
||||
},
|
||||
output: {
|
||||
nodeData: {
|
||||
'Edit with BOM included': [[{ json: { X: null } }]],
|
||||
'Edit with BOM excluded': [[{ json: { X: '1' } }]],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const nodeTypes = Helpers.setup(tests);
|
||||
|
||||
Reference in New Issue
Block a user