feat: tests

This commit is contained in:
2023-04-21 12:08:35 +02:00
parent 8cb9285462
commit d8c79256c9
140 changed files with 2100 additions and 2693 deletions

View File

@@ -13,7 +13,6 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '@openstapps/logger';
import {createWriteStream} from 'fs';
import * as request from 'got';
import {
expandTypeValue,
@@ -22,9 +21,10 @@ import {
LightweightClassDefinition,
LightweightDefinition,
LightweightProperty,
LightweightType
LightweightType,
} from '@openstapps/easy-ast';
import {UMLConfig} from './uml-config.js';
import {writeFile} from 'fs/promises';
/**
* Converts the lightweight class/enum definitions according to the configuration,
@@ -81,8 +81,8 @@ export async function createDiagramFromString(
plantUmlBaseURL: string,
outputFile = `Diagram-${new Date().toISOString()}`,
) {
// eslint-disable-next-line @typescript-eslint/no-var-requires,unicorn/prefer-module
const plantumlEncoder = require('plantuml-encoder');
// @ts-expect-error no declarations
const plantumlEncoder = await import('plantuml-encoder');
const plantUMLCode = plantumlEncoder.encode(`@startuml\n${modelPlantUMLCode}\n@enduml`);
const url = `${plantUmlBaseURL}/svg/${plantUMLCode}`;
let response;
@@ -100,13 +100,10 @@ export async function createDiagramFromString(
throw error;
}
// attach file extension
const fileName = `${outputFile}.svg`;
try {
createWriteStream(fileName).write(response.body);
Logger.log(`Writen data to file: ${fileName}`);
} catch {
throw new Error('Could not write file. Are you missing permissions?');
}
const fileName = `${outputFile.replace(/[^\w-]/g, '_')}.svg`;
await writeFile(fileName, response.body);
Logger.log(`Writen data to file: ${fileName}`);
return fileName;
}