// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import { startActionBarTests } from "./actionBar.test";
import { startExtensionActivationTests } from "./activation.test";
import { startCommandPaletteTests } from "./commands.test";
import { startDebugConfigurationTests } from "./debugConfiguration.test";
import { startFileExplorerTests } from "./fileExplorer.test";
import { startCDPNodeVersionCompatibilityTests } from "./cdpNodeVersionCompatibility.test";
import { SmokeTestLogger } from "./helper/smokeTestLogger";
import { smokeTestFail } from "./helper/utilities";
import { startPackagerTests } from "./packager.test";
import { startVsixExistenceTest } from "./vsixbuild.test";

export function startSmokeTests(setup: () => Promise<void>, cleanUp: () => Promise<void>): void {
    // Guard: if mocha BDD hooks are absent, do not attempt to register tests
    if (
        typeof (global as any).before !== "function" ||
        typeof (global as any).describe !== "function"
    ) {
        return;
    }
    before(async function () {
        try {
            await cleanUp();
            await setup();
        } catch (err) {
            await smokeTestFail(err);
        }
    });

    after(async function () {
        SmokeTestLogger.testLog("Test execution completed.");
    });

    describe("Extension smoke tests", function () {
        // Using bail, when startExtensionActivationTests() failed, skip other test cases.
        this.bail(true);
        startExtensionActivationTests();

        startCommandPaletteTests();
        startFileExplorerTests();
        startPackagerTests();
        startActionBarTests();
        startDebugConfigurationTests();
        startCDPNodeVersionCompatibilityTests();
        startVsixExistenceTest();
    });
}
