import path from "node:path";
import esbuild from "esbuild";
import { rimrafSync } from "rimraf";
import { TEST_IN_FOLDER, TEST_OUT_FOLDER } from "../common/constants.js";
import { logger } from "../common/logger.js";
import { generateBuildOptionsForTest } from "./esbuild-config.js";
import { runTests } from "./invoke-test.js";
import { findTestFiles } from "./test-files.js";
export async function test(argv) {
    const normalizedDir = path.resolve(argv.dir);
    const testDir = path.join(normalizedDir, TEST_OUT_FOLDER);
    rimrafSync(testDir);
    const result = await esbuild.build({
        ...generateBuildOptionsForTest(argv),
        entryPoints: findTestFiles(argv.dir),
    });
    if (result.warnings.length > 0) {
        logger.debug(result.warnings);
    }
    if (result.errors.length > 0) {
        logger.error(result.errors, `Failed to build the test files in ${argv.dir}/${TEST_IN_FOLDER}`);
    }
    else {
        const { exitCode } = await runTests(argv);
        process.exit(exitCode);
    }
}
//# sourceMappingURL=handler.js.map