refactor: mapping generation for `Elasticsearch 8.4

This commit is contained in:
Thea Schöbl
2023-04-27 09:33:09 +00:00
committed by Rainer Killinger
parent 08ec4e4381
commit 61fee2bbf3
52 changed files with 1859 additions and 972 deletions

View File

@@ -15,8 +15,8 @@
import {Logger} from '@openstapps/logger';
import {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/MapAggTest';
import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
import {MapAggTest} from './mapping-model/map-agg-test';
import {MapAggTestOptions} from './mapping-model/map-agg-test-options';
describe('ES Mapping Gen', async () => {
const magAppInstance = new MapAggTest('mappings');
@@ -24,27 +24,36 @@ describe('ES Mapping Gen', async () => {
/**
* Expand a path to a list of all files deeply contained in it
*/
// eslint-disable-next-line unicorn/consistent-function-scoping
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
const fullPath = path.resolve(sourcePath);
const directory = statSync(fullPath);
return directory.isDirectory()
? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
))
? // eslint-disable-next-line unicorn/prefer-spread
([] as string[]).concat(
...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
),
)
: [fullPath].filter(accept);
}
for (const file of expandPathToFilesSync('./test/mapping-model/mappings/', file => file.endsWith('mapping-test.ts'))) {
for (const file of expandPathToFilesSync('./test/mapping-model/mappings/', file =>
file.endsWith('mapping-test.ts'),
)) {
try {
// eslint-disable-next-line unicorn/no-await-expression-member
const test = (await import(file))['testConfig'] as MapAggTestOptions;
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test)
})
magAppInstance.testInterfaceAgainstPath(test);
});
} catch (error) {
await Logger.error('UNHANDLED REJECTION', error.stack);
process.exit(1);
}
}
}).timeout(20_000).slow(10_000);
})
.timeout(20_000)
.slow(10_000);