"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CypressTestRunner = void 0;
const lib_1 = require("tnp-core/lib");
const lib_2 = require("tnp-core/lib");
const lib_3 = require("tnp-helpers/lib");
const constants_1 = require("../../../../../../constants");
const base_test_runner_1 = require("./base-test-runner");
class CypressTestRunner extends base_test_runner_1.BaseTestRunner {
    fileCommand(files) {
        return this.getCommonFilePattern('e2e', files, ['.e2e.ts', '.e2e.tsx']);
    }
    async start(files, debug = false) {
        let command;
        command = command =
            `npm-run mocha  ${debug ? '--inspect' : ''} --require ts-node/register ${this.fileCommand(files)} ` +
                ` --timeout ${constants_1.UNIT_TEST_TIMEOUT} `;
        this.project.run(command, { output: true }).sync();
    }
    async startAndWatch(files, debug = false) {
        if (this.project.typeIsNot(lib_1.LibTypeEnum.ISOMORPHIC_LIB)) {
            lib_3.Helpers.error(`Tests not impolemented for ${this.project.type}`, false, true);
        }
        let command = `npm-run mocha  ${debug ? '--inspect' : ''} --require ts-node/register ${this.fileCommand(files)} ` +
            `--watch --watch-files src/tests/**/* --timeout ${constants_1.UNIT_TEST_TIMEOUT} `;
        command = lib_3.Helpers._fixCommand(command);
        lib_3.Helpers.run(command, {
            stdio: ['pipe', 'pipe', 'pipe'],
            // env: { ...process.env, FORCE_COLOR: '1' },
            cwd: this.project.location,
        }).async();
    }
}
exports.CypressTestRunner = CypressTestRunner;
function remoteAtFromCallStack(s) {
    // let oneExPass = false;
    return s
        .split('\n')
        .map(l => {
        // if (l.trim().startsWith('at ')) { // TODO hmmm i think I don't need this.. long call stack ok when no fail
        //   if (oneExPass) {
        //     return void 0;
        //   } else {
        //     oneExPass = true;
        //   }
        // }
        return l;
    })
        .filter(l => !lib_2._.isUndefined(l))
        .join('\n')
        .trim();
}
//# sourceMappingURL=cypress-test-runner.js.map