feat: modernize core-tools

This commit is contained in:
Wieland Schöbl
2021-08-25 09:47:36 +00:00
parent 106dd26f89
commit fe59204b42
106 changed files with 4131 additions and 6216 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable unicorn/prefer-module */
/*
* Copyright (C) 2018-2019 StApps
* This program is free software: you can redistribute it and/or modify it
@@ -13,19 +14,19 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {expect} from 'chai';
import {resolve} from 'path';
import {existsSync, unlinkSync} from 'fs';
import {slow, suite, test, timeout} from '@testdeck/mocha';
import {getProjectReflection} from '../src/common';
import {createDiagram, createDiagramFromString} from '../src/uml/create-diagram';
import {UMLConfig} from '../src/uml/uml-config';
import {readDefinitions} from '../src/uml/read-definitions';
import {LightweightDefinition} from '../src/uml/model/lightweight-definition';
import {LightweightDefinition} from '../src/easy-ast/types/lightweight-definition';
import nock = require('nock');
import {lightweightDefinitionsFromPath} from '../src/easy-ast/easy-ast';
import path from 'path';
@suite(timeout(15000), slow(5000))
@suite(timeout(15_000), slow(5000))
export class CreateDiagramSpec {
plantUmlConfig: UMLConfig;
definitions: LightweightDefinition[];
constructor() {
@@ -39,21 +40,20 @@ export class CreateDiagramSpec {
showProperties: true,
};
const projectReflection = getProjectReflection('./test/model', true);
this.definitions = readDefinitions(projectReflection);
this.definitions = lightweightDefinitionsFromPath('./test/model');
}
@test
async shouldRefuseRequest() {
const testPlantUmlCode: string = 'class Test{\n}';
const testPlantUmlCode = 'class Test{\n}';
try {
await createDiagramFromString(testPlantUmlCode, "http://plantuml:8080");
} catch (e) {
await createDiagramFromString(testPlantUmlCode, 'http://plantuml:8080');
} catch (error) {
expect([
new Error('getaddrinfo ENOTFOUND plantuml plantuml:8080').message,
new Error('getaddrinfo EAI_AGAIN plantuml plantuml:8080').message,
new Error('getaddrinfo ENOTFOUND plantuml').message,
]).to.include(e.message);
]).to.include(error.message);
}
}
@@ -69,18 +69,18 @@ export class CreateDiagramSpec {
nock('http://plantuml:8080')
.persist()
.get(() => true)
.reply(200, 'This will be the file content')
.reply(200, 'This will be the file content');
let fileName = await createDiagram(this.definitions, this.plantUmlConfig, "http://plantuml:8080");
let filePath = resolve(__dirname, '..', fileName);
let fileName = await createDiagram(this.definitions, this.plantUmlConfig, 'http://plantuml:8080');
let filePath = path.resolve(__dirname, '..', fileName);
expect(await existsSync(filePath)).to.equal(true);
await unlinkSync(fileName);
this.plantUmlConfig.showAssociations = false;
this.plantUmlConfig.showInheritance = false;
fileName = await createDiagram(this.definitions, this.plantUmlConfig, "http://plantuml:8080");
filePath = resolve(__dirname, '..', fileName);
fileName = await createDiagram(this.definitions, this.plantUmlConfig, 'http://plantuml:8080');
filePath = path.resolve(__dirname, '..', fileName);
expect(await existsSync(filePath)).to.equal(true);
await unlinkSync(fileName);