// 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";
import { startLogGrammarTests } from "./logGrammar.test";
import { startNetworkInspectorTests } from "./networkInspector.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();
        startNetworkInspectorTests();
        startActionBarTests();
        startDebugConfigurationTests();
        startCDPNodeVersionCompatibilityTests();
        startLogGrammarTests();
        startVsixExistenceTest();
    });
}
