@typed/test
Version:
Testing made simple.
17 lines • 906 B
JavaScript
import { isAbsolute, join } from 'path';
import { collectByKey } from '../common/collectByKey';
import { flatten } from '../common/flatten';
export function collectTests(cwd, testMetadata) {
const metadataByFilePath = collectByKey(x => joinIfNotAbsolute(cwd, x.filePath), testMetadata);
const filePaths = Object.keys(metadataByFilePath);
return flatten(filePaths.map(filePath => testsWithMetadata(filePath, metadataByFilePath[filePath])));
}
function joinIfNotAbsolute(cwd, filePath) {
return isAbsolute(filePath) ? filePath : join(cwd, filePath);
}
// Must collect whole file at once to properly handle only/skip modifiers
function testsWithMetadata(filePath, metadataList) {
const testModule = require(filePath);
return metadataList.map(metadata => (Object.assign({}, metadata, { tests: metadata.exportNames.map(x => testModule[x]) })));
}
//# sourceMappingURL=collectTests.js.map