@tachybase/test 0.23.8
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.log +24 -0
- package/LICENSE +201 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/e2e.d.ts +1 -0
- package/e2e.js +1 -0
- package/es/client/index.d.ts +7 -0
- package/es/client/index.mjs +20 -0
- package/es/e2e/defineConfig.d.ts +2 -0
- package/es/e2e/e2eUtils.d.ts +298 -0
- package/es/e2e/index.d.ts +3 -0
- package/es/e2e/index.mjs +20547 -0
- package/es/e2e/templatesOfCollection.d.ts +41 -0
- package/es/e2e/templatesOfPage.d.ts +573 -0
- package/es/index.d.ts +1 -0
- package/es/index.mjs +223 -0
- package/es/scripts/test-db-creator.d.ts +1 -0
- package/es/scripts/test-db-distributor.d.ts +1 -0
- package/es/server/index.d.ts +17 -0
- package/es/server/mockServer.d.ts +75 -0
- package/lib/client/index.d.ts +7 -0
- package/lib/client/index.js +59 -0
- package/lib/e2e/defineConfig.d.ts +2 -0
- package/lib/e2e/defineConfig.js +78 -0
- package/lib/e2e/e2eUtils.d.ts +298 -0
- package/lib/e2e/e2eUtils.js +633 -0
- package/lib/e2e/index.d.ts +3 -0
- package/lib/e2e/index.js +25 -0
- package/lib/e2e/templatesOfCollection.d.ts +41 -0
- package/lib/e2e/templatesOfCollection.js +720 -0
- package/lib/e2e/templatesOfPage.d.ts +573 -0
- package/lib/e2e/templatesOfPage.js +19345 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +21 -0
- package/lib/scripts/test-db-creator.d.ts +1 -0
- package/lib/scripts/test-db-creator.js +163 -0
- package/lib/scripts/test-db-distributor.d.ts +1 -0
- package/lib/scripts/test-db-distributor.js +234 -0
- package/lib/server/index.d.ts +17 -0
- package/lib/server/index.js +105 -0
- package/lib/server/mockServer.d.ts +75 -0
- package/lib/server/mockServer.js +209 -0
- package/package.json +74 -0
- package/playwright/tests/auth.setup.ts +21 -0
- package/server.d.ts +1 -0
- package/server.js +1 -0
- package/setup/client.ts +69 -0
- package/setup/server.ts +5 -0
- package/vitest.d.ts +24 -0
- package/vitest.mjs +119 -0
|
@@ -0,0 +1,209 @@
|
|
|
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 mockServer_exports = {};
|
|
30
|
+
__export(mockServer_exports, {
|
|
31
|
+
MockServer: () => MockServer,
|
|
32
|
+
createMockServer: () => createMockServer,
|
|
33
|
+
default: () => mockServer_default,
|
|
34
|
+
mockServer: () => mockServer,
|
|
35
|
+
startMockServer: () => startMockServer
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(mockServer_exports);
|
|
38
|
+
var import_database = require("@tachybase/database");
|
|
39
|
+
var import_server = require("@tachybase/server");
|
|
40
|
+
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
41
|
+
var import_qs = __toESM(require("qs"));
|
|
42
|
+
var import_supertest = __toESM(require("supertest"));
|
|
43
|
+
const _MockServer = class _MockServer extends import_server.Application {
|
|
44
|
+
async loadAndInstall(options = {}) {
|
|
45
|
+
await this.load({ method: "install" });
|
|
46
|
+
if (options.afterLoad) {
|
|
47
|
+
await options.afterLoad(this);
|
|
48
|
+
}
|
|
49
|
+
await this.install({
|
|
50
|
+
...options,
|
|
51
|
+
sync: {
|
|
52
|
+
force: false,
|
|
53
|
+
alter: {
|
|
54
|
+
drop: false
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async cleanDb() {
|
|
60
|
+
await this.db.clean({ drop: true });
|
|
61
|
+
}
|
|
62
|
+
async quickstart(options = {}) {
|
|
63
|
+
const { clean } = options;
|
|
64
|
+
if (clean) {
|
|
65
|
+
await this.cleanDb();
|
|
66
|
+
}
|
|
67
|
+
await this.runCommand("start", "--quickstart");
|
|
68
|
+
}
|
|
69
|
+
async destroy(options = {}) {
|
|
70
|
+
await super.destroy(options);
|
|
71
|
+
import_server.Gateway.getInstance().destroy();
|
|
72
|
+
await import_server.AppSupervisor.getInstance().destroy();
|
|
73
|
+
}
|
|
74
|
+
agent() {
|
|
75
|
+
const agent = import_supertest.default.agent(this.callback());
|
|
76
|
+
const prefix = this.resourcer.options.prefix;
|
|
77
|
+
const proxy = new Proxy(agent, {
|
|
78
|
+
get(target, method, receiver) {
|
|
79
|
+
if (["login", "loginUsingId"].includes(method)) {
|
|
80
|
+
return (userOrId) => {
|
|
81
|
+
return proxy.auth(
|
|
82
|
+
import_jsonwebtoken.default.sign(
|
|
83
|
+
{
|
|
84
|
+
userId: typeof userOrId === "number" ? userOrId : userOrId == null ? void 0 : userOrId.id
|
|
85
|
+
},
|
|
86
|
+
process.env.APP_KEY,
|
|
87
|
+
{
|
|
88
|
+
expiresIn: "1d"
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
{ type: "bearer" }
|
|
92
|
+
).set("X-Authenticator", "basic");
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (method === "resource") {
|
|
96
|
+
return (name, resourceOf) => {
|
|
97
|
+
const keys = name.split(".");
|
|
98
|
+
const proxy2 = new Proxy(
|
|
99
|
+
{},
|
|
100
|
+
{
|
|
101
|
+
get(target2, method2, receiver2) {
|
|
102
|
+
return (params = {}) => {
|
|
103
|
+
let { filterByTk } = params;
|
|
104
|
+
const { values = {}, file, ...restParams } = params;
|
|
105
|
+
if (params.associatedIndex) {
|
|
106
|
+
resourceOf = params.associatedIndex;
|
|
107
|
+
}
|
|
108
|
+
if (params.resourceIndex) {
|
|
109
|
+
filterByTk = params.resourceIndex;
|
|
110
|
+
}
|
|
111
|
+
let url = prefix || "";
|
|
112
|
+
if (keys.length > 1) {
|
|
113
|
+
url += `/${keys[0]}/${resourceOf}/${keys[1]}`;
|
|
114
|
+
} else {
|
|
115
|
+
url += `/${name}`;
|
|
116
|
+
}
|
|
117
|
+
url += `:${method2}`;
|
|
118
|
+
if (filterByTk) {
|
|
119
|
+
url += `/${filterByTk}`;
|
|
120
|
+
}
|
|
121
|
+
const queryString = import_qs.default.stringify(restParams, { arrayFormat: "brackets" });
|
|
122
|
+
let request;
|
|
123
|
+
switch (method2) {
|
|
124
|
+
case "list":
|
|
125
|
+
case "get":
|
|
126
|
+
request = agent.get(`${url}?${queryString}`);
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
request = agent.post(`${url}?${queryString}`);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
return file ? request.attach("file", file).field(values) : request.send(values);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
return proxy2;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return agent[method];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return proxy;
|
|
144
|
+
}
|
|
145
|
+
createDatabase(options) {
|
|
146
|
+
const oldDatabase = this.db;
|
|
147
|
+
const databaseOptions = oldDatabase ? oldDatabase.options : (options == null ? void 0 : options.database) || {};
|
|
148
|
+
const database = (0, import_database.mockDatabase)(databaseOptions);
|
|
149
|
+
database.setContext({ app: this });
|
|
150
|
+
return database;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
__name(_MockServer, "MockServer");
|
|
154
|
+
let MockServer = _MockServer;
|
|
155
|
+
function mockServer(options = {}) {
|
|
156
|
+
if (typeof TextEncoder === "undefined") {
|
|
157
|
+
global.TextEncoder = require("util").TextEncoder;
|
|
158
|
+
}
|
|
159
|
+
if (typeof TextDecoder === "undefined") {
|
|
160
|
+
global.TextDecoder = require("util").TextDecoder;
|
|
161
|
+
}
|
|
162
|
+
import_server.Gateway.getInstance().reset();
|
|
163
|
+
if (!import_server.PluginManager.findPackagePatched) {
|
|
164
|
+
import_server.PluginManager.getPackageJson = async () => {
|
|
165
|
+
return {
|
|
166
|
+
version: "0.0.0"
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
import_server.PluginManager.findPackagePatched = true;
|
|
170
|
+
}
|
|
171
|
+
const app = new MockServer({
|
|
172
|
+
acl: false,
|
|
173
|
+
...options
|
|
174
|
+
});
|
|
175
|
+
return app;
|
|
176
|
+
}
|
|
177
|
+
__name(mockServer, "mockServer");
|
|
178
|
+
async function startMockServer(options = {}) {
|
|
179
|
+
const app = mockServer(options);
|
|
180
|
+
await app.runCommand("start");
|
|
181
|
+
return app;
|
|
182
|
+
}
|
|
183
|
+
__name(startMockServer, "startMockServer");
|
|
184
|
+
async function createMockServer(options = {}) {
|
|
185
|
+
const { version, beforeInstall, skipInstall, skipStart, ...others } = options;
|
|
186
|
+
const app = mockServer(others);
|
|
187
|
+
if (!skipInstall) {
|
|
188
|
+
if (beforeInstall) {
|
|
189
|
+
await beforeInstall(app);
|
|
190
|
+
}
|
|
191
|
+
await app.runCommandThrowError("install", "-f");
|
|
192
|
+
}
|
|
193
|
+
if (version) {
|
|
194
|
+
await app.version.update(version);
|
|
195
|
+
}
|
|
196
|
+
if (!skipStart) {
|
|
197
|
+
await app.runCommandThrowError("start");
|
|
198
|
+
}
|
|
199
|
+
return app;
|
|
200
|
+
}
|
|
201
|
+
__name(createMockServer, "createMockServer");
|
|
202
|
+
var mockServer_default = mockServer;
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
MockServer,
|
|
206
|
+
createMockServer,
|
|
207
|
+
mockServer,
|
|
208
|
+
startMockServer
|
|
209
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachybase/test",
|
|
3
|
+
"version": "0.23.8",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"require": {
|
|
8
|
+
"types": "./lib/index.d.ts",
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./es/index.d.ts",
|
|
13
|
+
"default": "./es/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"./client": {
|
|
17
|
+
"require": {
|
|
18
|
+
"types": "./lib/client/index.d.ts",
|
|
19
|
+
"default": "./lib/client/index.js"
|
|
20
|
+
},
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./es/client/index.d.ts",
|
|
23
|
+
"default": "./es/client/index.mjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./e2e": {
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./lib/e2e/index.d.ts",
|
|
29
|
+
"default": "./lib/e2e/index.js"
|
|
30
|
+
},
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./es/e2e/index.d.ts",
|
|
33
|
+
"default": "./es/e2e/index.mjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json",
|
|
37
|
+
"./vitest.mjs": "./vitest.mjs"
|
|
38
|
+
},
|
|
39
|
+
"main": "lib/index.js",
|
|
40
|
+
"module": "./src/index.ts",
|
|
41
|
+
"types": "./lib/index.d.ts",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@faker-js/faker": "8.4.1",
|
|
44
|
+
"@formily/shared": "2.3.2",
|
|
45
|
+
"@playwright/test": "^1.49.1",
|
|
46
|
+
"@testing-library/dom": "^9.3.4",
|
|
47
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
48
|
+
"@testing-library/react": "^14.3.1",
|
|
49
|
+
"@testing-library/user-event": "^14.5.2",
|
|
50
|
+
"@types/supertest": "^2.0.16",
|
|
51
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
52
|
+
"dotenv": "^16.4.7",
|
|
53
|
+
"jsdom": "^16.7.0",
|
|
54
|
+
"jsdom-worker": "^0.3.0",
|
|
55
|
+
"jsonwebtoken": "^8.5.1",
|
|
56
|
+
"lodash": "4.17.21",
|
|
57
|
+
"mariadb": "^2.5.6",
|
|
58
|
+
"mockjs": "^1.1.0",
|
|
59
|
+
"mysql2": "^3.11.5",
|
|
60
|
+
"pg": "^8.13.1",
|
|
61
|
+
"pg-hstore": "^2.3.4",
|
|
62
|
+
"qs": "^6.13.1",
|
|
63
|
+
"sqlite3": "^5.1.7",
|
|
64
|
+
"supertest": "^6.3.4",
|
|
65
|
+
"vite": "^5.4.11",
|
|
66
|
+
"vitest": "^1.6.0",
|
|
67
|
+
"ws": "^8.18.0",
|
|
68
|
+
"@tachybase/server": "0.23.8",
|
|
69
|
+
"@tachybase/database": "0.23.8"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tachybase-build --no-dts @tachybase/test"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { expect, test as setup } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
// 保存登录状态,避免每次都要登录
|
|
4
|
+
setup('admin', async ({ page }) => {
|
|
5
|
+
await page.goto('/');
|
|
6
|
+
await page.getByPlaceholder('Username/Email').click();
|
|
7
|
+
await page.getByPlaceholder('Username/Email').fill('admin@tachybase.com');
|
|
8
|
+
await page.getByPlaceholder('Password').click();
|
|
9
|
+
await page.getByPlaceholder('Password').fill('admin123');
|
|
10
|
+
await page.getByRole('button', { name: 'Sign in' }).click();
|
|
11
|
+
|
|
12
|
+
await expect(page.getByTestId('user-center-button')).toBeVisible();
|
|
13
|
+
|
|
14
|
+
// 开启配置状态
|
|
15
|
+
await page.evaluate(() => {
|
|
16
|
+
localStorage.setItem('TACHYBASE_DESIGNABLE', 'true');
|
|
17
|
+
});
|
|
18
|
+
await page.context().storageState({
|
|
19
|
+
path: process.env.PLAYWRIGHT_AUTH_FILE,
|
|
20
|
+
});
|
|
21
|
+
});
|
package/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/server';
|
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/server');
|
package/setup/client.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest';
|
|
2
|
+
|
|
3
|
+
import { configure } from '@testing-library/react';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
import { vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 解决 TypeError: URL.createObjectURL is not a function
|
|
9
|
+
* 解决 ReferenceError: Worker is not defined
|
|
10
|
+
*/
|
|
11
|
+
import 'jsdom-worker';
|
|
12
|
+
|
|
13
|
+
import path from 'path';
|
|
14
|
+
|
|
15
|
+
configure({ asyncUtilTimeout: 30000 });
|
|
16
|
+
dotenv.config({ path: path.resolve(process.cwd(), '.env.test') });
|
|
17
|
+
|
|
18
|
+
// 解决 TypeError: window.matchMedia is not a function
|
|
19
|
+
// 参见: https://github.com/vitest-dev/vitest/issues/821#issuecomment-1046954558
|
|
20
|
+
Object.defineProperty(window, 'matchMedia', {
|
|
21
|
+
writable: true,
|
|
22
|
+
value: vi.fn().mockImplementation((query) => ({
|
|
23
|
+
matches: false,
|
|
24
|
+
media: query,
|
|
25
|
+
onchange: null,
|
|
26
|
+
addListener: vi.fn(), // deprecated
|
|
27
|
+
removeListener: vi.fn(), // deprecated
|
|
28
|
+
addEventListener: vi.fn(),
|
|
29
|
+
removeEventListener: vi.fn(),
|
|
30
|
+
dispatchEvent: vi.fn(),
|
|
31
|
+
})),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 解决 Error: Not implemented: window.computedStyle(elt, pseudoElt)
|
|
35
|
+
// 参见:https://github.com/nickcolley/jest-axe/issues/147#issuecomment-758804533
|
|
36
|
+
const { getComputedStyle } = window;
|
|
37
|
+
window.getComputedStyle = (elt) => getComputedStyle(elt);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 解决 TypeError: range.getBoundingClientRect is not a function
|
|
41
|
+
* 参见:https://github.com/jsdom/jsdom/issues/3002
|
|
42
|
+
*/
|
|
43
|
+
document.createRange = () => {
|
|
44
|
+
const range = new Range();
|
|
45
|
+
|
|
46
|
+
range.getBoundingClientRect = () => {
|
|
47
|
+
return {
|
|
48
|
+
x: 0,
|
|
49
|
+
y: 0,
|
|
50
|
+
bottom: 0,
|
|
51
|
+
height: 0,
|
|
52
|
+
left: 0,
|
|
53
|
+
right: 0,
|
|
54
|
+
top: 0,
|
|
55
|
+
width: 0,
|
|
56
|
+
toJSON: () => {},
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
range.getClientRects = () => {
|
|
61
|
+
return {
|
|
62
|
+
item: (index) => null,
|
|
63
|
+
length: 0,
|
|
64
|
+
*[Symbol.iterator]() {},
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return range;
|
|
69
|
+
};
|
package/setup/server.ts
ADDED
package/vitest.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type UserConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
const suite: (typeof import('vitest'))['suite'];
|
|
5
|
+
const test: (typeof import('vitest'))['test'];
|
|
6
|
+
const describe: (typeof import('vitest'))['describe'];
|
|
7
|
+
const it: (typeof import('vitest'))['it'];
|
|
8
|
+
const expectTypeOf: (typeof import('vitest'))['expectTypeOf'];
|
|
9
|
+
const assertType: (typeof import('vitest'))['assertType'];
|
|
10
|
+
const expect: (typeof import('vitest'))['expect'];
|
|
11
|
+
const assert: (typeof import('vitest'))['assert'];
|
|
12
|
+
const vitest: (typeof import('vitest'))['vitest'];
|
|
13
|
+
const vi: (typeof import('vitest'))['vitest'];
|
|
14
|
+
const beforeAll: (typeof import('vitest'))['beforeAll'];
|
|
15
|
+
const afterAll: (typeof import('vitest'))['afterAll'];
|
|
16
|
+
const beforeEach: (typeof import('vitest'))['beforeEach'];
|
|
17
|
+
const afterEach: (typeof import('vitest'))['afterEach'];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare const defineConfig: (
|
|
21
|
+
config?: UserConfig & {
|
|
22
|
+
server: boolean;
|
|
23
|
+
},
|
|
24
|
+
) => UserConfig;
|
package/vitest.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path, { resolve } from 'path';
|
|
3
|
+
import { URL } from 'url';
|
|
4
|
+
|
|
5
|
+
import react from '@vitejs/plugin-react';
|
|
6
|
+
import { defineConfig as vitestConfig } from 'vitest/config';
|
|
7
|
+
|
|
8
|
+
const __dirname = new URL('.', import.meta.url).pathname;
|
|
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 const defineConfig = (config = {}) => {
|
|
49
|
+
return vitestConfig(
|
|
50
|
+
process.env.TEST_ENV === 'server-side'
|
|
51
|
+
? {
|
|
52
|
+
root: process.cwd(),
|
|
53
|
+
resolve: {
|
|
54
|
+
mainFields: ['module'],
|
|
55
|
+
},
|
|
56
|
+
test: {
|
|
57
|
+
globals: true,
|
|
58
|
+
setupFiles: resolve(__dirname, './setup/server.ts'),
|
|
59
|
+
alias: tsConfigPathsToAlias(),
|
|
60
|
+
include: ['packages/**/__tests__/**/*.test.ts'],
|
|
61
|
+
exclude: [
|
|
62
|
+
'**/node_modules/**',
|
|
63
|
+
'**/dist/**',
|
|
64
|
+
'**/lib/**',
|
|
65
|
+
'**/es/**',
|
|
66
|
+
'**/e2e/**',
|
|
67
|
+
'**/__e2e__/**',
|
|
68
|
+
'**/{vitest,commitlint}.config.*',
|
|
69
|
+
'packages/**/{sdk,client}/**/__tests__/**/*.{test,spec}.{ts,tsx}',
|
|
70
|
+
],
|
|
71
|
+
testTimeout: 300000,
|
|
72
|
+
hookTimeout: 300000,
|
|
73
|
+
// bail: 1,
|
|
74
|
+
// 在 GitHub Actions 中不输出日志
|
|
75
|
+
silent: !!process.env.GITHUB_ACTIONS,
|
|
76
|
+
// poolOptions: {
|
|
77
|
+
// threads: {
|
|
78
|
+
// singleThread: process.env.SINGLE_THREAD == 'false' ? false : true,
|
|
79
|
+
// },
|
|
80
|
+
// },
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
: {
|
|
84
|
+
plugins: [react()],
|
|
85
|
+
resolve: {
|
|
86
|
+
mainFields: ['module'],
|
|
87
|
+
},
|
|
88
|
+
define: {
|
|
89
|
+
'process.env.__TEST__': true,
|
|
90
|
+
'process.env.__E2E__': false,
|
|
91
|
+
},
|
|
92
|
+
test: {
|
|
93
|
+
globals: true,
|
|
94
|
+
setupFiles: resolve(__dirname, './setup/client.ts'),
|
|
95
|
+
environment: 'jsdom',
|
|
96
|
+
css: false,
|
|
97
|
+
alias: tsConfigPathsToAlias(),
|
|
98
|
+
include: ['packages/**/{sdk,client}/**/__tests__/**/*.{test,spec}.{ts,tsx}'],
|
|
99
|
+
exclude: [
|
|
100
|
+
'**/node_modules/**',
|
|
101
|
+
'**/dist/**',
|
|
102
|
+
'**/lib/**',
|
|
103
|
+
'**/es/**',
|
|
104
|
+
'**/e2e/**',
|
|
105
|
+
'**/__e2e__/**',
|
|
106
|
+
'**/{vitest,commitlint}.config.*',
|
|
107
|
+
],
|
|
108
|
+
testTimeout: 300000,
|
|
109
|
+
// 在 GitHub Actions 中不输出日志
|
|
110
|
+
silent: !!process.env.GITHUB_ACTIONS,
|
|
111
|
+
server: {
|
|
112
|
+
deps: {
|
|
113
|
+
inline: ['@juggle/resize-observer', 'clsx'],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
);
|
|
119
|
+
};
|