"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.desc = exports.command = exports.builder = void 0;
const utils_1 = require("../utils");
const utils_2 = require("@syftdata/common/lib/utils");
const glob = require("glob");
const puppeteer_1 = require("../replay/puppeteer");
const builder = (y) => {
    return y
        .option('test-specs', {
        describe: 'folder with test specs.',
        default: (0, utils_1.getTestSpecFolder)(),
        type: 'string'
    })
        .option('headless', {
        describe: 'Enable headless mode',
        default: true,
        type: 'boolean'
    });
};
exports.builder = builder;
exports.command = 'test';
exports.desc = 'Run your event tests';
async function handler({ testSpecs, headless }) {
    const files = glob.sync(`${testSpecs}/**/*`, {
        nodir: true
    });
    const successPromises = files.map(async (filePath) => {
        (0, utils_2.logVerbose)(`Running test in: ${filePath}`);
        return await (0, puppeteer_1.verifyPuppeteerTest)(filePath, headless);
    });
    const successes = await Promise.all(successPromises);
    if (successes.every((success) => success)) {
        (0, utils_2.logInfo)(':sparkles: All tests are passed');
    }
    else {
        process.exit(1);
    }
}
exports.handler = handler;
