"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    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) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const cli_core_1 = require("@igniteui/cli-core");
const command = {
    // tslint:disable:object-literal-sort-keys
    command: "test",
    desc: "executes project tests",
    builder: {
        e2e: {
            describe: "Executes end-to-end tests",
            type: "boolean"
        }
    },
    execute(argv) {
        return __awaiter(this, void 0, void 0, function* () {
            cli_core_1.GoogleAnalytics.post({
                t: "screenview",
                cd: "Test"
            });
            command.test(argv);
        });
    },
    test(argv) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!cli_core_1.ProjectConfig.hasLocalConfig()) {
                cli_core_1.Util.error("Test command is supported only on existing project created with igniteui-cli", "red");
                return;
            }
            const project = cli_core_1.ProjectConfig.getConfig().project;
            if (!argv.skipAnalytics) {
                cli_core_1.GoogleAnalytics.post({
                    t: "event",
                    ec: "$ig test",
                    ea: `e2e: ${argv.e2e};`,
                    cd1: project.framework,
                    cd2: project.projectType,
                    cd11: !!project.skipGit,
                    cd14: project.theme
                });
            }
            if (argv.e2e && project.framework === "angular" && project.projectType === "igx-ts") {
                cli_core_1.Util.execSync("npm run e2e", { stdio: "inherit" });
            }
            else {
                cli_core_1.Util.execSync("npm test", { stdio: "inherit" });
            }
        });
    }
};
exports.default = command;
