"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 });
exports.HotTestDriver = void 0;
/**
 * This actually executes the tests.
 */
class HotTestDriver {
    constructor(processor, page = null) {
        this.processor = processor;
        this.tester = null;
        this.page = page;
        this.commandDelay = 20;
        this.pageTestDelay = 700;
        this.persistentData = {};
    }
    /**
     * Get a test object by it's name. If a * is used, it will be used as a
     * wildcard for the object's name. If a > is used, then the name will
     * be treated as a CSS selector.
     */
    parseTestObject(name) {
        let pos = name.indexOf("*");
        let wildcard = "";
        if (pos > -1) {
            name = name.replace(/\*/, "");
            wildcard = "*";
        }
        let selector = `[data-test-object-name${wildcard}='${name}']`;
        if (name.length > 0) {
            if (name[0] === ">") {
                name = name.substring(1);
                selector = name;
            }
        }
        return (selector);
    }
    /**
     * Wait for a number of milliseconds.
     */
    wait(numMilliseconds) {
        return __awaiter(this, void 0, void 0, function* () {
            return (new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve();
                }, numMilliseconds);
            }));
        });
    }
    /**
     * Print a message.
     */
    print(message) {
        return __awaiter(this, void 0, void 0, function* () {
            process.stdout.write(message);
        });
    }
    /**
     * Print a message line.
     */
    println(message) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.print(`${message}\n`);
        });
    }
    /**
     * Disconnect this server or destroy anything associated with this HotTestDriver.
     */
    destroy() {
        return __awaiter(this, void 0, void 0, function* () {
        });
    }
    /**
     * An expression to test.
     */
    assert(value_1) {
        return __awaiter(this, arguments, void 0, function* (value, errorMessage = "") {
            if (!(value))
                throw new Error(errorMessage);
        });
    }
}
exports.HotTestDriver = HotTestDriver;
//# sourceMappingURL=HotTestDriver.js.map