add .global-setup and .setup files
- also include .test.ts files for vitest config
This commit is contained in:
parent
2e2c5eb638
commit
577c1a8643
3 changed files with 50 additions and 1 deletions
11
core/test/vitest.global-setup.ts
Normal file
11
core/test/vitest.global-setup.ts
Normal file
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
32
core/test/vitest.setup.ts
Normal file
32
core/test/vitest.setup.ts
Normal file
|
|
@ -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);
|
||||
|
|
@ -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"],
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue