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());
    });
};
import { isAbsolute, join } from 'path';
import { findNode } from '../typescript/findNode';
import { isTypedTestTestInterface } from '../typescript/isTypedTestTestInterface';
import { parseTestMetadata } from './parseTestMetadata';
import { makeAbsolute } from '../common/makeAbsolute';
export function findMetadataFromProgram(sourcePaths, program) {
    return __awaiter(this, void 0, void 0, function* () {
        const { currentDirectory, typeChecker, sourceFiles } = programData(program);
        const absoluteSourcePaths = sourcePaths.map(x => makeAbsolute(currentDirectory, x));
        const typedTestInterface = yield findNode(isTypedTestTestInterface(typeChecker), sourceFiles);
        const typedTestSymbol = typeChecker.getTypeAtLocation(typedTestInterface).getSymbol();
        const userSourceFiles = sourceFiles.filter(({ fileName }) => isAbsolute(fileName)
            ? absoluteSourcePaths.includes(fileName)
            : absoluteSourcePaths.includes(join(currentDirectory, fileName)));
        return parseTestMetadata(userSourceFiles, typedTestSymbol, typeChecker).map(m => (Object.assign({}, m, { filePath: makeAbsolute(currentDirectory, m.filePath) })));
    });
}
function programData(program) {
    return {
        typeChecker: program.getTypeChecker(),
        currentDirectory: program.getCurrentDirectory(),
        sourceFiles: program.getSourceFiles(),
    };
}
//# sourceMappingURL=findMetadataFromProgram.js.map