@tachybase/test 1.6.12 → 1.6.13-alpha.3

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/lib/vitest.js ADDED
@@ -0,0 +1,173 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var vitest_exports = {};
30
+ __export(vitest_exports, {
31
+ default: () => vitest_default,
32
+ defineTegoVitestConfig: () => defineTegoVitestConfig
33
+ });
34
+ module.exports = __toCommonJS(vitest_exports);
35
+ var import_node_fs = __toESM(require("node:fs"));
36
+ var import_node_module = require("node:module");
37
+ var import_node_path = __toESM(require("node:path"));
38
+ var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
39
+ var import_config = require("vitest/config");
40
+ const runtimeRequire = (0, import_node_module.createRequire)(import_node_path.default.resolve(process.cwd(), "package.json"));
41
+ const packageRoot = import_node_fs.default.existsSync(import_node_path.default.resolve(process.cwd(), "packages/test/package.json")) ? import_node_path.default.resolve(process.cwd(), "packages/test") : import_node_path.default.dirname(runtimeRequire.resolve("@tachybase/test/package.json"));
42
+ const relativePathToAbsolute = /* @__PURE__ */ __name((relativePath) => {
43
+ return import_node_path.default.resolve(process.cwd(), relativePath);
44
+ }, "relativePathToAbsolute");
45
+ function tsConfigPathsToAlias() {
46
+ var _a;
47
+ const alias = [
48
+ {
49
+ find: "@tachybase/utils/plugin-symlink",
50
+ replacement: "node_modules/@tachybase/utils/plugin-symlink.js"
51
+ },
52
+ {
53
+ find: "@opentelemetry/resources",
54
+ replacement: "node_modules/@opentelemetry/resources/build/src/index.js"
55
+ }
56
+ ];
57
+ try {
58
+ const json = JSON.parse(
59
+ import_node_fs.default.readFileSync(import_node_path.default.resolve(process.cwd(), "./tsconfig.paths.json"), { encoding: "utf8" })
60
+ );
61
+ const paths = ((_a = json.compilerOptions) == null ? void 0 : _a.paths) || {};
62
+ alias.push(
63
+ ...Object.keys(paths).reduce((acc, key) => {
64
+ var _a2;
65
+ if (key !== "@@/*") {
66
+ const value = (_a2 = paths[key]) == null ? void 0 : _a2[0];
67
+ if (value) {
68
+ acc.push({
69
+ find: key,
70
+ replacement: value
71
+ });
72
+ }
73
+ }
74
+ return acc;
75
+ }, [])
76
+ );
77
+ } catch {
78
+ }
79
+ return [
80
+ { find: /^~antd\/(.*)/, replacement: "antd/$1" },
81
+ ...alias.map((item) => {
82
+ return {
83
+ ...item,
84
+ replacement: relativePathToAbsolute(item.replacement)
85
+ };
86
+ })
87
+ ];
88
+ }
89
+ __name(tsConfigPathsToAlias, "tsConfigPathsToAlias");
90
+ function defineTegoVitestConfig(options = {}) {
91
+ var _a, _b;
92
+ const serverSetupFile = ((_a = options.server) == null ? void 0 : _a.setupFile) || (0, import_node_path.resolve)(packageRoot, "./setup/server.ts");
93
+ const clientSetupFiles = [(0, import_node_path.resolve)(packageRoot, "./setup/client.ts"), (_b = options.client) == null ? void 0 : _b.setupFile].filter(Boolean);
94
+ return (0, import_config.defineConfig)({
95
+ test: {
96
+ testTimeout: 6e4,
97
+ hookTimeout: 6e4,
98
+ coverage: {
99
+ provider: "v8",
100
+ reporter: ["text", "json-summary", "json"],
101
+ reportOnFailure: true,
102
+ thresholds: {
103
+ lines: 60,
104
+ branches: 60,
105
+ functions: 80,
106
+ statements: 80
107
+ }
108
+ },
109
+ silent: !!process.env.GITHUB_ACTIONS,
110
+ globals: true,
111
+ alias: tsConfigPathsToAlias(),
112
+ projects: [
113
+ {
114
+ root: process.cwd(),
115
+ resolve: {
116
+ mainFields: ["module"]
117
+ },
118
+ extends: true,
119
+ test: {
120
+ name: "server",
121
+ setupFiles: serverSetupFile,
122
+ include: ["packages/**/__tests__/**/*.test.ts", "apps/**/__tests__/**/*.test.ts"],
123
+ exclude: [
124
+ "**/node_modules/**",
125
+ "**/dist/**",
126
+ "**/lib/**",
127
+ "**/es/**",
128
+ "**/e2e/**",
129
+ "**/__e2e__/**",
130
+ "**/{vitest,commitlint}.config.*",
131
+ "packages/**/{sdk,client,schema,components}/**/__tests__/**/*.{test,spec}.{ts,tsx}"
132
+ ]
133
+ }
134
+ },
135
+ {
136
+ // @ts-ignore
137
+ plugins: [(0, import_plugin_react.default)()],
138
+ resolve: {
139
+ mainFields: ["module"]
140
+ },
141
+ define: {
142
+ "process.env.__TEST__": true,
143
+ "process.env.__E2E__": false
144
+ },
145
+ test: {
146
+ name: "client",
147
+ globals: true,
148
+ setupFiles: clientSetupFiles,
149
+ environment: "jsdom",
150
+ css: false,
151
+ alias: tsConfigPathsToAlias(),
152
+ include: ["packages/**/{sdk,client,schema,components}/**/__tests__/**/*.{test,spec}.{ts,tsx}"],
153
+ exclude: [
154
+ "**/node_modules/**",
155
+ "**/dist/**",
156
+ "**/lib/**",
157
+ "**/es/**",
158
+ "**/e2e/**",
159
+ "**/__e2e__/**",
160
+ "**/{vitest,commitlint}.config.*"
161
+ ]
162
+ }
163
+ }
164
+ ]
165
+ }
166
+ });
167
+ }
168
+ __name(defineTegoVitestConfig, "defineTegoVitestConfig");
169
+ var vitest_default = defineTegoVitestConfig();
170
+ // Annotate the CommonJS export names for ESM import in node:
171
+ 0 && (module.exports = {
172
+ defineTegoVitestConfig
173
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/test",
3
- "version": "1.6.12",
3
+ "version": "1.6.13-alpha.3",
4
4
  "homepage": "https://github.com/tegojs/tego#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/tegojs/tego/issues"
@@ -42,8 +42,47 @@
42
42
  "default": "./es/e2e/index.mjs"
43
43
  }
44
44
  },
