@prosopo/config 3.4.0 → 3.4.2
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/.turbo/turbo-build$colon$cjs.log +7 -6
- package/.turbo/turbo-build$colon$tsc.log +4 -4
- package/.turbo/turbo-build.log +8 -7
- package/CHANGELOG.md +51 -0
- package/dist/cjs/vite/testFileGlobs.cjs +31 -0
- package/dist/cjs/vite/vite.frontend.config.cjs +1 -0
- package/dist/cjs/vite/vite.test.config.cjs +9 -8
- package/dist/cjs/vite/vite.threads.test.config.cjs +9 -8
- package/dist/vite/configs.test.js +6 -19
- package/dist/vite/configs.test.js.map +1 -1
- package/dist/vite/testFileGlobs.d.ts +8 -0
- package/dist/vite/testFileGlobs.d.ts.map +1 -0
- package/dist/vite/testFileGlobs.js +29 -0
- package/dist/vite/testFileGlobs.js.map +1 -0
- package/dist/vite/testFileGlobs.test.d.ts +2 -0
- package/dist/vite/testFileGlobs.test.d.ts.map +1 -0
- package/dist/vite/testFileGlobs.test.js +113 -0
- package/dist/vite/testFileGlobs.test.js.map +1 -0
- package/dist/vite/vite.frontend.config.d.ts.map +1 -1
- package/dist/vite/vite.frontend.config.js +1 -0
- package/dist/vite/vite.frontend.config.js.map +1 -1
- package/dist/vite/vite.test.config.d.ts.map +1 -1
- package/dist/vite/vite.test.config.js +9 -8
- package/dist/vite/vite.test.config.js.map +1 -1
- package/dist/vite/vite.threads.test.config.d.ts.map +1 -1
- package/dist/vite/vite.threads.test.config.js +9 -8
- package/dist/vite/vite.threads.test.config.js.map +1 -1
- package/package.json +1 -1
- package/src/vite/configs.test.ts +11 -23
- package/src/vite/testFileGlobs.test.ts +162 -0
- package/src/vite/testFileGlobs.ts +57 -0
- package/src/vite/vite.frontend.config.ts +6 -0
- package/src/vite/vite.test.config.ts +7 -13
- package/src/vite/vite.threads.test.config.ts +7 -13
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
|
|
2
|
+
import { testFileGlobs } from "./testFileGlobs.js";
|
|
2
3
|
import VitePluginSourcemapExclude from "./vite-plugin-sourcemap-exclude.js";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import path from "node:path";
|
|
@@ -6,11 +7,8 @@ import tsconfigPaths from "vite-tsconfig-paths";
|
|
|
6
7
|
import { defineConfig } from "vitest/config";
|
|
7
8
|
//#region src/vite/vite.test.config.ts
|
|
8
9
|
function vite_test_config_default(tsConfigPath) {
|
|
9
|
-
const
|
|
10
|
-
console.log(`TEST_TYPE
|
|
11
|
-
const testTypes = testTypeEnv ? testTypeEnv.trim().split(",") : [];
|
|
12
|
-
const testTypeGlob = testTypes.length > 0 ? `@(${testTypes.map((t) => `.${t}`).join("|")})` : "@(|)";
|
|
13
|
-
console.log(`Filtering tests by type: ${testTypeGlob}`);
|
|
10
|
+
const testFiles = testFileGlobs(process.env.TEST_TYPE);
|
|
11
|
+
console.log(`TEST_TYPE=${process.env.TEST_TYPE ?? ""} include=${testFiles.include.join(",")} exclude=${testFiles.exclude.join(",")}`);
|
|
14
12
|
const cwd = process.cwd();
|
|
15
13
|
const isRunningFromPackage = fs.existsSync(path.join(cwd, "package.json")) && fs.existsSync(path.join(cwd, "src"));
|
|
16
14
|
const coverageInclude = isRunningFromPackage ? [
|
|
@@ -36,7 +34,6 @@ function vite_test_config_default(tsConfigPath) {
|
|
|
36
34
|
"**/node_modules/**",
|
|
37
35
|
"**/dist/**"
|
|
38
36
|
];
|
|
39
|
-
const include = `src/**/*${testTypeGlob}.@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)`;
|
|
40
37
|
const plugins = [VitePluginSourcemapExclude({ excludeNodeModules: true }), VitePluginCloseAndCopy()];
|
|
41
38
|
if (tsConfigPath) plugins.push(tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }));
|
|
42
39
|
return defineConfig({
|
|
@@ -47,9 +44,13 @@ function vite_test_config_default(tsConfigPath) {
|
|
|
47
44
|
},
|
|
48
45
|
test: {
|
|
49
46
|
reporters: [["default", { summary: false }]],
|
|
50
|
-
include:
|
|
47
|
+
include: testFiles.include,
|
|
51
48
|
watch: false,
|
|
52
|
-
exclude: [
|
|
49
|
+
exclude: [
|
|
50
|
+
"**/node_modules/**",
|
|
51
|
+
"**/dist/**",
|
|
52
|
+
...testFiles.exclude
|
|
53
|
+
],
|
|
53
54
|
logHeapUsage: true,
|
|
54
55
|
coverage: {
|
|
55
56
|
enabled: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.test.config.js","sourceRoot":"","sources":["../../src/vite/vite.test.config.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,sBAAsB,MAAM,iCAAiC,CAAC;AACrE,OAAO,0BAA0B,MAAM,oCAAoC,CAAC;AAE5E,MAAM,CAAC,OAAO,WAAW,YAAqB;IAC7C,MAAM,
|
|
1
|
+
{"version":3,"file":"vite.test.config.js","sourceRoot":"","sources":["../../src/vite/vite.test.config.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,sBAAsB,MAAM,iCAAiC,CAAC;AACrE,OAAO,0BAA0B,MAAM,oCAAoC,CAAC;AAE5E,MAAM,CAAC,OAAO,WAAW,YAAqB;IAC7C,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,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M,EAAE,KAAK;YACb,SAAS,EAAE,KAAK;YAChB,aAAa,EAAE;gBACd,MAAM,EAAE;oBACP,SAAS,EAAE,KAAK;iBAChB;aACD;SACD;QACD,IAAI,EAAE;YAIL,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YAC5C,OAAO,EAAE,SAAS,CAAC,OAAO;YAC1B,KAAK,EAAE,KAAK;YACZ,OAAO,EAAE,CAAC,oBAAoB,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC;YACnE,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE;gBACT,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,eAAe;gBACxB,OAAO,EAAE,eAAe;aACxB;YACD,SAAS,EAAE;gBACV,OAAO,EAAE,IAAI;aACb;YACD,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE;gBACT,OAAO,EAAE,IAAI;aACb;YACD,WAAW,EAAE,KAAK;SAClB;QACD,OAAO,EAAE,OAAO;KAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.threads.test.config.d.ts","sourceRoot":"","sources":["../../src/vite/vite.threads.test.config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.threads.test.config.d.ts","sourceRoot":"","sources":["../../src/vite/vite.threads.test.config.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,OAAO,WAAW,YAAY,CAAC,EAAE,MAAM,6BA8E7C"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
|
|
2
|
+
import { testFileGlobs } from "./testFileGlobs.js";
|
|
2
3
|
import VitePluginSourcemapExclude from "./vite-plugin-sourcemap-exclude.js";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
5
6
|
import { defineConfig } from "vitest/config";
|
|
6
7
|
//#region src/vite/vite.threads.test.config.ts
|
|
7
8
|
function vite_threads_test_config_default(tsConfigPath) {
|
|
8
|
-
const
|
|
9
|
-
console.log(`TEST_TYPE
|
|
10
|
-
const testTypes = testTypeEnv ? testTypeEnv.trim().split(",") : [];
|
|
11
|
-
const testTypeGlob = testTypes.length > 0 ? `@(${testTypes.map((t) => `.${t}`).join("|")})` : "@(|)";
|
|
12
|
-
console.log(`Filtering tests by type: ${testTypeGlob}`);
|
|
9
|
+
const testFiles = testFileGlobs(process.env.TEST_TYPE);
|
|
10
|
+
console.log(`TEST_TYPE=${process.env.TEST_TYPE ?? ""} include=${testFiles.include.join(",")} exclude=${testFiles.exclude.join(",")}`);
|
|
13
11
|
const cwd = process.cwd();
|
|
14
12
|
const isRunningFromPackage = cwd.includes("/packages/") && cwd.includes("/src") === false;
|
|
15
13
|
const coverageInclude = isRunningFromPackage ? [
|
|
@@ -33,7 +31,6 @@ function vite_threads_test_config_default(tsConfigPath) {
|
|
|
33
31
|
"**/node_modules/**",
|
|
34
32
|
"**/dist/**"
|
|
35
33
|
];
|
|
36
|
-
const include = `src/**/*${testTypeGlob}.@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)`;
|
|
37
34
|
const plugins = [VitePluginSourcemapExclude({ excludeNodeModules: true }), VitePluginCloseAndCopy()];
|
|
38
35
|
if (tsConfigPath) plugins.push(tsconfigPaths({ projects: [path.resolve(tsConfigPath)] }));
|
|
39
36
|
return defineConfig({
|
|
@@ -44,9 +41,13 @@ function vite_threads_test_config_default(tsConfigPath) {
|
|
|
44
41
|
},
|
|
45
42
|
test: {
|
|
46
43
|
reporters: [["default", { summary: false }]],
|
|
47
|
-
include:
|
|
44
|
+
include: testFiles.include,
|
|
48
45
|
watch: false,
|
|
49
|
-
exclude: [
|
|
46
|
+
exclude: [
|
|
47
|
+
"**/node_modules/**",
|
|
48
|
+
"**/dist/**",
|
|
49
|
+
...testFiles.exclude
|
|
50
|
+
],
|
|
50
51
|
logHeapUsage: true,
|
|
51
52
|
coverage: {
|
|
52
53
|
enabled: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.threads.test.config.js","sourceRoot":"","sources":["../../src/vite/vite.threads.test.config.ts"],"names":[],"mappings":"AAcA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,sBAAsB,MAAM,iCAAiC,CAAC;AACrE,OAAO,0BAA0B,MAAM,oCAAoC,CAAC;AAE5E,MAAM,CAAC,OAAO,WAAW,YAAqB;IAC7C,MAAM,
|
|
1
|
+
{"version":3,"file":"vite.threads.test.config.js","sourceRoot":"","sources":["../../src/vite/vite.threads.test.config.ts"],"names":[],"mappings":"AAcA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,sBAAsB,MAAM,iCAAiC,CAAC;AACrE,OAAO,0BAA0B,MAAM,oCAAoC,CAAC;AAE5E,MAAM,CAAC,OAAO,WAAW,YAAqB;IAC7C,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CACV,aAAa,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,YAAY,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CACxH,CAAC;IAGF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,oBAAoB,GACzB,GAAG,CAAC,QAAQ,C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AO,EAAE,IAAI;gBACb,OAAO,EAAE,eAAe;gBACxB,OAAO,EAAE,eAAe;aACxB;YACD,SAAS,EAAE;gBACV,OAAO,EAAE,IAAI;aACb;YACD,IAAI,EAAE,SAAS;YAGf,eAAe,EAAE,KAAK;YACtB,WAAW,EAAE,KAAK;SAClB;QACD,OAAO,EAAE,OAAO;KAChB,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/vite/configs.test.ts
CHANGED
|
@@ -81,35 +81,23 @@ describe("ViteTestConfig", () => {
|
|
|
81
81
|
expect(config.test?.isolate).toBe(true);
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
it("includes
|
|
84
|
+
it("includes every test file when no filter is set", () => {
|
|
85
85
|
asPackage();
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
const config = ViteTestConfig();
|
|
87
|
+
expect(config_include(config)).toBe(
|
|
88
|
+
"src/**/*.@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)",
|
|
88
89
|
);
|
|
90
|
+
expect(config.test?.exclude).toEqual(["**/node_modules/**", "**/dist/**"]);
|
|
89
91
|
});
|
|
90
92
|
|
|
91
|
-
it("filters
|
|
93
|
+
it("filters by excluding the other known test types", () => {
|
|
94
|
+
// Which files that actually selects is proven against vitest's own
|
|
95
|
+
// collection in testFileGlobs.test.ts.
|
|
92
96
|
asPackage();
|
|
93
97
|
process.env.TEST_TYPE = "unit";
|
|
94
|
-
expect(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
it("filters on several test types", () => {
|
|
98
|
-
asPackage();
|
|
99
|
-
process.env.TEST_TYPE = "unit,integration";
|
|
100
|
-
expect(config_include(ViteTestConfig())).toContain("@(.unit|.integration)");
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("trims whitespace around the test type list", () => {
|
|
104
|
-
asPackage();
|
|
105
|
-
process.env.TEST_TYPE = " unit ";
|
|
106
|
-
expect(config_include(ViteTestConfig())).toContain("@(.unit)");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("ignores an empty test type, keeping the default glob", () => {
|
|
110
|
-
asPackage();
|
|
111
|
-
process.env.TEST_TYPE = "";
|
|
112
|
-
expect(config_include(ViteTestConfig())).toContain("@(|)");
|
|
98
|
+
expect(ViteTestConfig().test?.exclude).toContain(
|
|
99
|
+
"src/**/*.@(integration).@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)",
|
|
100
|
+
);
|
|
113
101
|
});
|
|
114
102
|
|
|
115
103
|
it("scopes coverage to the local src when run from a package", () => {
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
// Drives vitest's own file collection over a fixture package, so the
|
|
16
|
+
// assertions are about which files actually run, not about glob strings.
|
|
17
|
+
|
|
18
|
+
import fs from "node:fs";
|
|
19
|
+
import os from "node:os";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
22
|
+
import { createVitest } from "vitest/node";
|
|
23
|
+
import { parseTestTypes, testFileGlobs } from "./testFileGlobs.js";
|
|
24
|
+
import ViteTestConfig from "./vite.test.config.js";
|
|
25
|
+
import ViteThreadsTestConfig from "./vite.threads.test.config.js";
|
|
26
|
+
|
|
27
|
+
const FIXTURE_FILES: readonly string[] = [
|
|
28
|
+
"src/untyped.test.ts",
|
|
29
|
+
"src/typed.unit.test.ts",
|
|
30
|
+
"src/typed.integration.test.ts",
|
|
31
|
+
"src/nested/named.withDots.test.ts",
|
|
32
|
+
"src/component.spec.tsx",
|
|
33
|
+
"src/notATest.ts",
|
|
34
|
+
"src/types.test-d.ts",
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const ALL_RUNTIME_TESTS: readonly string[] = [
|
|
38
|
+
"src/component.spec.tsx",
|
|
39
|
+
"src/nested/named.withDots.test.ts",
|
|
40
|
+
"src/typed.integration.test.ts",
|
|
41
|
+
"src/typed.unit.test.ts",
|
|
42
|
+
"src/untyped.test.ts",
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
let root: string;
|
|
46
|
+
let cwd: string;
|
|
47
|
+
let originalTestType: string | undefined;
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), "prosopo-test-globs-"));
|
|
51
|
+
for (const file of FIXTURE_FILES) {
|
|
52
|
+
fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
53
|
+
fs.writeFileSync(path.join(root, file), "export {};\n");
|
|
54
|
+
}
|
|
55
|
+
fs.writeFileSync(path.join(root, "package.json"), "{}");
|
|
56
|
+
cwd = process.cwd();
|
|
57
|
+
process.chdir(root);
|
|
58
|
+
originalTestType = process.env.TEST_TYPE;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
process.chdir(cwd);
|
|
63
|
+
if (originalTestType === undefined) {
|
|
64
|
+
// biome-ignore lint/performance/noDelete: restore absence, not ""
|
|
65
|
+
delete process.env.TEST_TYPE;
|
|
66
|
+
} else {
|
|
67
|
+
process.env.TEST_TYPE = originalTestType;
|
|
68
|
+
}
|
|
69
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
type ConfigFactory = () => ReturnType<typeof ViteTestConfig>;
|
|
73
|
+
|
|
74
|
+
/** Files vitest would collect for `TEST_TYPE=testType` under `factory`. */
|
|
75
|
+
const collected = async (
|
|
76
|
+
factory: ConfigFactory,
|
|
77
|
+
testType: string | undefined,
|
|
78
|
+
): Promise<string[]> => {
|
|
79
|
+
if (testType === undefined) {
|
|
80
|
+
// biome-ignore lint/performance/noDelete: the config reads presence, not value
|
|
81
|
+
delete process.env.TEST_TYPE;
|
|
82
|
+
} else {
|
|
83
|
+
process.env.TEST_TYPE = testType;
|
|
84
|
+
}
|
|
85
|
+
const config = factory();
|
|
86
|
+
const vitest = await createVitest(
|
|
87
|
+
"test",
|
|
88
|
+
{ config: false, root, watch: false },
|
|
89
|
+
{
|
|
90
|
+
test: {
|
|
91
|
+
include: config.test?.include,
|
|
92
|
+
exclude: config.test?.exclude,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
try {
|
|
97
|
+
const specs = await vitest.globTestSpecifications();
|
|
98
|
+
return specs
|
|
99
|
+
.map((spec) =>
|
|
100
|
+
path.relative(root, spec.moduleId).split(path.sep).join("/"),
|
|
101
|
+
)
|
|
102
|
+
.sort();
|
|
103
|
+
} finally {
|
|
104
|
+
await vitest.close();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const without = (excluded: string): string[] =>
|
|
109
|
+
ALL_RUNTIME_TESTS.filter((f) => f !== excluded);
|
|
110
|
+
|
|
111
|
+
describe.each([
|
|
112
|
+
["ViteTestConfig", (): ReturnType<typeof ViteTestConfig> => ViteTestConfig()],
|
|
113
|
+
[
|
|
114
|
+
"ViteThreadsTestConfig",
|
|
115
|
+
(): ReturnType<typeof ViteTestConfig> => ViteThreadsTestConfig(),
|
|
116
|
+
],
|
|
117
|
+
])("%s test file collection", (_name: string, factory: ConfigFactory) => {
|
|
118
|
+
it("collects every test file when TEST_TYPE is unset", async () => {
|
|
119
|
+
expect(await collected(factory, undefined)).toEqual(ALL_RUNTIME_TESTS);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("treats an empty TEST_TYPE as unset", async () => {
|
|
123
|
+
expect(await collected(factory, "")).toEqual(ALL_RUNTIME_TESTS);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("TEST_TYPE=unit keeps untyped tests and drops integration tests", async () => {
|
|
127
|
+
expect(await collected(factory, "unit")).toEqual(
|
|
128
|
+
without("src/typed.integration.test.ts"),
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("TEST_TYPE=integration keeps untyped tests and drops unit tests", async () => {
|
|
133
|
+
expect(await collected(factory, "integration")).toEqual(
|
|
134
|
+
without("src/typed.unit.test.ts"),
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("accepts a spaced, comma-separated list", async () => {
|
|
139
|
+
expect(await collected(factory, " unit , integration ")).toEqual(
|
|
140
|
+
ALL_RUNTIME_TESTS,
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("testFileGlobs", () => {
|
|
146
|
+
it("excludes nothing without a filter", () => {
|
|
147
|
+
expect(testFileGlobs(undefined).exclude).toEqual([]);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("excludes only the known types that were not selected", () => {
|
|
151
|
+
expect(testFileGlobs("unit").exclude).toEqual([
|
|
152
|
+
"src/**/*.@(integration).@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)",
|
|
153
|
+
]);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("parses the list, dropping blanks", () => {
|
|
157
|
+
expect(parseTestTypes(" unit, ,integration ")).toEqual([
|
|
158
|
+
"unit",
|
|
159
|
+
"integration",
|
|
160
|
+
]);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
/** Test types a file can declare as `name.<type>.test.ts`. */
|
|
16
|
+
export const KNOWN_TEST_TYPES: readonly string[] = ["unit", "integration"];
|
|
17
|
+
|
|
18
|
+
const TEST_FILE_SUFFIX =
|
|
19
|
+
"@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)" as const;
|
|
20
|
+
|
|
21
|
+
export interface TestFileGlobs {
|
|
22
|
+
include: string[];
|
|
23
|
+
exclude: string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const parseTestTypes = (testTypeEnv: string | undefined): string[] =>
|
|
27
|
+
(testTypeEnv ?? "")
|
|
28
|
+
.split(",")
|
|
29
|
+
.map((t) => t.trim())
|
|
30
|
+
.filter((t) => t.length > 0);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Globs selecting the test files for a `TEST_TYPE` filter.
|
|
34
|
+
*
|
|
35
|
+
* Filtering works by excluding the *other* known types rather than by
|
|
36
|
+
* including only the selected one. Files with no declared type
|
|
37
|
+
* (`foo.test.ts`) therefore run under every filter: we don't know what kind
|
|
38
|
+
* of test they are, and an include-only glob silently dropped them from
|
|
39
|
+
* packages whose `test` script sets `TEST_TYPE`.
|
|
40
|
+
*/
|
|
41
|
+
export const testFileGlobs = (
|
|
42
|
+
testTypeEnv: string | undefined,
|
|
43
|
+
): TestFileGlobs => {
|
|
44
|
+
const include = [`src/**/*.${TEST_FILE_SUFFIX}`];
|
|
45
|
+
const selected = parseTestTypes(testTypeEnv);
|
|
46
|
+
if (selected.length === 0) {
|
|
47
|
+
return { include, exclude: [] };
|
|
48
|
+
}
|
|
49
|
+
const excluded = KNOWN_TEST_TYPES.filter((t) => !selected.includes(t));
|
|
50
|
+
return {
|
|
51
|
+
include,
|
|
52
|
+
exclude:
|
|
53
|
+
excluded.length > 0
|
|
54
|
+
? [`src/**/*.@(${excluded.join("|")}).${TEST_FILE_SUFFIX}`]
|
|
55
|
+
: [],
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -81,6 +81,12 @@ export default async function (
|
|
|
81
81
|
"process.env.PROSOPO_PROVIDER_URL_DEVELOPMENT": JSON.stringify(
|
|
82
82
|
process.env.PROSOPO_PROVIDER_URL_DEVELOPMENT,
|
|
83
83
|
),
|
|
84
|
+
// Points a self-hosted build at its own providers regardless of
|
|
85
|
+
// environment, so a production bundle no longer has to masquerade as a
|
|
86
|
+
// development build to be redirected.
|
|
87
|
+
"process.env.PROSOPO_PROVIDER_LIST": JSON.stringify(
|
|
88
|
+
process.env.PROSOPO_PROVIDER_LIST,
|
|
89
|
+
),
|
|
84
90
|
"process.env._DEV_ONLY_WATCH_EVENTS": JSON.stringify(
|
|
85
91
|
process.env._DEV_ONLY_WATCH_EVENTS,
|
|
86
92
|
),
|
|
@@ -16,20 +16,15 @@ import fs from "node:fs";
|
|
|
16
16
|
import path from "node:path";
|
|
17
17
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
18
18
|
import { defineConfig } from "vitest/config";
|
|
19
|
+
import { testFileGlobs } from "./testFileGlobs.js";
|
|
19
20
|
import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
|
|
20
21
|
import VitePluginSourcemapExclude from "./vite-plugin-sourcemap-exclude.js";
|
|
21
22
|
|
|
22
23
|
export default function (tsConfigPath?: string) {
|
|
23
|
-
const
|
|
24
|
-
console.log(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// If we drop ^, there's a chance the tests with no type specified get ignored by accident, which we want to avoid. Ergo, include them by default.
|
|
28
|
-
const testTypeGlob =
|
|
29
|
-
testTypes.length > 0
|
|
30
|
-
? `@(${testTypes.map((t) => `.${t}`).join("|")})`
|
|
31
|
-
: "@(|)";
|
|
32
|
-
console.log(`Filtering tests by type: ${testTypeGlob}`);
|
|
24
|
+
const testFiles = testFileGlobs(process.env.TEST_TYPE);
|
|
25
|
+
console.log(
|
|
26
|
+
`TEST_TYPE=${process.env.TEST_TYPE ?? ""} include=${testFiles.include.join(",")} exclude=${testFiles.exclude.join(",")}`,
|
|
27
|
+
);
|
|
33
28
|
|
|
34
29
|
// Determine coverage include paths based on current working directory.
|
|
35
30
|
//
|
|
@@ -72,7 +67,6 @@ export default function (tsConfigPath?: string) {
|
|
|
72
67
|
"**/node_modules/**",
|
|
73
68
|
"**/dist/**",
|
|
74
69
|
];
|
|
75
|
-
const include = `src/**/*${testTypeGlob}.@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)`;
|
|
76
70
|
const plugins = [
|
|
77
71
|
VitePluginSourcemapExclude({ excludeNodeModules: true }),
|
|
78
72
|
VitePluginCloseAndCopy(),
|
|
@@ -97,9 +91,9 @@ export default function (tsConfigPath?: string) {
|
|
|
97
91
|
// vitest 4 removed the "basic" reporter; the default reporter with
|
|
98
92
|
// summary disabled reproduces its terse output.
|
|
99
93
|
reporters: [["default", { summary: false }]],
|
|
100
|
-
include:
|
|
94
|
+
include: testFiles.include,
|
|
101
95
|
watch: false,
|
|
102
|
-
exclude: ["**/node_modules/**", "**/dist/**"],
|
|
96
|
+
exclude: ["**/node_modules/**", "**/dist/**", ...testFiles.exclude],
|
|
103
97
|
logHeapUsage: true,
|
|
104
98
|
coverage: {
|
|
105
99
|
enabled: true,
|
|
@@ -15,20 +15,15 @@
|
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
17
17
|
import { defineConfig } from "vitest/config";
|
|
18
|
+
import { testFileGlobs } from "./testFileGlobs.js";
|
|
18
19
|
import VitePluginCloseAndCopy from "./vite-plugin-close-and-copy.js";
|
|
19
20
|
import VitePluginSourcemapExclude from "./vite-plugin-sourcemap-exclude.js";
|
|
20
21
|
|
|
21
22
|
export default function (tsConfigPath?: string) {
|
|
22
|
-
const
|
|
23
|
-
console.log(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// If we drop ^, there's a chance the tests with no type specified get ignored by accident, which we want to avoid. Ergo, include them by default.
|
|
27
|
-
const testTypeGlob =
|
|
28
|
-
testTypes.length > 0
|
|
29
|
-
? `@(${testTypes.map((t) => `.${t}`).join("|")})`
|
|
30
|
-
: "@(|)";
|
|
31
|
-
console.log(`Filtering tests by type: ${testTypeGlob}`);
|
|
23
|
+
const testFiles = testFileGlobs(process.env.TEST_TYPE);
|
|
24
|
+
console.log(
|
|
25
|
+
`TEST_TYPE=${process.env.TEST_TYPE ?? ""} include=${testFiles.include.join(",")} exclude=${testFiles.exclude.join(",")}`,
|
|
26
|
+
);
|
|
32
27
|
|
|
33
28
|
// Determine coverage include paths based on current working directory
|
|
34
29
|
const cwd = process.cwd();
|
|
@@ -58,7 +53,6 @@ export default function (tsConfigPath?: string) {
|
|
|
58
53
|
"**/node_modules/**",
|
|
59
54
|
"**/dist/**",
|
|
60
55
|
];
|
|
61
|
-
const include = `src/**/*${testTypeGlob}.@(test|spec).@(mts|cts|mjs|cjs|js|ts|tsx|jsx)`;
|
|
62
56
|
const plugins = [
|
|
63
57
|
VitePluginSourcemapExclude({ excludeNodeModules: true }),
|
|
64
58
|
VitePluginCloseAndCopy(),
|
|
@@ -83,9 +77,9 @@ export default function (tsConfigPath?: string) {
|
|
|
83
77
|
// vitest 4 removed the "basic" reporter; the default reporter with
|
|
84
78
|
// summary disabled reproduces its terse output.
|
|
85
79
|
reporters: [["default", { summary: false }]],
|
|
86
|
-
include:
|
|
80
|
+
include: testFiles.include,
|
|
87
81
|
watch: false,
|
|
88
|
-
exclude: ["**/node_modules/**", "**/dist/**"],
|
|
82
|
+
exclude: ["**/node_modules/**", "**/dist/**", ...testFiles.exclude],
|
|
89
83
|
logHeapUsage: true,
|
|
90
84
|
coverage: {
|
|
91
85
|
enabled: true,
|