2022-03-10 12:26:24 -03:00
|
|
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
|
|
/* eslint-disable import/prefer-default-export */
|
2022-03-14 17:31:54 -03:00
|
|
|
import fs from 'fs';
|
2022-03-10 12:26:24 -03:00
|
|
|
import path from 'path';
|
|
|
|
import { expect } from '@jest/globals';
|
2022-03-14 17:31:54 -03:00
|
|
|
import { diff } from 'jest-diff';
|
2022-03-10 12:26:24 -03:00
|
|
|
import Importer from '../../../src/components/import/Importer';
|
2022-03-18 14:23:08 -03:00
|
|
|
|
|
|
|
const saveOutputRecord = false;
|
2022-03-17 16:24:52 -03:00
|
|
|
|
|
|
|
export const parseXMLString = (xmlStr: string, mimeType: DOMParserSupportedType) => {
|
|
|
|
const parser = new DOMParser();
|
|
|
|
const xmlDoc = parser.parseFromString(xmlStr, mimeType);
|
|
|
|
|
|
|
|
return xmlDoc;
|
|
|
|
};
|
|
|
|
|
2022-07-13 01:45:36 +00:00
|
|
|
export const parseXMLFile = (
|
|
|
|
filePath: fs.PathOrFileDescriptor,
|
|
|
|
mimeType: DOMParserSupportedType,
|
|
|
|
) => {
|
2022-03-17 16:24:52 -03:00
|
|
|
const stream = fs.readFileSync(filePath, { encoding: 'utf-8' });
|
|
|
|
|
2022-03-22 12:34:27 -03:00
|
|
|
const content = stream.toString();
|
2022-03-17 16:24:52 -03:00
|
|
|
|
|
|
|
return parseXMLString(content, mimeType);
|
|
|
|
};
|
2022-03-10 12:26:24 -03:00
|
|
|
|
|
|
|
export const exporterAssert = async (testName: string, importer: Importer) => {
|
|
|
|
const actualMindmap = await importer.import(testName, '');
|
|
|
|
|
2022-03-18 14:23:08 -03:00
|
|
|
// Load mindmap file..
|
2022-03-10 12:26:24 -03:00
|
|
|
const mindmapPath = path.resolve(__dirname, `./expected/${testName}.wxml`);
|
2022-03-18 14:23:08 -03:00
|
|
|
if (saveOutputRecord) {
|
|
|
|
fs.writeFileSync(mindmapPath, actualMindmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
const mindmapExpect = fs.readFileSync(mindmapPath).toString();
|
2022-03-10 12:26:24 -03:00
|
|
|
|
2022-03-14 17:31:54 -03:00
|
|
|
// Compare with expected...
|
|
|
|
if (actualMindmap !== mindmapExpect) {
|
|
|
|
const diffResult = diff(actualMindmap, mindmapExpect);
|
|
|
|
console.log(diffResult);
|
2022-03-18 14:23:08 -03:00
|
|
|
expect(actualMindmap).toEqual(mindmapExpect);
|
2022-03-14 17:31:54 -03:00
|
|
|
}
|
2022-03-10 12:26:24 -03:00
|
|
|
};
|