diff --git a/core/test/vitest.global-setup.ts b/core/test/vitest.global-setup.ts new file mode 100644 index 000000000..c1194e3d1 --- /dev/null +++ b/core/test/vitest.global-setup.ts @@ -0,0 +1,11 @@ +import fs from "fs"; +import path from "path"; + +// Sets up the GLOBAL directory for testing - equivalent to ~/.continue +// IMPORTANT: the CONTINUE_GLOBAL_DIR environment variable is used in utils/paths for getting all local paths +export default async function () { + process.env.CONTINUE_GLOBAL_DIR = path.join(__dirname, ".continue-test"); + if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR)) { + fs.rmdirSync(process.env.CONTINUE_GLOBAL_DIR, { recursive: true }); + } +} diff --git a/core/test/vitest.setup.ts b/core/test/vitest.setup.ts new file mode 100644 index 000000000..f1a1e5643 --- /dev/null +++ b/core/test/vitest.setup.ts @@ -0,0 +1,32 @@ +import { TextDecoder, TextEncoder } from "util"; + +import fetch, { Request, Response } from "node-fetch"; +import { beforeAll } from "vitest"; + +// if (process.env.DEBUG === "jest") { +// jest.setTimeout(5 * 60 * 1000); +// } + +beforeAll(() => { + // @ts-ignore + globalThis.fetch = fetch; + // @ts-ignore + globalThis.Request = Request; + // @ts-ignore + globalThis.Response = Response; + globalThis.TextEncoder = TextEncoder; + // @ts-ignore + globalThis.TextDecoder = TextDecoder; +}); + +// https://github.com/mswjs/msw/issues/1576#issuecomment-1482643055 + +// TODO - currently causing tests to fail because sqlite is still running for some reason +// const clearTestDirectory = () => { +// if (fs.existsSync(process.env.CONTINUE_GLOBAL_DIR!)) { +// fs.rmSync(process.env.CONTINUE_GLOBAL_DIR!, { recursive: true }); +// } +// }; + +// globalThis.beforeAll(clearTestDirectory); +// globalThis.afterAll(clearTestDirectory); diff --git a/core/vitest.config.ts b/core/vitest.config.ts index d2394ad50..603d3f643 100644 --- a/core/vitest.config.ts +++ b/core/vitest.config.ts @@ -2,6 +2,12 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - include: ["**/*.vitest.ts"], + testTransformMode: { + web: ["/.[jt]s?$/"], + ssr: ["/.[jt]s?$/"], + }, + globalSetup: "./test/vitest.global-setup.ts", + setupFiles: "./test/vitest.setup.ts", + include: ["**/*.test.ts"], }, });