"use strict";

const path = require("path");
const ProfilingPlugin = require("../lib/debug/ProfilingPlugin");

describe("Profiling Plugin", () => {
	it("should persist the passed output path", () => {
		const outputPath = path.join(__dirname, "invest_in_doge_coin");
		const plugin = new ProfilingPlugin({
			outputPath
		});
		expect(plugin.options.outputPath).toBe(outputPath);
	});

	it("should handle no options", () => {
		expect(() => {
			// eslint-disable-next-line no-new
			new ProfilingPlugin();
		}).not.toThrow();
	});

	it("should handle when unable to require the inspector", () => {
		// @ts-expect-error intentionally calling without required argument
		const profiler = new ProfilingPlugin.Profiler();
		return profiler.startProfiling();
	});

	it("should handle when unable to start a profiling session", () => {
		const profiler = new ProfilingPlugin.Profiler(
			/** @type {EXPECTED_ANY} */ ({
				Session() {
					throw new Error("Sean Larkin was here.");
				}
			})
		);

		return profiler.startProfiling();
	});

	it("handles sending a profiling message when no session", () => {
		// @ts-expect-error intentionally calling without required argument
		const profiler = new ProfilingPlugin.Profiler();
		return profiler.sendCommand(
			"randy",
			/** @type {EXPECTED_OBJECT} */ (/** @type {unknown} */ ("is awesome"))
		);
	});

	it("handles destroying when no session", () => {
		// @ts-expect-error intentionally calling without required argument
		const profiler = new ProfilingPlugin.Profiler();
		return profiler.destroy();
	});
});
