import { defineConfig } from "@vscode/test-cli";
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";

const workspacePath = dirname(import.meta.dirname);
const vscodePath = join(workspacePath, ".vscode-test");
const vscodeTestPath = join(vscodePath, "launch.test.js");

if (!existsSync(vscodeTestPath)) {
  mkdirSync(vscodePath, { recursive: true });
  writeFileSync(
    vscodeTestPath,
    `// Generated by ${import.meta.filename}
// A test that intentionally waits forever and does nothing,
// so you can debug and test the VSCode extension in a clean environment.
suite("VSCode extension", function () {
  this.timeout(Number.MAX_SAFE_INTEGER);
  test("wait forever", (done) => {});
});
`,
  );
}

export default defineConfig({
  workspaceFolder: join(workspacePath, "example"),
  extensionDevelopmentPath: workspacePath,
  skipExtensionDependencies: true,
  files: vscodeTestPath,
});
