/* * Copyright (C) 2020 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 . */ import {readdirSync, statSync} from 'fs'; import path from 'path'; import {MapAggTest} from './mapping-model/map-agg-test.js'; import {MapAggTestOptions} from './mapping-model/map-agg-test-options.js'; describe('ES Aggregation Gen', async () => { const magAppInstance = new MapAggTest('aggregations'); /** * Expand a path to a list of all files deeply contained in it */ function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] { const fullPath = path.resolve(sourcePath); const directory = statSync(fullPath); return directory.isDirectory() ? // 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/aggregations/', file => file.endsWith('agg-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); }); } catch (error) { console.error('UNHANDLED REJECTION', (error as any).stack); process.exit(1); } } }) .timeout(20_000) .slow(10_000);