Spaces:
Running
Running
fix(config): test setup update (#1430)
Browse files* fix test setup
* exclude vite config from type check
- package.json +1 -1
- scripts/setupTest.ts +37 -0
- tsconfig.json +2 -1
- vite.config.ts +7 -2
package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11 |
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
12 |
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
13 |
"format": "prettier --plugin-search-dir . --write .",
|
14 |
-
"test": "
|
15 |
"updateLocalEnv": "node --loader ts-node/esm scripts/updateLocalEnv.ts",
|
16 |
"populate": "vite-node --options.transformMode.ssr='/.*/' scripts/populate.ts",
|
17 |
"prepare": "husky"
|
|
|
11 |
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
12 |
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
13 |
"format": "prettier --plugin-search-dir . --write .",
|
14 |
+
"test": "vitest",
|
15 |
"updateLocalEnv": "node --loader ts-node/esm scripts/updateLocalEnv.ts",
|
16 |
"populate": "vite-node --options.transformMode.ssr='/.*/' scripts/populate.ts",
|
17 |
"prepare": "husky"
|
scripts/setupTest.ts
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { vi } from "vitest";
|
2 |
+
import dotenv from "dotenv";
|
3 |
+
import { resolve } from "path";
|
4 |
+
import fs from "fs";
|
5 |
+
|
6 |
+
// Load the .env file
|
7 |
+
const envPath = resolve(__dirname, "../.env");
|
8 |
+
dotenv.config({ path: envPath });
|
9 |
+
|
10 |
+
// Read the .env file content
|
11 |
+
const envContent = fs.readFileSync(envPath, "utf-8");
|
12 |
+
|
13 |
+
// Parse the .env content
|
14 |
+
const envVars = dotenv.parse(envContent);
|
15 |
+
|
16 |
+
// Separate public and private variables
|
17 |
+
const publicEnv = {};
|
18 |
+
const privateEnv = {};
|
19 |
+
|
20 |
+
for (const [key, value] of Object.entries(envVars)) {
|
21 |
+
if (key.startsWith("PUBLIC_")) {
|
22 |
+
publicEnv[key] = value;
|
23 |
+
} else {
|
24 |
+
privateEnv[key] = value;
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
vi.mock("$env/dynamic/public", () => ({
|
29 |
+
env: publicEnv,
|
30 |
+
}));
|
31 |
+
|
32 |
+
vi.mock("$env/dynamic/private", () => ({
|
33 |
+
env: {
|
34 |
+
...privateEnv,
|
35 |
+
MONGODB_URL: "mongodb://127.0.0.1:27017/",
|
36 |
+
},
|
37 |
+
}));
|
tsconfig.json
CHANGED
@@ -10,7 +10,8 @@
|
|
10 |
"sourceMap": true,
|
11 |
"strict": true,
|
12 |
"target": "ES2018"
|
13 |
-
}
|
|
|
14 |
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
15 |
//
|
16 |
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
|
|
10 |
"sourceMap": true,
|
11 |
"strict": true,
|
12 |
"target": "ES2018"
|
13 |
+
},
|
14 |
+
"exclude": ["vite.config.ts"]
|
15 |
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
16 |
//
|
17 |
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
vite.config.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import { sveltekit } from "@sveltejs/kit/vite";
|
2 |
-
import { defineConfig, type PluginOption } from "vite";
|
3 |
import Icons from "unplugin-icons/vite";
|
4 |
import { promises } from "fs";
|
|
|
5 |
|
6 |
// used to load fonts server side for thumbnail generation
|
7 |
-
function loadTTFAsArrayBuffer()
|
8 |
return {
|
9 |
name: "load-ttf-as-array-buffer",
|
10 |
async transform(_src, id) {
|
@@ -37,4 +37,9 @@ export default defineConfig({
|
|
37 |
server: {
|
38 |
open: "/",
|
39 |
},
|
|
|
|
|
|
|
|
|
|
|
40 |
});
|
|
|
1 |
import { sveltekit } from "@sveltejs/kit/vite";
|
|
|
2 |
import Icons from "unplugin-icons/vite";
|
3 |
import { promises } from "fs";
|
4 |
+
import { defineConfig } from "vitest/config";
|
5 |
|
6 |
// used to load fonts server side for thumbnail generation
|
7 |
+
function loadTTFAsArrayBuffer() {
|
8 |
return {
|
9 |
name: "load-ttf-as-array-buffer",
|
10 |
async transform(_src, id) {
|
|
|
37 |
server: {
|
38 |
open: "/",
|
39 |
},
|
40 |
+
test: {
|
41 |
+
setupFiles: ["./scripts/setupTest.ts"],
|
42 |
+
deps: { inline: ["@sveltejs/kit"] },
|
43 |
+
globals: true,
|
44 |
+
},
|
45 |
});
|