"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const collectByKey_1 = require("../common/collectByKey");
const flatten_1 = require("../common/flatten");
function collectTests(cwd, testMetadata) {
    const metadataByFilePath = collectByKey_1.collectByKey(x => joinIfNotAbsolute(cwd, x.filePath), testMetadata);
    const filePaths = Object.keys(metadataByFilePath);
    return flatten_1.flatten(filePaths.map(filePath => testsWithMetadata(filePath, metadataByFilePath[filePath])));
}
exports.collectTests = collectTests;
function joinIfNotAbsolute(cwd, filePath) {
    return path_1.isAbsolute(filePath) ? filePath : path_1.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