feat: improve monorepo dev experience

This commit is contained in:
2023-10-30 17:31:40 +01:00
parent f65fb52def
commit 8466976b3c
59 changed files with 157 additions and 2662 deletions

View File

@@ -37,7 +37,6 @@
"ajv-formats": "2.1.1"
},
"devDependencies": {
"@openstapps/core-tools": "workspace:*",
"@openstapps/eslint-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",

View File

@@ -1,7 +1,6 @@
import Ajv, {AnySchema} from 'ajv';
import addFormats from 'ajv-formats';
import schema from '../schema/core.schema.json';
import {SchemaMap} from '../schema/core.schema.js';
import schema, {SchemaMap} from '@openstapps/core/schema.json';
export type RemoveNeverProperties<T> = {
[K in Exclude<

View File

@@ -0,0 +1,85 @@
/* eslint-disable unicorn/prefer-module */
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from 'packages/logger/lib/index.js';
import {expect} from 'chai';
import {existsSync} from 'fs';
import {JSONSchema7 as Schema} from 'json-schema';
import {Foo} from '@openstapps/core-tools/src/resources/foo.js';
import {Validator} from '../src/validate.js';
import path from 'path';
import {fileURLToPath} from 'url';
import {rm, mkdir, writeFile} from 'fs/promises';
import {Converter} from '@openstapps/core-tools/src/index.js';
process.on('unhandledRejection', (error: unknown) => {
if (error instanceof Error) {
void Logger.error('UNHANDLED REJECTION', error.stack);
}
process.exit(1);
});
const tmpdir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'tmp');
const fooInstance: Foo = {
lorem: 'ipsum',
type: 'Foo',
};
describe('Validator', function () {
this.timeout(40_000);
this.slow(5000);
let schema: Schema;
let converter: Converter;
beforeEach(async function () {
converter = new Converter(
path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'src', 'resources'),
);
schema = converter.getSchema('Foo', '0.0.1');
if (!existsSync(tmpdir)) {
await mkdir(tmpdir);
}
await writeFile(path.join(tmpdir, 'SCFoo.json'), JSON.stringify(schema, undefined, 2));
});
afterEach(async function () {
try {
await rm(tmpdir, {recursive: true});
} catch (error) {
expect(error, `Unable to remove temporary directory for tests at: ${tmpdir}`).to.be.null;
}
});
it('should validate by schema identifying string', async function () {
const validator = new Validator();
await validator.addSchemas(tmpdir);
const validationResult = validator.validate(fooInstance, 'SCFoo');
expect(validationResult.errors, JSON.stringify(validationResult.errors, undefined, 2)).to.be.empty;
});
it('should validate by schema instance', async function () {
const validator = new Validator();
const validationResult = validator.validate(fooInstance, schema);
expect(validationResult.errors, JSON.stringify(validationResult.errors, undefined, 2)).to.be.empty;
});
it('should validate intrinsic', async function () {
const validator = new Validator();
await validator.addSchemas(tmpdir);
const validationResult = validator.validate(fooInstance);
expect(validationResult.errors, JSON.stringify(validationResult.errors, undefined, 2)).to.be.empty;
});
});