45
+ "./server": {
46
+ "require": {
47
+ "types": "./lib/server/index.d.ts",
48
+ "default": "./lib/server/index.js"
49
+ },
50
+ "import": {
51
+ "types": "./es/server/index.d.ts",
52
+ "default": "./es/server/index.mjs"
53
+ }
54
+ },
55
+ "./server/mockServer": {
56
+ "require": {
57
+ "types": "./lib/server/mockServer.d.ts",
58
+ "default": "./lib/server/mockServer.js"
59
+ },
60
+ "import": {
61
+ "types": "./es/server/mockServer.d.ts",
62
+ "default": "./es/server/mockServer.mjs"
63
+ }
64
+ },
65
+ "./setup-server": {
66
+ "require": {
67
+ "types": "./lib/setup-server.d.ts",
68
+ "default": "./lib/setup-server.js"
69
+ },
70
+ "import": {
71
+ "types": "./es/setup-server.d.ts",
72
+ "default": "./es/setup-server.mjs"
73
+ }
74
+ },
45
75
  "./package.json": "./package.json",
46
- "./vitest": "./vitest.ts"
76
+ "./vitest": {
77
+ "require": {
78
+ "types": "./vitest.d.ts",
79
+ "default": "./vitest.js"
80
+ },
81
+ "import": {
82
+ "types": "./es/vitest.d.ts",
83
+ "default": "./es/vitest.mjs"
84
+ }
85
+ }
47
86
  },
48
87
  "main": "lib/index.js",
49
88
  "module": "./src/index.ts",
