"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const Project_1 = require("../app/Project");
const CartoApp_1 = require("../app/CartoApp");
const NodeStorage_1 = require("../local/NodeStorage");
const Database_1 = require("../minecraft/Database");
const LocalEnvironment_1 = require("../local/LocalEnvironment");
const StorageUtilities_1 = require("../storage/StorageUtilities");
const child_process_1 = require("child_process");
const stringio_1 = require("@rauschma/stringio");
const fs = require("fs");
const Utilities_1 = require("../core/Utilities");
const axios_1 = require("axios");
const ProjectInfoSet_1 = require("../info/ProjectInfoSet");
const IProjectInfoData_1 = require("../info/IProjectInfoData");
const ProjectUtilities_1 = require("../app/ProjectUtilities");
const TestUtilities_1 = require("./TestUtilities");
CartoApp_1.default.hostType = CartoApp_1.HostType.testLocal;
let carto = undefined;
let localEnv = undefined;
let scenariosFolder = undefined;
let resultsFolder = undefined;
let sampleFolder = undefined;
localEnv = new LocalEnvironment_1.default(false);
(async () => {
    CartoApp_1.default.localFolderExists = _localFolderExists;
    CartoApp_1.default.ensureLocalFolder = _ensureLocalFolder;
    const testRootPath = NodeStorage_1.default.ensureEndsWithDelimiter(__dirname) + "/../../test/";
    const sampleContentRootPath = NodeStorage_1.default.ensureEndsWithDelimiter(__dirname) + "/../../../";
    const scenariosStorage = new NodeStorage_1.default(testRootPath, "scenarios");
    scenariosFolder = scenariosStorage.rootFolder;
    await scenariosFolder.ensureExists();
    const resultsStorage = new NodeStorage_1.default(testRootPath, "results");
    resultsFolder = resultsStorage.rootFolder;
    await resultsFolder.ensureExists();
    const sampleContentStorage = new NodeStorage_1.default(sampleContentRootPath, "samplecontent");
    sampleFolder = sampleContentStorage.rootFolder;
    await sampleFolder.ensureExists();
    CartoApp_1.default.prefsStorage = new NodeStorage_1.default(localEnv.utilities.testWorkingPath + "prefs" + NodeStorage_1.default.platformFolderDelimiter, "");
    CartoApp_1.default.projectsStorage = new NodeStorage_1.default(localEnv.utilities.testWorkingPath + "projects" + NodeStorage_1.default.platformFolderDelimiter, "");
    CartoApp_1.default.packStorage = new NodeStorage_1.default(localEnv.utilities.testWorkingPath + "packs" + NodeStorage_1.default.platformFolderDelimiter, "");
    CartoApp_1.default.worldStorage = new NodeStorage_1.default(localEnv.utilities.testWorkingPath + "worlds" + NodeStorage_1.default.platformFolderDelimiter, "");
    CartoApp_1.default.deploymentStorage = new NodeStorage_1.default(localEnv.utilities.testWorkingPath + "deployment" + NodeStorage_1.default.platformFolderDelimiter, "");
    CartoApp_1.default.workingStorage = new NodeStorage_1.default(localEnv.utilities.testWorkingPath + "working" + NodeStorage_1.default.platformFolderDelimiter, "");
    const coreStorage = new NodeStorage_1.default(__dirname + "/../../public/data/content/", "");
    Database_1.default.contentFolder = coreStorage.rootFolder;
    await CartoApp_1.default.init(); // carto app init does something here that, if removed, causes these tests to fail. Also, await needs to be here.
    carto = CartoApp_1.default.carto;
    if (!carto) {
        return;
    }
    await carto.load();
})();
function _ensureLocalFolder(path) {
    const ls = new NodeStorage_1.default(path, "");
    return ls.rootFolder;
}
async function _localFolderExists(path) {
    const ls = new NodeStorage_1.default(path, "");
    return await ls.rootFolder.exists();
}
function removeResultFolder(scenarioName) {
    if (resultsFolder) {
        const path = StorageUtilities_1.default.ensureEndsWithDelimiter(resultsFolder.fullPath) +
            StorageUtilities_1.default.ensureEndsWithDelimiter(scenarioName);
        const exists = fs.existsSync(path);
        if (exists && !StorageUtilities_1.default.isPathRiskyForDelete(path))
            try {
                fs.rmSync(path, {
                    recursive: true,
                });
            }
            catch (e) {
                console.log("Error occurred during rmSync on '" + path + "'");
                throw e;
            }
    }
}
function ensureResultFolder(scenarioName) {
    if (resultsFolder) {
        const path = StorageUtilities_1.default.ensureEndsWithDelimiter(resultsFolder.fullPath) +
            StorageUtilities_1.default.ensureEndsWithDelimiter(scenarioName);
        if (!fs.existsSync(path))
            // @ts-ignore
            fs.mkdirSync(path, {
                recursive: true,
            });
    }
}
describe("worldCommand", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(10000);
        removeResultFolder("worldCommand");
        ensureResultFolder("worldCommand");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "world",
            "set",
            "-i",
            "./test/results/worldCommand",
            "-betaapis",
            "-o",
            "./test/results/worldCommand/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async () => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
    }).timeout(10000);
    it("exit code should be zero", async () => {
        chai_1.assert.equal(exitCode, 0);
    }).timeout(10000);
    it("output matches", async () => {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "worldCommand");
    });
});
describe("serveCommandValidate", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    let process = null;
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("serveCommandValidate");
        const passcode = Utilities_1.default.createUuid().substring(0, 8);
        if (!sampleFolder) {
            throw new Error("Sample folder does not exist.");
        }
        sampleFolder
            .ensureFileFromRelativePath("/addon/build/packages/aop_moremobs_animationmanifesterrors.zip")
            .then((sampleFile) => {
            console.log("Starting web server.");
            process = (0, child_process_1.spawn)("node", [
                " ./../toolbuild/jsn/cli",
                "serve",
                "basicwebservices",
                "localhost",
                "6126",
                "-lv",
                "-once",
                "-updatepc",
                passcode,
            ]);
            collectLines(process.stdout, stdoutLines);
            collectLines(process.stderr, stderrLines);
            sampleFile.loadContent().then(() => {
                const content = sampleFile.content;
                Utilities_1.default.sleep(3000).then(() => {
                    console.log("Making validation web request to http://localhost:6126/api/validate/ " + content?.length + " bytes");
                    axios_1.default
                        .post("http://localhost:6126/api/validate/", content, {
                        headers: { mctpc: passcode, "content-type": "application/zip" },
                        method: "POST",
                    })
                        .then((response) => {
                        (0, TestUtilities_1.ensureReportJsonMatchesScenario)(scenariosFolder, resultsFolder, response.data, "serveCommandValidate");
                        if (response === undefined) {
                            throw new Error("Could not connect to server.");
                        }
                        if (process) {
                            process.on("exit", (code) => {
                                exitCode = code;
                                process = null;
                                done();
                            });
                        }
                    });
                });
            });
        });
    });
    it("should have no stderr lines", async () => {
        if (process) {
            process.kill();
            process = null;
        }
        chai_1.assert.equal(stderrLines.length, 0, "Error: " + stderrLines.join("\n") + "|");
    }).timeout(10000);
    it("exit code should be zero", async () => {
        if (process) {
            process.kill();
            process = null;
        }
        chai_1.assert.equal(exitCode, 0);
    }).timeout(10000);
    it("output matches", async () => {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "serveCommandValidate");
    });
    after(function () {
        if (process) {
            console.log("Ending web process in serverCommandValidate after function.");
            process.kill();
            process = null;
        }
    });
});
describe("serveCommandValidateAddon", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    let process = null;
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("serveCommandValidateAddon");
        const passcode = Utilities_1.default.createUuid().substring(0, 8);
        if (!sampleFolder) {
            throw new Error("Sample folder does not exist.");
        }
        sampleFolder
            .ensureFileFromRelativePath("/addon/build/packages/aop_moremobs_animationmanifesterrors.zip")
            .then((sampleFile) => {
            console.log("Starting web server.");
            process = (0, child_process_1.spawn)("node", [
                " ./../toolbuild/jsn/cli",
                "serve",
                "basicwebservices",
                "localhost",
                "6126",
                "-lv",
                "-once",
                "-updatepc",
                passcode,
            ]);
            collectLines(process.stdout, stdoutLines);
            collectLines(process.stderr, stderrLines);
            sampleFile.loadContent().then(() => {
                const content = sampleFile.content;
                Utilities_1.default.sleep(3000).then(() => {
                    console.log("Making validation web request to http://localhost:6126/api/validate/ " + content?.length + " bytes");
                    axios_1.default
                        .post("http://localhost:6126/api/validate/", content, {
                        headers: { mctpc: passcode, "content-type": "application/zip", mctsuite: "addon" },
                        method: "POST",
                    })
                        .then((response) => {
                        (0, TestUtilities_1.ensureReportJsonMatchesScenario)(scenariosFolder, resultsFolder, response.data, "serveCommandValidateAddon");
                        if (response === undefined) {
                            throw new Error("Could not connect to server.");
                        }
                        if (process) {
                            process.on("exit", (code) => {
                                exitCode = code;
                                process = null;
                                done();
                            });
                        }
                    });
                });
            });
        });
    });
    it("should have no stderr lines", async () => {
        if (process) {
            process.kill();
            process = null;
        }
        chai_1.assert.equal(stderrLines.length, 0, "Error: " + stderrLines.join("\n") + "|");
    }).timeout(10000);
    it("exit code should be zero", async () => {
        if (process) {
            process.kill();
            process = null;
        }
        chai_1.assert.equal(exitCode, 0);
    }).timeout(10000);
    it("output matches", async () => {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "serveCommandValidateAddon");
    });
    after(function () {
        if (process) {
            console.log("Ending web process in serverCommandValidateAddon after function.");
            process.kill();
            process = null;
        }
    });
});
describe("serveCommandValidateAdvanced", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    let process = null;
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("serveCommandValidateAdvanced");
        const passcode = Utilities_1.default.createUuid().substring(0, 8);
        if (!sampleFolder) {
            throw new Error("Sample folder does not exist.");
        }
        sampleFolder
            .ensureFileFromRelativePath("/addon/build/packages/aop_moremobs_advanced.zip")
            .then((sampleFile) => {
            console.log("Starting web server.");
            process = (0, child_process_1.spawn)("node", [
                " ./../toolbuild/jsn/cli",
                "serve",
                "basicwebservices",
                "localhost",
                "6126",
                "-lv",
                "-once",
                "-updatepc",
                passcode,
            ]);
            collectLines(process.stdout, stdoutLines);
            collectLines(process.stderr, stderrLines);
            sampleFile.loadContent().then(() => {
                const content = sampleFile.content;
                Utilities_1.default.sleep(3000).then(() => {
                    console.log("Making validation web request to http://localhost:6126/api/validate/ " + content?.length + " bytes");
                    axios_1.default
                        .post("http://localhost:6126/api/validate/", content, {
                        headers: { mctpc: passcode, "content-type": "application/zip", mctsuite: "all" },
                        method: "POST",
                    })
                        .then((response) => {
                        (0, TestUtilities_1.ensureReportJsonMatchesScenario)(scenariosFolder, resultsFolder, response.data, "serveCommandValidateAdvanced");
                        if (response === undefined) {
                            throw new Error("Could not connect to server.");
                        }
                        if (process) {
                            process.on("exit", (code) => {
                                exitCode = code;
                                process = null;
                                done();
                            });
                        }
                    });
                });
            });
        });
    });
    it("should have no stderr lines", async () => {
        if (process) {
            process.kill();
            process = null;
        }
        chai_1.assert.equal(stderrLines.length, 0, "Error: " + stderrLines.join("\n") + "|");
    }).timeout(10000);
    it("exit code should be zero", async () => {
        if (process) {
            process.kill();
            process = null;
        }
        chai_1.assert.equal(exitCode, 0);
    }).timeout(10000);
    it("output matches", async () => {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "serveCommandValidateAdvanced");
    });
    after(function () {
        if (process) {
            console.log("Ending web process in serverCommandValidateAdvanced after function.");
            process.kill();
            process = null;
        }
    });
});
describe("createCommandAddonStarter", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    let project = null;
    let allProjectInfoSet = null;
    let addonProjectInfoSet = null;
    before(function (done) {
        this.timeout(10000);
        removeResultFolder("createCommandAddonStarter");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "create",
            "testerName",
            "addonStarter",
            "testerCreatorName",
            "testerDescription",
            "-o",
            "./test/results/createCommandAddonStarter/",
            "-internalOnlyRunningInTheContextOfTestCommandLines",
            "yes",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            (0, chai_1.assert)(carto, "Carto is not properly initialized");
            project = new Project_1.default(carto, "createCommandAddonStarter", null);
            // exclude eslint because we know the .ts comes with some warnings due to
            // the starter TS having some unused variables.
            allProjectInfoSet = new ProjectInfoSet_1.default(project, IProjectInfoData_1.ProjectInfoSuite.default);
            addonProjectInfoSet = new ProjectInfoSet_1.default(project, IProjectInfoData_1.ProjectInfoSuite.cooperativeAddOn);
            project.autoDeploymentMode = Project_1.ProjectAutoDeploymentMode.noAutoDeployment;
            project.localFolderPath = __dirname + "/../../test/results/createCommandAddonStarter/";
            project.inferProjectItemsFromFiles().then(() => {
                (0, chai_1.assert)(project);
                ProjectUtilities_1.default.setIsAddon(project).then(() => {
                    (0, chai_1.assert)(allProjectInfoSet);
                    allProjectInfoSet.generateForProject().then(() => {
                        (0, chai_1.assert)(addonProjectInfoSet);
                        addonProjectInfoSet.generateForProject().then(() => {
                            done();
                        });
                    });
                });
            });
        });
    });
    it("should have no stderr lines", async () => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
    }).timeout(10000);
    it("exit code should be zero", async () => {
        chai_1.assert.equal(exitCode, 0);
    }).timeout(10000);
    it("should have 17 project items", async () => {
        (0, chai_1.assert)(project);
        chai_1.assert.equal(project.items.length, 17);
    }).timeout(10000);
    it("main validation should have 0 errors, failures, or warnings", async () => {
        (0, chai_1.assert)(allProjectInfoSet);
        chai_1.assert.equal(allProjectInfoSet.errorFailWarnCount, 0, allProjectInfoSet.errorFailWarnString);
    }).timeout(10000);
    it("addon validation should have 0 errors, failures, or warnings", async () => {
        (0, chai_1.assert)(addonProjectInfoSet);
        chai_1.assert.equal(addonProjectInfoSet.errorFailWarnCount, 0, addonProjectInfoSet.errorFailWarnString);
    }).timeout(10000);
    it("output matches", async () => {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "createCommandAddonStarter", ["manifest.json"]);
    });
});
describe("addLootTable", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    let project = null;
    let allProjectInfoSet = null;
    let addonProjectInfoSet = null;
    before(function (done) {
        this.timeout(10000);
        removeResultFolder("addLootTable");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "add",
            "loot_table",
            "testerName",
            "-o",
            "./test/results/addLootTable/",
            "-internalOnlyRunningInTheContextOfTestCommandLines",
            "yes",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            (0, chai_1.assert)(carto, "Carto is not properly initialized");
            project = new Project_1.default(carto, "addLootTable", null);
            // exclude eslint because we know the .ts comes with some warnings due to
            // the starter TS having some unused variables.
            allProjectInfoSet = new ProjectInfoSet_1.default(project, IProjectInfoData_1.ProjectInfoSuite.default);
            project.autoDeploymentMode = Project_1.ProjectAutoDeploymentMode.noAutoDeployment;
            project.localFolderPath = __dirname + "/../../test/results/addLootTable/";
            project.inferProjectItemsFromFiles().then(() => {
                (0, chai_1.assert)(project);
                (0, chai_1.assert)(allProjectInfoSet);
                allProjectInfoSet.generateForProject().then(() => {
                    done();
                });
            });
        });
    });
    it("should have no stderr lines", async () => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
    }).timeout(10000);
    it("exit code should be zero", async () => {
        chai_1.assert.equal(exitCode, 0);
    }).timeout(10000);
    it("should have 1 project item", async () => {
        (0, chai_1.assert)(project);
        chai_1.assert.equal(project.items.length, 1);
    }).timeout(10000);
    it("main validation should have 2 errors (which is expected, no manifest exists)", async () => {
        (0, chai_1.assert)(allProjectInfoSet);
        chai_1.assert.equal(allProjectInfoSet.errorFailWarnCount, 2, allProjectInfoSet.errorFailWarnString);
    }).timeout(10000);
    it("output matches", async () => {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "addLootTable", ["manifest.json"]);
    });
});
describe("validateAddons1WellFormedCommand", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(10000);
        removeResultFolder("validateAddons1WellFormedCommand");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "addon",
            "-i",
            "./../samplecontent/addon/build/content1",
            "-o",
            "./test/results/validateAddons1WellFormedCommand/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", function (done) {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", function (done) {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateAddons1WellFormedCommand");
    }).timeout(10000);
});
describe("validateAddons2AnimationManifestErrorsCommand", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(10000);
        removeResultFolder("validateAddons2AnimationManifestErrorsCommand");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "addon",
            "-i",
            "./../samplecontent/addon/build/content2",
            "-o",
            "./test/results/validateAddons2AnimationManifestErrorsCommand/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateAddons2AnimationManifestErrorsCommand");
    }).timeout(10000);
});
describe("validateAddons3ExtraneousStuffUsesMinecraftCommand", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("validateAddons3ExtraneousStuffUsesMinecraftCommand");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "addon",
            "-i",
            "./../samplecontent/addon/build/content3",
            "-o",
            "./test/results/validateAddons3ExtraneousStuffUsesMinecraftCommand/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateAddons3ExtraneousStuffUsesMinecraftCommand");
    });
});
describe("validateAddons3PlatformVersions", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("validateAddons3PlatformVersions");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "currentplatform",
            "-i",
            "./../samplecontent/addon/build/content3",
            "-o",
            "./test/results/validateAddons3PlatformVersions/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateAddons3PlatformVersions");
    });
});
describe("deployCommand", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(10000);
        removeResultFolder("deployCommand");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "deploy",
            "folder",
            "-i",
            "./../samplecontent/simple/",
            "-o",
            "./test/results/deployCommand/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async () => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
    });
    it("exit code should be zero", async () => {
        chai_1.assert.equal(exitCode, 0);
    });
    it("output matches", async () => {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "deployCommand");
    });
});
describe("validateLinkErrors", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("validateLinkErrors");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "all",
            "-i",
            "./../samplecontent/addon/build/content_linkerrors",
            "-o",
            "./test/results/validateLinkErrors/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateLinkErrors");
    });
});
describe("validateVibrantVisuals", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("validateVibrantVisuals");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "all",
            "-i",
            "./../samplecontent/addon/build/content_vibrantvisuals",
            "-o",
            "./test/results/validateVibrantVisuals/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateVibrantVisuals");
    });
});
describe("validateComprehensiveContent", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("validateComprehensiveContent");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "addon",
            "-i",
            "./../samplecontent/comprehensive",
            "-o",
            "./test/results/validateComprehensiveContent/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateComprehensiveContent");
    });
});
describe("validateBehaviorPackOnly", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("validateBehaviorPackOnly");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "addon",
            "-i",
            "./../samplecontent/behavior_pack_only",
            "-o",
            "./test/results/validateBehaviorPackOnly/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateBehaviorPackOnly");
    });
});
describe("validateResourcePackOnly", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(20000);
        removeResultFolder("validateResourcePackOnly");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "val",
            "addon",
            "-i",
            "./../samplecontent/resource_pack_only",
            "-o",
            "./test/results/validateResourcePackOnly/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async (done) => {
        chai_1.assert.equal(stderrLines.length, 0, "Error: |" + stderrLines.join("\n") + "|");
        done();
    }).timeout(10000);
    it("exit code should be zero", async (done) => {
        chai_1.assert.equal(exitCode, 0);
        done();
    }).timeout(10000);
    it("output matches", async function () {
        await (0, TestUtilities_1.folderMatches)(scenariosFolder, resultsFolder, "validateResourcePackOnly");
    });
});
async function collectLines(readable, data) {
    for await (const line of (0, stringio_1.chunksToLinesAsync)(readable)) {
        if (line !== undefined && line.length >= 0) {
            let lineUp = line.replace(/\\n/g, "");
            lineUp = lineUp.replace(/\\r/g, "");
            if (lineUp.indexOf("ebugger") <= 0) {
                // ignore any lines about the debugger.
                // console.log(lineUp);
                data.push(lineUp);
            }
        }
    }
}
describe("spawnRulesDependency validate", async () => {
    let exitCode = null;
    const stdoutLines = [];
    const stderrLines = [];
    before(function (done) {
        this.timeout(10000);
        removeResultFolder("spawnRulesDependency");
        const process = (0, child_process_1.spawn)("node", [
            " ./../toolbuild/jsn/cli",
            "validate",
            "-i",
            "./../samplecontent/spawnRulesDependency/",
            "-o",
            "./test/results/spawnRulesDependency/",
        ]);
        collectLines(process.stdout, stdoutLines);
        collectLines(process.stderr, stderrLines);
        process.on("exit", (code) => {
            exitCode = code;
            done();
        });
    });
    it("should have no stderr lines", async () => {
        chai_1.assert.equal(stderrLines.length, 0);
    });
    it("exit code should be zero", async () => {
        chai_1.assert.equal(exitCode, 0);
    });
});

//# sourceMappingURL=../maps/test/CommandLineTest.js.map
