@kcconfigs/vitest 0.0.1 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/index.cjs +141 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +93 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +135 -0
- package/dist/index.js.map +1 -0
- package/dist/mockHelpers/index.cjs +10 -0
- package/dist/mockHelpers/index.d.cts +4 -0
- package/dist/mockHelpers/index.d.ts +4 -0
- package/dist/mockHelpers/index.js +5 -0
- package/package.json +69 -1
- package/src/constants.ts +48 -0
- package/src/index.test.ts +47 -0
- package/src/index.ts +8 -0
- package/src/mockHelpers/fs.ts +1 -0
- package/src/mockHelpers/index.test.ts +24 -0
- package/src/mockHelpers/index.ts +1 -0
- package/src/models.test.ts +39 -0
- package/src/models.ts +27 -0
- package/src/utils/defineEmptyProject.test.ts +70 -0
- package/src/utils/defineEmptyProject.ts +9 -0
- package/src/utils/defineEmptyRoot.test.ts +97 -0
- package/src/utils/defineEmptyRoot.ts +9 -0
- package/src/utils/defineProject.test.ts +87 -0
- package/src/utils/defineProject.ts +18 -0
- package/src/utils/defineProjectOrRoot.test.ts +88 -0
- package/src/utils/defineProjectOrRoot.ts +18 -0
- package/src/utils/defineRoot.example.ts +16 -0
- package/src/utils/defineRoot.test.ts +114 -0
- package/src/utils/defineRoot.ts +16 -0
- package/src/utils/mergeConfig.test.ts +126 -0
- package/src/utils/mergeConfig.ts +29 -0
- package/src/utils/setupMocks.test.ts +81 -0
- package/src/utils/setupMocks.ts +22 -0
package/src/constants.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { UserConfig } from "./models";
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
export const baseRootConfig: UserConfig = {
|
|
5
|
+
test: {
|
|
6
|
+
restoreMocks: true,
|
|
7
|
+
mockReset: true,
|
|
8
|
+
clearMocks: true,
|
|
9
|
+
unstubGlobals: true,
|
|
10
|
+
unstubEnvs: true,
|
|
11
|
+
environment: "node",
|
|
12
|
+
reporters: ["default", "html", "junit"],
|
|
13
|
+
outputFile: {
|
|
14
|
+
html: "reports/test-results/index.html",
|
|
15
|
+
junit: "reports/test-results/junit.xml",
|
|
16
|
+
},
|
|
17
|
+
coverage: {
|
|
18
|
+
enabled: true,
|
|
19
|
+
provider: "v8",
|
|
20
|
+
reporter: [["text"], ["lcovonly"], ["html", { subdir: "html" }]],
|
|
21
|
+
reportsDirectory: "reports/coverage",
|
|
22
|
+
thresholds: {
|
|
23
|
+
perFile: true,
|
|
24
|
+
},
|
|
25
|
+
include: ["**/*.{ts,tsx}"],
|
|
26
|
+
exclude: [
|
|
27
|
+
// Ignored hidden files
|
|
28
|
+
"**/[.]**",
|
|
29
|
+
// Ignored test files
|
|
30
|
+
"**/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)",
|
|
31
|
+
"**/__mocks__/**",
|
|
32
|
+
// Ignored dist files
|
|
33
|
+
"**/dist/**",
|
|
34
|
+
// Ignored typescript definition files
|
|
35
|
+
"**/*.d.{ts,cts,mts}",
|
|
36
|
+
// Ignored example files
|
|
37
|
+
"**/*.example.?(c|m)[jt]s?(x)",
|
|
38
|
+
// Ignored configuration files
|
|
39
|
+
"**/*.config.?(c|m)[jt]s?(x)",
|
|
40
|
+
// Ignored schema files
|
|
41
|
+
"**/*.schema.?(c|m)[jt]s?(x)",
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** @internal */
|
|
48
|
+
export const baseProjectConfig: UserConfig = {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
defineEmptyProject,
|
|
4
|
+
defineEmptyRoot,
|
|
5
|
+
defineProject,
|
|
6
|
+
defineProjectOrRoot,
|
|
7
|
+
defineRoot,
|
|
8
|
+
mergeConfig,
|
|
9
|
+
setupMocks,
|
|
10
|
+
} from "./index";
|
|
11
|
+
|
|
12
|
+
describe("Main Exports", () => {
|
|
13
|
+
test("should export defineRoot", () => {
|
|
14
|
+
expect(defineRoot).toBeDefined();
|
|
15
|
+
expect(typeof defineRoot).toBe("function");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("should export defineProject", () => {
|
|
19
|
+
expect(defineProject).toBeDefined();
|
|
20
|
+
expect(typeof defineProject).toBe("function");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("should export defineEmptyRoot", () => {
|
|
24
|
+
expect(defineEmptyRoot).toBeDefined();
|
|
25
|
+
expect(typeof defineEmptyRoot).toBe("function");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("should export defineEmptyProject", () => {
|
|
29
|
+
expect(defineEmptyProject).toBeDefined();
|
|
30
|
+
expect(typeof defineEmptyProject).toBe("function");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("should export defineProjectOrRoot", () => {
|
|
34
|
+
expect(defineProjectOrRoot).toBeDefined();
|
|
35
|
+
expect(typeof defineProjectOrRoot).toBe("function");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("should export mergeConfig", () => {
|
|
39
|
+
expect(mergeConfig).toBeDefined();
|
|
40
|
+
expect(typeof mergeConfig).toBe("function");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("should export setupMocks", () => {
|
|
44
|
+
expect(setupMocks).toBeDefined();
|
|
45
|
+
expect(typeof setupMocks).toBe("function");
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { AnyConfig, ProjectConfig, UserConfig } from "./models";
|
|
2
|
+
export { defineEmptyProject } from "./utils/defineEmptyProject";
|
|
3
|
+
export { defineEmptyRoot } from "./utils/defineEmptyRoot";
|
|
4
|
+
export { defineProject } from "./utils/defineProject";
|
|
5
|
+
export { defineProjectOrRoot } from "./utils/defineProjectOrRoot";
|
|
6
|
+
export { defineRoot } from "./utils/defineRoot";
|
|
7
|
+
export { mergeConfig } from "./utils/mergeConfig";
|
|
8
|
+
export { setupMocks } from "./utils/setupMocks";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { vol } from "memfs";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { vol } from "./index";
|
|
3
|
+
|
|
4
|
+
describe("Mock Helpers", () => {
|
|
5
|
+
test("should export vol from memfs", () => {
|
|
6
|
+
expect(vol).toBeDefined();
|
|
7
|
+
expect(typeof vol).toBe("object");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("vol should have fromJSON method", () => {
|
|
11
|
+
expect(vol.fromJSON).toBeDefined();
|
|
12
|
+
expect(typeof vol.fromJSON).toBe("function");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("vol should have reset method", () => {
|
|
16
|
+
expect(vol.reset).toBeDefined();
|
|
17
|
+
expect(typeof vol.reset).toBe("function");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("vol should have toJSON method", () => {
|
|
21
|
+
expect(vol.toJSON).toBeDefined();
|
|
22
|
+
expect(typeof vol.toJSON).toBe("function");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./fs";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** biome-ignore-all lint/complexity/useLiteralKeys: Conflict with ts(4111) */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
4
|
+
import type { AnyConfig, ProjectConfig, UserConfig } from "./models";
|
|
5
|
+
|
|
6
|
+
describe("Type Definitions", () => {
|
|
7
|
+
test("should export UserConfig type", () => {
|
|
8
|
+
const config: UserConfig = {
|
|
9
|
+
test: {
|
|
10
|
+
environment: "node",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
expect(config).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("should export ProjectConfig type", () => {
|
|
18
|
+
const config: ProjectConfig = {
|
|
19
|
+
test: {
|
|
20
|
+
name: "test-project",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
expect(config).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("should export AnyConfig type", () => {
|
|
28
|
+
const config: AnyConfig = {
|
|
29
|
+
anyKey: "anyValue",
|
|
30
|
+
nested: {
|
|
31
|
+
deep: true,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
expect(config).toBeDefined();
|
|
36
|
+
expect(config["anyKey"]).toBe("anyValue");
|
|
37
|
+
expect(config["nested"]["deep"]).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
});
|
package/src/models.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UserWorkspaceConfig as _ProjectConfig,
|
|
3
|
+
ViteUserConfig as _UserConfig,
|
|
4
|
+
} from "vitest/config";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generic configuration type allowing any string keys and values.
|
|
8
|
+
* Used as a flexible type for configuration merging operations.
|
|
9
|
+
*/
|
|
10
|
+
// biome-ignore lint/suspicious/noExplicitAny: Necessary for generic config type
|
|
11
|
+
export type AnyConfig = Record<string, any>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Vitest user configuration type for root workspace setup.
|
|
15
|
+
* Extends Vite's user configuration with Vitest-specific test settings.
|
|
16
|
+
*
|
|
17
|
+
* @see https://vitest.dev/config/
|
|
18
|
+
*/
|
|
19
|
+
export type UserConfig = _UserConfig;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Vitest project configuration type for workspace projects.
|
|
23
|
+
* Extends Vite's workspace config with project-specific test settings.
|
|
24
|
+
*
|
|
25
|
+
* @see https://vitest.dev/config/
|
|
26
|
+
*/
|
|
27
|
+
export type ProjectConfig = _ProjectConfig;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { defineEmptyProject } from "./defineEmptyProject";
|
|
3
|
+
|
|
4
|
+
describe("defineEmptyProject", () => {
|
|
5
|
+
test("should return an empty configuration", () => {
|
|
6
|
+
const config = defineEmptyProject();
|
|
7
|
+
|
|
8
|
+
expect(config).toBeDefined();
|
|
9
|
+
expect(typeof config).toBe("object");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("should not include base configuration", () => {
|
|
13
|
+
const config = defineEmptyProject();
|
|
14
|
+
|
|
15
|
+
// Should not have default values
|
|
16
|
+
expect(config.test?.environment).toBeUndefined();
|
|
17
|
+
expect(config.test?.restoreMocks).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("should merge custom configuration", () => {
|
|
21
|
+
const config = defineEmptyProject({
|
|
22
|
+
test: {
|
|
23
|
+
name: "my-project",
|
|
24
|
+
environment: "jsdom",
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(config.test?.name).toBe("my-project");
|
|
29
|
+
expect(config.test?.environment).toBe("jsdom");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("should handle multiple configuration objects", () => {
|
|
33
|
+
const config = defineEmptyProject(
|
|
34
|
+
{
|
|
35
|
+
test: {
|
|
36
|
+
name: "project-1",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
test: {
|
|
41
|
+
environment: "node",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expect(config.test?.name).toBe("project-1");
|
|
47
|
+
expect(config.test?.environment).toBe("node");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("should handle undefined configuration", () => {
|
|
51
|
+
const config = defineEmptyProject(undefined);
|
|
52
|
+
|
|
53
|
+
expect(config).toBeDefined();
|
|
54
|
+
expect(config.test).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("should allow project-specific configuration", () => {
|
|
58
|
+
const config = defineEmptyProject({
|
|
59
|
+
test: {
|
|
60
|
+
name: "test-package",
|
|
61
|
+
root: "./packages/test-package",
|
|
62
|
+
include: ["src/**/*.test.ts"],
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(config.test?.name).toBe("test-package");
|
|
67
|
+
expect(config.test?.root).toBe("./packages/test-package");
|
|
68
|
+
expect(config.test?.include).toEqual(["src/**/*.test.ts"]);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineProject } from "vitest/config";
|
|
2
|
+
import type { ProjectConfig } from "../models";
|
|
3
|
+
import { mergeConfig } from "./mergeConfig";
|
|
4
|
+
|
|
5
|
+
export const defineEmptyProject = (
|
|
6
|
+
...configs: Optional<ProjectConfig>[]
|
|
7
|
+
): ProjectConfig => {
|
|
8
|
+
return defineProject(mergeConfig({}, ...configs));
|
|
9
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { defineEmptyRoot } from "./defineEmptyRoot";
|
|
3
|
+
|
|
4
|
+
describe("defineEmptyRoot", () => {
|
|
5
|
+
test("should return an empty configuration", () => {
|
|
6
|
+
const config = defineEmptyRoot();
|
|
7
|
+
|
|
8
|
+
expect(config).toBeDefined();
|
|
9
|
+
expect(typeof config).toBe("object");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("should not include base root configuration", () => {
|
|
13
|
+
const config = defineEmptyRoot();
|
|
14
|
+
|
|
15
|
+
// Should not have default values from baseRootConfig
|
|
16
|
+
expect(config.test?.environment).toBeUndefined();
|
|
17
|
+
expect(config.test?.restoreMocks).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("should merge custom configuration", () => {
|
|
21
|
+
const config = defineEmptyRoot({
|
|
22
|
+
test: {
|
|
23
|
+
environment: "jsdom",
|
|
24
|
+
globals: true,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(config.test?.environment).toBe("jsdom");
|
|
29
|
+
expect(config.test?.globals).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("should handle multiple configuration objects", () => {
|
|
33
|
+
const config = defineEmptyRoot(
|
|
34
|
+
{
|
|
35
|
+
test: {
|
|
36
|
+
environment: "node",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
test: {
|
|
41
|
+
globals: true,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expect(config.test?.environment).toBe("node");
|
|
47
|
+
expect(config.test?.globals).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("should handle undefined configuration", () => {
|
|
51
|
+
const config = defineEmptyRoot(undefined);
|
|
52
|
+
|
|
53
|
+
expect(config).toBeDefined();
|
|
54
|
+
expect(config.test).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("should handle null configuration", () => {
|
|
58
|
+
const config = defineEmptyRoot(null);
|
|
59
|
+
|
|
60
|
+
expect(config).toBeDefined();
|
|
61
|
+
expect(config.test).toBeUndefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("should merge nested configurations", () => {
|
|
65
|
+
const config = defineEmptyRoot({
|
|
66
|
+
test: {
|
|
67
|
+
coverage: {
|
|
68
|
+
enabled: true,
|
|
69
|
+
provider: "v8",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(config.test?.coverage?.enabled).toBe(true);
|
|
75
|
+
expect(config.test?.coverage?.provider).toBe("v8");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("should allow full custom configuration", () => {
|
|
79
|
+
const customConfig = {
|
|
80
|
+
test: {
|
|
81
|
+
name: "custom-test",
|
|
82
|
+
environment: "happy-dom",
|
|
83
|
+
reporters: ["json"],
|
|
84
|
+
coverage: {
|
|
85
|
+
enabled: false,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const config = defineEmptyRoot(customConfig);
|
|
91
|
+
|
|
92
|
+
expect(config.test?.name).toBe("custom-test");
|
|
93
|
+
expect(config.test?.environment).toBe("happy-dom");
|
|
94
|
+
expect(config.test?.reporters).toEqual(["json"]);
|
|
95
|
+
expect(config.test?.coverage?.enabled).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
import type { UserConfig } from "../models";
|
|
3
|
+
import { mergeConfig } from "./mergeConfig";
|
|
4
|
+
|
|
5
|
+
export const defineEmptyRoot = (
|
|
6
|
+
...configs: Optional<UserConfig>[]
|
|
7
|
+
): UserConfig => {
|
|
8
|
+
return defineConfig(mergeConfig({}, ...configs));
|
|
9
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { defineProject } from "./defineProject";
|
|
3
|
+
|
|
4
|
+
describe("defineProject", () => {
|
|
5
|
+
test("should return a configuration object", () => {
|
|
6
|
+
const config = defineProject();
|
|
7
|
+
|
|
8
|
+
expect(config).toBeDefined();
|
|
9
|
+
expect(typeof config).toBe("object");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("should include base root configuration", () => {
|
|
13
|
+
const config = defineProject();
|
|
14
|
+
|
|
15
|
+
expect(config.test).toBeDefined();
|
|
16
|
+
expect(config.test?.environment).toBe("node");
|
|
17
|
+
expect(config.test?.restoreMocks).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("should merge custom configuration", () => {
|
|
21
|
+
const config = defineProject({
|
|
22
|
+
test: {
|
|
23
|
+
name: "my-project",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
expect(config.test?.name).toBe("my-project");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("should preserve base configuration when merging", () => {
|
|
31
|
+
const config = defineProject({
|
|
32
|
+
test: {
|
|
33
|
+
name: "my-project",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(config.test?.restoreMocks).toBe(true);
|
|
38
|
+
expect(config.test?.environment).toBe("node");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("should handle multiple configuration overrides", () => {
|
|
42
|
+
const config = defineProject(
|
|
43
|
+
{
|
|
44
|
+
test: {
|
|
45
|
+
name: "my-project",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
test: {
|
|
50
|
+
environment: "jsdom",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
expect(config.test?.name).toBe("my-project");
|
|
56
|
+
expect(config.test?.environment).toBe("jsdom");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("should handle undefined configuration", () => {
|
|
60
|
+
const config = defineProject(undefined);
|
|
61
|
+
|
|
62
|
+
expect(config).toBeDefined();
|
|
63
|
+
expect(config.test?.environment).toBe("node");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("should support root property for workspace project", () => {
|
|
67
|
+
const config = defineProject({
|
|
68
|
+
test: {
|
|
69
|
+
root: "./packages/my-package",
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(config.test?.root).toBe("./packages/my-package");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("should merge project-specific test configuration", () => {
|
|
77
|
+
const config = defineProject({
|
|
78
|
+
test: {
|
|
79
|
+
name: "test-package",
|
|
80
|
+
include: ["src/**/*.test.ts"],
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(config.test?.name).toBe("test-package");
|
|
85
|
+
expect(config.test?.include).toEqual(["src/**/*.test.ts"]);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { baseProjectConfig, baseRootConfig } from "../constants";
|
|
2
|
+
import type { ProjectConfig } from "../models";
|
|
3
|
+
import { defineEmptyProject } from "./defineEmptyProject";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Defines the root Vitest configuration for the workspace.
|
|
7
|
+
* Merges the base root configuration with any provided user configuration.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Optional user-provided Vitest configuration overrides
|
|
10
|
+
* @returns The merged root Vitest configuration
|
|
11
|
+
*
|
|
12
|
+
* @includeExample
|
|
13
|
+
*/
|
|
14
|
+
export const defineProject = (
|
|
15
|
+
...config: Optional<ProjectConfig>[]
|
|
16
|
+
): ProjectConfig => {
|
|
17
|
+
return defineEmptyProject(baseRootConfig, baseProjectConfig, ...config);
|
|
18
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { defineProjectOrRoot } from "./defineProjectOrRoot";
|
|
3
|
+
|
|
4
|
+
describe("defineProjectOrRoot", () => {
|
|
5
|
+
test("should return a configuration object", () => {
|
|
6
|
+
const config = defineProjectOrRoot();
|
|
7
|
+
|
|
8
|
+
expect(config).toBeDefined();
|
|
9
|
+
expect(typeof config).toBe("object");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("should include base root configuration", () => {
|
|
13
|
+
const config = defineProjectOrRoot();
|
|
14
|
+
|
|
15
|
+
expect(config.test).toBeDefined();
|
|
16
|
+
expect(config.test?.environment).toBe("node");
|
|
17
|
+
expect(config.test?.restoreMocks).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("should merge custom configuration", () => {
|
|
21
|
+
const config = defineProjectOrRoot({
|
|
22
|
+
test: {
|
|
23
|
+
name: "my-config",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
expect(config.test?.name).toBe("my-config");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("should preserve base configuration when merging", () => {
|
|
31
|
+
const config = defineProjectOrRoot({
|
|
32
|
+
test: {
|
|
33
|
+
name: "my-config",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(config.test?.restoreMocks).toBe(true);
|
|
38
|
+
expect(config.test?.environment).toBe("node");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("should handle multiple configuration overrides", () => {
|
|
42
|
+
const config = defineProjectOrRoot(
|
|
43
|
+
{
|
|
44
|
+
test: {
|
|
45
|
+
environment: "jsdom",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
test: {
|
|
50
|
+
globals: true,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
expect(config.test?.environment).toBe("jsdom");
|
|
56
|
+
expect(config.test?.globals).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("should work as root configuration", () => {
|
|
60
|
+
const config = defineProjectOrRoot({
|
|
61
|
+
test: {
|
|
62
|
+
projects: ["packages/**/vitest.config.ts"],
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(config.test?.projects).toEqual(["packages/**/vitest.config.ts"]);
|
|
67
|
+
expect(config.test?.environment).toBe("node");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("should work as project configuration", () => {
|
|
71
|
+
const config = defineProjectOrRoot({
|
|
72
|
+
test: {
|
|
73
|
+
name: "my-project",
|
|
74
|
+
root: "./packages/my-project",
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(config.test?.name).toBe("my-project");
|
|
79
|
+
expect(config.test?.root).toBe("./packages/my-project");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("should handle undefined configuration", () => {
|
|
83
|
+
const config = defineProjectOrRoot(undefined);
|
|
84
|
+
|
|
85
|
+
expect(config).toBeDefined();
|
|
86
|
+
expect(config.test?.environment).toBe("node");
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { baseProjectConfig, baseRootConfig } from "../constants";
|
|
2
|
+
import type { ProjectConfig, UserConfig } from "../models";
|
|
3
|
+
import { defineEmptyRoot } from "./defineEmptyRoot";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Defines the root Vitest configuration for the workspace.
|
|
7
|
+
* Merges the base root configuration with any provided user configuration.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Optional user-provided Vitest configuration overrides
|
|
10
|
+
* @returns The merged root Vitest configuration
|
|
11
|
+
*
|
|
12
|
+
* @includeExample
|
|
13
|
+
*/
|
|
14
|
+
export const defineProjectOrRoot = (
|
|
15
|
+
...config: Optional<UserConfig>[]
|
|
16
|
+
): ProjectConfig => {
|
|
17
|
+
return defineEmptyRoot(baseRootConfig, baseProjectConfig, ...config);
|
|
18
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineRoot } from "./defineRoot";
|
|
2
|
+
|
|
3
|
+
// Example usages of defineRoot
|
|
4
|
+
defineRoot();
|
|
5
|
+
|
|
6
|
+
// Example with user configuration overrides
|
|
7
|
+
defineRoot({
|
|
8
|
+
test: {
|
|
9
|
+
dir: "packages",
|
|
10
|
+
coverage: {
|
|
11
|
+
thresholds: {
|
|
12
|
+
"100": true,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|