@@ -70,12 +109,13 @@
70
109
  "qs": "^6.14.0",
71
110
  "sqlite3": "^5.1.7",
72
111
  "supertest": "^7.1.4",
112
+ "tsx": "^4.20.5",
73
113
  "vite": "^7.1.10",
74
114
  "vitest": "^3.2.4",
75
115
  "ws": "^8.18.3",
76
- "@tachybase/database": "1.6.12",
77
- "@tachybase/schema": "1.6.12",
78
- "@tachybase/globals": "1.6.12",
79
- "@tego/core": "1.6.12"
116
+ "@tachybase/globals": "1.6.13-alpha.3",
117
+ "@tachybase/schema": "1.6.13-alpha.3",
118
+ "@tego/core": "1.6.13-alpha.3",
119
+ "@tachybase/database": "1.6.13-alpha.3"
80
120
  }
81
121
  }
package/setup/client.ts CHANGED
@@ -15,6 +15,43 @@ import path from 'node:path';
15
15
  configure({ asyncUtilTimeout: 30000 });
16
16
  dotenv.config({ path: path.resolve(process.cwd(), '.env.test') });
17
17
 
18
+ class DOMMatrixMock {
19
+ a = 1;
20
+ b = 0;
21
+ c = 0;
22
+ d = 1;
23
+ e = 0;
24
+ f = 0;
25
+
26
+ multiplySelf() {
27
+ return this;
28
+ }
29
+
30
+ preMultiplySelf() {
31
+ return this;
32
+ }
33
+
34
+ translateSelf() {
35
+ return this;
36
+ }
37
+
38
+ scaleSelf() {
39
+ return this;
40
+ }
41
+
42
+ rotateSelf() {
43
+ return this;
44
+ }
45
+
46
+ invertSelf() {
47
+ return this;
48
+ }
49
+ }
50
+
51
+ globalThis.DOMMatrix ??= DOMMatrixMock as any;
52
+ globalThis.ImageData ??= class ImageDataMock {} as any;
53
+ globalThis.Path2D ??= class Path2DMock {} as any;
54
+
18
55
  // 解决 TypeError: window.matchMedia is not a function
19
56
  // 参见: https://github.com/vitest-dev/vitest/issues/821#issuecomment-1046954558
