feat: pipeline improvements

This commit is contained in:
2023-11-07 18:51:55 +01:00
parent 51602ffa0f
commit fdec5a5baa
20 changed files with 118 additions and 150 deletions

View File

@@ -16,18 +16,18 @@
"main": "./src/index.js",
"types": "./src/types.d.ts",
"files": [
"lib",
"src",
"schema",
"Dockerfile",
"README.md",
"CHANGELOG.md"
],
"scripts": {
"docs": "typedoc --json ./docs/docs.json --options ../../typedoc.base.json src/index.ts",
"docs": "typedoc --json ./docs/docs.json --options ../../typedoc.base.json src/types.d.ts",
"format": "prettier . -c --ignore-path ../../.gitignore",
"format:fix": "prettier --write . --ignore-path ../../.gitignore",
"lint": "eslint --ext .ts src/",
"lint:fix": "eslint --fix --ext .ts src/",
"lint": "tsc --noEmit && eslint --ext .js src/",
"lint:fix": "eslint --fix --ext .js src/",
"test": "c8 mocha"
},
"dependencies": {
@@ -51,6 +51,7 @@
"mocha": "10.2.0",
"mocha-junit-reporter": "2.2.0",
"nock": "13.3.1",
"ts-node": "10.9.1",
"typedoc": "0.24.8",
"typescript": "5.1.6"
},

View File

@@ -0,0 +1,58 @@
/* 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 {expect} from 'chai';
import path from 'path';
import {fileURLToPath} from 'url';
import {stat, readFile} from 'fs/promises';
import {Validator} from '../src/index.js';
describe('Validator', function () {
this.timeout(40_000);
this.slow(5000);
/** @type {import('json-schema').JSONSchema7} */
let schema;
/** @type {import('@openstapps/core').SCThings[]} */
let instances = [];
beforeEach(async function () {
const resourceDirectory = path.join(
path.dirname(fileURLToPath(import.meta.url)),
'..',
'..',
'core',
'test',
'resources',
);
/** @type {import('@openstapps/core').SCThings[]} */
instances = [];
for (const file in await stat(resourceDirectory)) {
if (file.endsWith('.json')) {
const {instance} = JSON.parse(await readFile(path.join(resourceDirectory, file), 'utf8'));
instances.push(instance);
}
}
});
it('should validate schemas by their SCThingType', async function () {
const validator = new Validator();
for (const instance of instances) {
const validationResult = validator.validate(instance, instance.type);
expect(validator.errors).to.be.empty;
expect(validationResult).to.be.true;
}
});
});

View File

@@ -1,85 +0,0 @@
/* 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;
});
});

View File

@@ -1,7 +1,3 @@
{
"extends": "@openstapps/tsconfig",
"compilerOptions": {
"noUnusedLocals": false,
"stripInternal": true
}
"extends": "@openstapps/tsconfig"
}