/* lib/terminal/test/application/simulation - A list of command related tests for running shell simulations against the supported commands. */ import filePathDecode from "./browserUtilities/file_path_decode.js";
import node from "../../utilities/node.js";
import testEvaluation from "./evaluation.js";
import vars from "../../utilities/vars.js";
import tests from "../samples/simulation.js";
/**
 * Defines the *simulation* type test application as an object.
 * ```typescript
 * interface module_test_simulationApplication {
 *     execute: (config:config_test_execute) => void; // Executes each test case.
 *     tests  : test_item[];                          // Stores test cases.
 * }
 * ``` */ const simulation = {
    execute: function terminal_test_application_simulations_execute(config) {
        const command = filePathDecode(null, simulation.tests[config.index].command);
        simulation.tests[config.index].command = command;
        if (typeof simulation.tests[config.index].artifact === "string") {
            simulation.tests[config.index].artifact = filePathDecode(null, simulation.tests[config.index].artifact);
        }
        if (typeof simulation.tests[config.index].file === "string") {
            simulation.tests[config.index].file = filePathDecode(null, simulation.tests[config.index].file);
        }
        node.child_process.exec(`${vars.terminal.command_instruction + command} test_simulation`, {
            cwd: vars.terminal.cwd,
            maxBuffer: 2048 * 500
        }, function terminal_test_application_simulations_execution_child(errs, stdout, stdError) {
            const test = typeof simulation.tests[config.index].test === "string" ? simulation.tests[config.index].test : JSON.stringify(simulation.tests[config.index].test), error = errs === null ? "" : errs.toString();
            simulation.tests[config.index].test = filePathDecode(null, test.replace("version[command]", vars.terminal.command_instruction).replace("version[name]", vars.environment.name));
            testEvaluation({
                callback: config.complete,
                fail: config.fail,
                index: config.index,
                list: config.list,
                test: simulation.tests[config.index],
                testType: "simulation",
                values: [
                    stdout,
                    error,
                    stdError.toString()
                ]
            });
        });
    },
    tests: tests
};
export default simulation;
