-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.config.ts
More file actions
42 lines (35 loc) · 1.13 KB
/
Copy pathvitest.config.ts
File metadata and controls
42 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Vitest config
// - run in a Node.js environment
// - map `.js` imports (TS NodeNext pattern) to `.ts` sources in tests
import fs from "node:fs";
import path from "node:path";
import { defineConfig } from "vitest/config";
function resolveTsFromJsImport() {
return {
name: "ailss-resolve-ts-from-js-import",
enforce: "pre",
resolveId(source: string, importer?: string) {
if (!importer) return null;
if (!source.startsWith(".") && !source.startsWith("/")) return null;
if (!source.endsWith(".js")) return null;
const resolvedJs = path.resolve(path.dirname(importer), source);
if (fs.existsSync(resolvedJs)) return null;
const resolvedTs = resolvedJs.slice(0, -3) + ".ts";
if (fs.existsSync(resolvedTs)) return resolvedTs;
return null;
},
};
}
export default defineConfig({
plugins: [resolveTsFromJsImport()],
resolve: {
alias: {
obsidian: path.resolve(__dirname, "packages/obsidian-plugin/test/mocks/obsidian.ts"),
},
},
test: {
environment: "node",
include: ["packages/**/test/**/*.test.ts"],
exclude: ["**/node_modules/**", "**/dist/**"],
},
});