"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const findNode_1 = require("../typescript/findNode");
const isTypedTestTestInterface_1 = require("../typescript/isTypedTestTestInterface");
const parseTestMetadata_1 = require("./parseTestMetadata");
const makeAbsolute_1 = require("../common/makeAbsolute");
function findMetadataFromProgram(sourcePaths, program) {
    return __awaiter(this, void 0, void 0, function* () {
        const { currentDirectory, typeChecker, sourceFiles } = programData(program);
        const absoluteSourcePaths = sourcePaths.map(x => makeAbsolute_1.makeAbsolute(currentDirectory, x));
        const typedTestInterface = yield findNode_1.findNode(isTypedTestTestInterface_1.isTypedTestTestInterface(typeChecker), sourceFiles);
        const typedTestSymbol = typeChecker.getTypeAtLocation(typedTestInterface).getSymbol();
        const userSourceFiles = sourceFiles.filter(({ fileName }) => path_1.isAbsolute(fileName)
            ? absoluteSourcePaths.includes(fileName)
            : absoluteSourcePaths.includes(path_1.join(currentDirectory, fileName)));
        return parseTestMetadata_1.parseTestMetadata(userSourceFiles, typedTestSymbol, typeChecker).map(m => (Object.assign({}, m, { filePath: makeAbsolute_1.makeAbsolute(currentDirectory, m.filePath) })));
    });
}
exports.findMetadataFromProgram = findMetadataFromProgram;
function programData(program) {
    return {
        typeChecker: program.getTypeChecker(),
        currentDirectory: program.getCurrentDirectory(),
        sourceFiles: program.getSourceFiles(),
    };
}
//# sourceMappingURL=findMetadataFromProgram.js.map