20
57
  Object.defineProperty(window, 'matchMedia', {
package/setup/server.ts CHANGED
@@ -1,18 +1,12 @@
1
- import os from 'node:os';
2
1
  import path from 'node:path';
3
- import TachybaseGlobal from '@tachybase/globals';
2
+ import { setupServerTestEnvironment } from '@tachybase/test/server';
4
3
  import { initEnv } from '@tego/devkit';
5
4
 
6
- import settings from './settings.sqlite';
7
-
8
- TachybaseGlobal.settings = settings;
9
- // Initialize PLUGIN_PATHS for test environment with an empty array
10
- // This prevents "pluginPaths is not iterable" errors when tests don't need actual plugin resolution
11
- TachybaseGlobal.getInstance().set('PLUGIN_PATHS', []);
12
- // process.env.DB_TEST_DISTRIBUTOR_PORT = '23450';
13
- // process.env.DB_TEST_PREFIX = 'test';
14
- process.env.TEGO_RUNTIME_HOME = path.join(os.tmpdir(), 'test-sqlite');
15
-
16
- process.env.APP_ENV_PATH = process.env.APP_ENV_PATH || '.env.test';
5
+ setupServerTestEnvironment({
6
+ workspaceRoot: process.cwd(),
7
+ pluginPaths: [path.resolve(process.cwd(), 'packages')],
8
+ disableRuntimePlugins: true,
9
+ disableOtherPlugins: true,
10
+ });
17
11
 
18
12
  initEnv();
@@ -0,0 +1 @@
1
+ export * from './lib/setup-server';
@@ -0,0 +1 @@
1
+ module.exports = require('./lib/setup-server');
package/vitest.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './src/vitest';
2
+ export { default } from './src/vitest';
package/vitest.js ADDED
@@ -0,0 +1,2 @@
1
+ require('tsx/cjs');
2
+ module.exports = require('./src/vitest.ts');
package/vitest.ts CHANGED
@@ -1,118 +1,2 @@
1
- import fs from 'node:fs';
2
- import path, { resolve } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import react from '@vitejs/plugin-react';
6
- import { defineConfig } from 'vitest/config';
7
-
8
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
-
10
- const relativePathToAbsolute = (relativePath) => {
11
- return path.resolve(process.cwd(), relativePath);
12
- };
13
-
14
- function tsConfigPathsToAlias() {
15
- const json = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './tsconfig.paths.json'), { encoding: 'utf8' }));
16
- const paths = json.compilerOptions.paths;
17
- const alias = Object.keys(paths).reduce((acc, key) => {
18
- if (key !== '@@/*') {
19
- const value = paths[key][0];
20
- acc.push({
21
- find: key,
22
- replacement: value,
23
- });
24
- }
25
- return acc;
26
- }, []);
27
- alias.unshift(
28
- {
29
- find: '@tachybase/utils/plugin-symlink',
30
- replacement: 'node_modules/@tachybase/utils/plugin-symlink.js',
31
- },
32
- {
33
- find: '@opentelemetry/resources',
34
- replacement: 'node_modules/@opentelemetry/resources/build/src/index.js',
35
- },
36
- );
37
- return [
38
- { find: /^~antd\/(.*)/, replacement: 'antd/$1' },
39
- ...alias.map((item) => {
40
- return {
41
- ...item,
42
- replacement: relativePathToAbsolute(item.replacement),
43
- };
44
- }),
45
- ];
46
- }
47
-
48
- export default defineConfig({
49
- test: {
50
- coverage: {
51
- provider: 'v8',
52
- // you can include other reporters, but 'json-summary' is required, json is recommended
53
- reporter: ['text', 'json-summary', 'json'],
54
- // If you want a coverage reports even if your tests are failing, include the reportOnFailure option
55
- reportOnFailure: true,
56
- thresholds: {
57
- lines: 60,
58
- branches: 60,
59
- functions: 80,
60
- statements: 80,
61
- },
62
- },
63
- silent: !!process.env.GITHUB_ACTIONS,
64
- globals: true,
65
- alias: tsConfigPathsToAlias(),
66
- projects: [
67
- {
68
- root: process.cwd(),
69
- resolve: {
70
- mainFields: ['module'],
71
- },
72
- extends: true,
73
- test: {
74
- setupFiles: resolve(__dirname, './setup/server.ts'),
75
- include: ['packages/**/__tests__/**/*.test.ts', 'apps/**/__tests__/**/*.test.ts'],
76
- exclude: [
77
- '**/node_modules/**',
78
- '**/dist/**',
79
- '**/lib/**',
80
- '**/es/**',
81
- '**/e2e/**',
82
- '**/__e2e__/**',
83
- '**/{vitest,commitlint}.config.*',
84
- 'packages/**/{sdk,client,schema,components}/**/__tests__/**/*.{test,spec}.{ts,tsx}',
85
- ],
86
- },
87
- },
88
- {
89
- // @ts-ignore
90
- plugins: [react()],
91
- resolve: {
92
- mainFields: ['module'],
93
- },
94
- define: {
95
- 'process.env.__TEST__': true,
96
- 'process.env.__E2E__': false,
97
- },
98
- test: {
99
- globals: true,
100
- setupFiles: resolve(__dirname, './setup/client.ts'),
101
- environment: 'jsdom',
102
- css: false,
103
- alias: tsConfigPathsToAlias(),
104
- include: ['packages/**/{sdk,client,schema,components}/**/__tests__/**/*.{test,spec}.{ts,tsx}'],
105
- exclude: [
106
- '**/node_modules/**',
107
- '**/dist/**',
108
- '**/lib/**',
109
- '**/es/**',
110
- '**/e2e/**',
111
- '**/__e2e__/**',
112
- '**/{vitest,commitlint}.config.*',
113
- ],
114
- },
115
- },
116
- ],
117
- },
118
- });
1
+ export * from './src/vitest';
2
+ export { default } from './src/vitest';