feat: migrate backend to cosmiconfig

This commit is contained in:
2023-04-25 15:54:06 +02:00
parent d8c79256c9
commit 0a76427ba8
70 changed files with 1786 additions and 1635 deletions

View File

@@ -42,7 +42,7 @@ describe('Bulk', function () {
afterEach(function () {
sandbox.restore();
})
});
it('should add', async function () {
sandbox.on(client, 'invokeRoute', () => {

View File

@@ -35,10 +35,17 @@ import chaiSpies from 'chai-spies';
import clone = require('rfdc');
import moment from 'moment';
import traverse from 'traverse';
import {ConnectorClient, EmptyBulkError, NamespaceNotDefinedError, HttpClient, HttpClientRequest, HttpClientResponse} from '../src/index.js';
import path from "path";
import {fileURLToPath} from "url";
import {readdir, readFile} from "fs/promises";
import {
ConnectorClient,
EmptyBulkError,
NamespaceNotDefinedError,
HttpClient,
HttpClientRequest,
HttpClientResponse,
} from '../src/index.js';
import path from 'path';
import {fileURLToPath} from 'url';
import {readdir, readFile} from 'fs/promises';
chai.should();
chai.use(chaiSpies);
@@ -333,7 +340,7 @@ describe('ConnectorClient', function () {
expect(ConnectorClient.makeUUID('foo', 'f-u')).not.to.be.equal(uuid);
});
it('should fail making a uuid', async function (){
it('should fail making a uuid', async function () {
expect(() => {
ConnectorClient.makeUUID('foo', 'b-u');
}).to.throw(NamespaceNotDefinedError);
@@ -353,12 +360,14 @@ describe('ConnectorClient', function () {
const testFiles = await readdir(pathToTestFiles);
const testInstances = await Promise.all(testFiles.map(async testFile => {
const buffer = await readFile(path.join(pathToTestFiles, testFile));
const content = JSON.parse(buffer.toString());
const testInstances = await Promise.all(
testFiles.map(async testFile => {
const buffer = await readFile(path.join(pathToTestFiles, testFile));
const content = JSON.parse(buffer.toString());
return content.instance;
}));
return content.instance;
}),
);
for (const testInstance of testInstances) {
const checkInstance = clone()(testInstance);

View File

@@ -33,9 +33,9 @@ import {createFileSync} from 'fs-extra';
// eslint-disable-next-line unicorn/prevent-abbreviations
import {e2eRun, getItemsFromSamples, ApiError, HttpClient, RequestOptions, Response} from '../src/index.js';
import {RecursivePartial} from './client.spec.js';
import {expect} from "chai";
import path from "path";
import {fileURLToPath} from "url";
import {expect} from 'chai';
import path from 'path';
import {fileURLToPath} from 'url';
chai.should();
chai.use(chaiSpies);
@@ -184,14 +184,18 @@ describe('e2e Connector', function () {
if (!existsSync(emptyDirectoryPath)) {
mkdirSync(emptyDirectoryPath);
}
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: emptyDirectoryPath}).should.be.rejectedWith(
'Could not index samples. None were retrieved from the file system.',
);
await e2eRun(httpClient, {
to: 'http://localhost',
samplesLocation: emptyDirectoryPath,
}).should.be.rejectedWith('Could not index samples. None were retrieved from the file system.');
rmdirSync(emptyDirectoryPath);
});
it('should fail to index directory without json data', async function () {
const somewhatFilledDirectoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'somewhatFilledDir');
const somewhatFilledDirectoryPath = path.join(
path.dirname(fileURLToPath(import.meta.url)),
'somewhatFilledDir',
);
if (!existsSync(somewhatFilledDirectoryPath)) {
mkdirSync(somewhatFilledDirectoryPath);
}

View File

@@ -21,7 +21,7 @@ import {HttpClient} from '../src/index.js';
describe('HttpClient', function () {
afterEach(function () {
nock.cleanAll();
})
});
it('should construct', function () {
expect(() => {

View File

@@ -19,9 +19,9 @@ import {expect} from 'chai';
import chaiSpies from 'chai-spies';
import {HttpClient} from '../src/index.js';
import {TestPlugin} from './plugin-resources/test-plugin.js';
import path from "path";
import {readFile} from "fs/promises";
import {fileURLToPath} from "url";
import path from 'path';
import {readFile} from 'fs/promises';
import {fileURLToPath} from 'url';
chai.use(chaiSpies);
@@ -56,12 +56,12 @@ describe('Plugin', function () {
'',
'',
);
})
});
afterEach(async function () {
await testPlugin.close();
sandbox.restore();
})
});
it('should construct', async function () {
const converter = new Converter(

View File

@@ -36,13 +36,14 @@ export class Validator {
*/
private readonly ajv = new Ajv.default({
verbose: true,
allowUnionTypes: true,
code: {regExp: re2 as never},
});
/**
* Map of schema names to schemas
*/
private readonly schemas: { [type: string]: Schema } = {};
private readonly schemas: {[type: string]: Schema} = {};
/**
* A wrapper function for Ajv that transforms the error into the compatible old error
@@ -94,7 +95,7 @@ export class Validator {
if (schema === undefined) {
if (isThingWithType(instance)) {
// schema name can be inferred from type string
const schemaSuffix = (instance as { type: string }).type
const schemaSuffix = (instance as {type: string}).type
.split(' ')
.map((part: string) => {
return part.slice(0, 1).toUpperCase() + part.slice(1);
@@ -178,7 +179,10 @@ export async function validateFiles(
await v.addSchemas(schemaDirectory);
// get a list of files to test
const testFiles = await glob(path.posix.join(resourcesDirectory.replaceAll(path.sep, path.posix.sep), '*.json'), {absolute: true});
const testFiles = await glob(
path.posix.join(resourcesDirectory.replaceAll(path.sep, path.posix.sep), '*.json'),
{absolute: true},
);
if (testFiles.length === 0) {
throw new Error(`No test files in ${resourcesDirectory}!`);

View File

@@ -8,7 +8,10 @@ describe('Schema', function () {
this.slow(10_000);
it('should validate against test files', async function () {
const errorsPerFile = await validateFiles(path.resolve('lib', 'schema'), path.resolve('test', 'resources'));
const errorsPerFile = await validateFiles(
path.resolve('lib', 'schema'),
path.resolve('test', 'resources'),
);
await mkdir('report', {recursive: true});
await writeReport(path.join('report', 'index.html'), errorsPerFile);