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
@@ -15,21 +16,21 @@
import {Logger} from '@openstapps/logger';
import {expect} from 'chai';
import {slow, suite, test, timeout} from '@testdeck/mocha';
import {join} from 'path';
import {Converter, getValidatableTypesFromReflection} from '../src/schema';
import {Converter} from '../src/schema';
import path from 'path';
process.on('unhandledRejection', (error: unknown) => {
if (error instanceof Error) {
Logger.error('UNHANDLED REJECTION', error.stack);
void Logger.error('UNHANDLED REJECTION', error.stack);
}
process.exit(1);
});
@suite(timeout(40000), slow(10000))
@suite(timeout(40_000), slow(10_000))
export class SchemaSpec {
@test
async getSchema() {
const converter = new Converter(join(__dirname, '..', 'src', 'resources'));
const converter = new Converter(path.join(__dirname, '..', 'src', 'resources'));
const schema = converter.getSchema('Foo', '0.0.1');
expect(schema).to.be.deep.equal({
@@ -38,21 +39,18 @@ export class SchemaSpec {
additionalProperties: false,
definitions: {
FooType: {
description: 'This is a simple type declaration for\nusage in the Foo interace.',
enum: [
'Foo',
],
type: 'string',
},
description: 'This is a simple type declaration for usage in the Foo interface.',
const: 'Foo',
type: 'string',
},
SCFoo: {
additionalProperties: false,
description: 'This is a simple interface declaration for\ntesting the schema generation and validation.',
description:
'This is a simple interface declaration for testing the schema generation and validation.',
properties: {
lorem: {
description: 'Dummy parameter',
enum: [
'ipsum',
],
enum: ['lorem', 'ipsum'],
type: 'string',
},
type: {
@@ -60,20 +58,15 @@ export class SchemaSpec {
description: 'String literal type property',
},
},
required: [
'lorem',
'type',
],
required: ['lorem', 'type'],
type: 'object',
},
},
description: 'This is a simple interface declaration for\ntesting the schema generation and validation.',
description: 'This is a simple interface declaration for testing the schema generation and validation.',
properties: {
lorem: {
description: 'Dummy parameter',
enum: [
'ipsum',
],
enum: ['lorem', 'ipsum'],
type: 'string',
},
type: {
@@ -81,47 +74,8 @@ export class SchemaSpec {
description: 'String literal type property',
},
},
required: [
'lorem',
'type',
],
required: ['lorem', 'type'],
type: 'object',
});
}
@test
async getValidatableTypesFromReflection() {
const reflection: any = {
children: [
{
children: [
{
comment: {
tags: [
{
tagName: 'validatable',
},
],
},
name: 'foo',
},
{
name: 'bar',
},
],
},
{
children: [
{
name: 'foobar',
},
],
},
],
};
const validatableTypes = getValidatableTypesFromReflection(reflection as any);
expect(validatableTypes).to.be.deep.equal(['foo']);
}
}