import { expect } from 'chai'; import { rm } from 'fs/promises'; import { getColCount, getFilesColCount } from '../../src/generate-conf/generate-csv-conf'; import { createFile } from '../../src/utils/file'; import { getTestPath, randomString } from '../utils/utils'; describe('generate-conf/index', () => { let inputPaths: string[] = []; beforeEach(async () => { inputPaths = []; const fileName = randomString(); const inputFilePath = getTestPath(`${fileName}-1.csv`); inputPaths.push(inputFilePath); await createFile(inputFilePath, [ 'a,b,c', 'a,b,c', 'e,d,f', ]); const inputFilePath2 = getTestPath(`${fileName}-2.csv`); inputPaths.push(inputFilePath2); await createFile(inputFilePath2, [ '5e0d2f393fff22602801c349,5ff960db13fe3a5929abe29f,anoy,1611805251,True,True,17', '5e0d2f393fff22602801c349,5ff960db13fe3a5929abe29f,anoy,1611805251,True,True,17', '5e0d2f393fff22602801c349,5ff960db13fe3a5929abe29f,anoy,1611805251,True,True,17', ]); }); afterEach(() => { inputPaths.forEach((path) => { rm(path); }); }); it('获取文件的列数对象(首列不同名)', async () => { const path = inputPaths[0]; const colObj = await getColCount(path); expect(colObj).to.deep.equals({ filePath: path, columnCount: 3, }); }); it('获取文件的列数对象(首列同名)', async () => { const path = inputPaths[1]; const colObj = await getColCount(path); expect(colObj).to.deep.equals({ filePath: path, columnCount: 7, }); }); it('获取文件的列数对象数组', async () => { const colObj = await getFilesColCount(getTestPath()); expect(colObj).to.deep.equals([ { filePath: inputPaths[0], columnCount: 3, }, { filePath: inputPaths[1], columnCount: 7, }, ]); }); });