@akanjs/test 0.0.45 → 0.0.47
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/index.js +2 -615
- package/package.json +9 -4
- package/src/index.js +25 -0
- package/src/jest.config.base.d.ts +2 -0
- package/src/jest.config.base.js +52 -0
- package/src/jest.globalSetup.d.ts +4 -0
- package/src/jest.globalSetup.js +38 -0
- package/src/jest.globalTeardown.d.ts +3 -0
- package/src/jest.globalTeardown.js +30 -0
- package/src/jest.setupFilesAfterEnv.d.ts +1 -0
- package/src/jest.setupFilesAfterEnv.js +10 -0
- package/src/jest.testServer.d.ts +11 -0
- package/src/jest.testServer.js +135 -0
- package/src/playwright.config.base.d.ts +9 -0
- package/src/playwright.config.base.js +76 -0
- package/src/playwright.pageAgent.d.ts +13 -0
- package/src/playwright.pageAgent.js +61 -0
- package/src/sample.js +41 -0
- package/src/sampleOf.js +76 -0
package/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
5
|
var __copyProps = (to, from, except, desc) => {
|
|
12
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -16,615 +10,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
10
|
}
|
|
17
11
|
return to;
|
|
18
12
|
};
|
|
19
|
-
var
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
27
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// pkgs/@akanjs/test/index.ts
|
|
30
15
|
var test_exports = {};
|
|
31
|
-
__export(test_exports, {
|
|
32
|
-
sample: () => sample,
|
|
33
|
-
sampleOf: () => sampleOf
|
|
34
|
-
});
|
|
35
16
|
module.exports = __toCommonJS(test_exports);
|
|
36
|
-
|
|
37
|
-
// pkgs/@akanjs/base/src/base.ts
|
|
38
|
-
var version = "0.9.0";
|
|
39
|
-
var logo = `
|
|
40
|
-
_ _ _
|
|
41
|
-
/ \\ | | ____ _ _ __ (_)___
|
|
42
|
-
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
43
|
-
/ ___ \\| < (_| | | | |_ | \\__ \\
|
|
44
|
-
/_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
|
|
45
|
-
|__/ ver ${version}
|
|
46
|
-
? See more details on docs https://www.akanjs.com/docs
|
|
47
|
-
\u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
|
|
48
|
-
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
// pkgs/@akanjs/base/src/baseEnv.ts
|
|
52
|
-
var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
|
|
53
|
-
var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
|
|
54
|
-
var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
|
|
55
|
-
if (appName === "unknown")
|
|
56
|
-
throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
|
|
57
|
-
if (repoName === "unknown")
|
|
58
|
-
throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
|
|
59
|
-
if (serveDomain === "unknown")
|
|
60
|
-
throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
|
|
61
|
-
var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
62
|
-
var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
63
|
-
var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
|
|
64
|
-
var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
|
|
65
|
-
var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
|
|
66
|
-
var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
|
|
67
|
-
var baseEnv = {
|
|
68
|
-
repoName,
|
|
69
|
-
serveDomain,
|
|
70
|
-
appName,
|
|
71
|
-
environment,
|
|
72
|
-
operationType,
|
|
73
|
-
operationMode,
|
|
74
|
-
networkType,
|
|
75
|
-
tunnelUsername,
|
|
76
|
-
tunnelPassword
|
|
77
|
-
};
|
|
78
|
-
var side = typeof window === "undefined" ? "server" : "client";
|
|
79
|
-
var renderMode = process.env.RENDER_ENV ?? "ssr";
|
|
80
|
-
var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
81
|
-
var clientPort = parseInt(
|
|
82
|
-
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
|
|
83
|
-
);
|
|
84
|
-
var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
|
|
85
|
-
var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
86
|
-
var serverHost = process.env.SERVER_HOST ?? (operationMode === "local" ? typeof window === "undefined" ? "localhost" : window.location.host.split(":")[0] : renderMode === "csr" ? `${appName}-${environment}.${serveDomain}` : side === "client" ? window.location.host.split(":")[0] : operationMode === "cloud" ? `backend-svc.${appName}-${environment}.svc.cluster.local` : "localhost");
|
|
87
|
-
var serverPort = parseInt(
|
|
88
|
-
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
89
|
-
);
|
|
90
|
-
var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
|
|
91
|
-
var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
92
|
-
var serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
93
|
-
var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
94
|
-
var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
95
|
-
var baseClientEnv = {
|
|
96
|
-
...baseEnv,
|
|
97
|
-
side,
|
|
98
|
-
renderMode,
|
|
99
|
-
websocket: true,
|
|
100
|
-
clientHost,
|
|
101
|
-
clientPort,
|
|
102
|
-
clientHttpProtocol,
|
|
103
|
-
clientHttpUri,
|
|
104
|
-
serverHost,
|
|
105
|
-
serverPort,
|
|
106
|
-
serverHttpProtocol,
|
|
107
|
-
serverHttpUri,
|
|
108
|
-
serverGraphqlUri,
|
|
109
|
-
serverWsProtocol,
|
|
110
|
-
serverWsUri
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// pkgs/@akanjs/base/src/scalar.ts
|
|
114
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
115
|
-
var dayjs = import_dayjs.default;
|
|
116
|
-
var Int = class {
|
|
117
|
-
__Scalar__;
|
|
118
|
-
};
|
|
119
|
-
var Upload = class {
|
|
120
|
-
__Scalar__;
|
|
121
|
-
filename;
|
|
122
|
-
mimetype;
|
|
123
|
-
encoding;
|
|
124
|
-
createReadStream;
|
|
125
|
-
};
|
|
126
|
-
var Float = class {
|
|
127
|
-
__Scalar__;
|
|
128
|
-
};
|
|
129
|
-
var ID = class {
|
|
130
|
-
__Scalar__;
|
|
131
|
-
};
|
|
132
|
-
var JSON = class {
|
|
133
|
-
__Scalar__;
|
|
134
|
-
};
|
|
135
|
-
var getNonArrayModel = (arraiedModel) => {
|
|
136
|
-
let arrDepth = 0;
|
|
137
|
-
let target = arraiedModel;
|
|
138
|
-
while (Array.isArray(target)) {
|
|
139
|
-
target = target[0];
|
|
140
|
-
arrDepth++;
|
|
141
|
-
}
|
|
142
|
-
return [target, arrDepth];
|
|
143
|
-
};
|
|
144
|
-
var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON, Map]);
|
|
145
|
-
var scalarNameMap = /* @__PURE__ */ new Map([
|
|
146
|
-
[ID, "ID"],
|
|
147
|
-
[Int, "Int"],
|
|
148
|
-
[Float, "Float"],
|
|
149
|
-
[String, "String"],
|
|
150
|
-
[Boolean, "Boolean"],
|
|
151
|
-
[Date, "Date"],
|
|
152
|
-
[Upload, "Upload"],
|
|
153
|
-
[JSON, "JSON"],
|
|
154
|
-
[Map, "Map"]
|
|
155
|
-
]);
|
|
156
|
-
var scalarArgMap = /* @__PURE__ */ new Map([
|
|
157
|
-
[ID, null],
|
|
158
|
-
[String, ""],
|
|
159
|
-
[Boolean, false],
|
|
160
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
161
|
-
[Int, 0],
|
|
162
|
-
[Float, 0],
|
|
163
|
-
[JSON, {}],
|
|
164
|
-
[Map, {}]
|
|
165
|
-
]);
|
|
166
|
-
var scalarDefaultMap = /* @__PURE__ */ new Map([
|
|
167
|
-
[ID, null],
|
|
168
|
-
[String, ""],
|
|
169
|
-
[Boolean, false],
|
|
170
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
171
|
-
[Int, 0],
|
|
172
|
-
[Float, 0],
|
|
173
|
-
[JSON, {}]
|
|
174
|
-
]);
|
|
175
|
-
var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
|
|
176
|
-
var isGqlMap = (modelRef) => modelRef === Map;
|
|
177
|
-
|
|
178
|
-
// pkgs/@akanjs/common/src/isDayjs.ts
|
|
179
|
-
var import_dayjs2 = require("dayjs");
|
|
180
|
-
|
|
181
|
-
// pkgs/@akanjs/common/src/isQueryEqual.ts
|
|
182
|
-
var import_dayjs3 = __toESM(require("dayjs"));
|
|
183
|
-
|
|
184
|
-
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
185
|
-
var import_dayjs4 = __toESM(require("dayjs"));
|
|
186
|
-
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
|
|
187
|
-
import_dayjs4.default.extend(import_customParseFormat.default);
|
|
188
|
-
|
|
189
|
-
// pkgs/@akanjs/common/src/randomPick.ts
|
|
190
|
-
var randomPick = (arr) => arr[Math.floor(Math.random() * arr.length)];
|
|
191
|
-
|
|
192
|
-
// pkgs/@akanjs/common/src/randomPicks.ts
|
|
193
|
-
var randomPicks = (arr, count = 1, allowDuplicate = false) => {
|
|
194
|
-
if (!allowDuplicate && arr.length <= count)
|
|
195
|
-
return arr;
|
|
196
|
-
const idxs = [];
|
|
197
|
-
let pickIdx;
|
|
198
|
-
for (let i = 0; i < count; i++) {
|
|
199
|
-
do {
|
|
200
|
-
pickIdx = Math.floor(Math.random() * arr.length);
|
|
201
|
-
} while (!allowDuplicate && idxs.includes(pickIdx));
|
|
202
|
-
idxs.push(pickIdx);
|
|
203
|
-
}
|
|
204
|
-
return idxs.map((idx) => arr[idx]);
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
// pkgs/@akanjs/common/src/pluralize.ts
|
|
208
|
-
var import_pluralize = __toESM(require("pluralize"));
|
|
209
|
-
|
|
210
|
-
// pkgs/@akanjs/common/src/Logger.ts
|
|
211
|
-
var import_dayjs5 = __toESM(require("dayjs"));
|
|
212
|
-
var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
213
|
-
var clc = {
|
|
214
|
-
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
215
|
-
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
216
|
-
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
217
|
-
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
218
|
-
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
219
|
-
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
220
|
-
};
|
|
221
|
-
var colorizeMap = {
|
|
222
|
-
trace: clc.bold,
|
|
223
|
-
verbose: clc.cyanBright,
|
|
224
|
-
debug: clc.magentaBright,
|
|
225
|
-
log: clc.green,
|
|
226
|
-
info: clc.green,
|
|
227
|
-
warn: clc.yellow,
|
|
228
|
-
error: clc.red
|
|
229
|
-
};
|
|
230
|
-
var Logger = class _Logger {
|
|
231
|
-
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
232
|
-
"InstanceLoader",
|
|
233
|
-
"RoutesResolver",
|
|
234
|
-
"RouterExplorer",
|
|
235
|
-
"NestFactory",
|
|
236
|
-
"WebSocketsController",
|
|
237
|
-
"GraphQLModule",
|
|
238
|
-
"NestApplication"
|
|
239
|
-
]);
|
|
240
|
-
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
241
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
242
|
-
static #startAt = (0, import_dayjs5.default)();
|
|
243
|
-
static setLevel(level) {
|
|
244
|
-
this.level = level;
|
|
245
|
-
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
246
|
-
}
|
|
247
|
-
name;
|
|
248
|
-
constructor(name) {
|
|
249
|
-
this.name = name;
|
|
250
|
-
}
|
|
251
|
-
trace(msg, context = "") {
|
|
252
|
-
if (_Logger.#levelIdx <= 0)
|
|
253
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
254
|
-
}
|
|
255
|
-
verbose(msg, context = "") {
|
|
256
|
-
if (_Logger.#levelIdx <= 1)
|
|
257
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
258
|
-
}
|
|
259
|
-
debug(msg, context = "") {
|
|
260
|
-
if (_Logger.#levelIdx <= 2)
|
|
261
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
262
|
-
}
|
|
263
|
-
log(msg, context = "") {
|
|
264
|
-
if (_Logger.#levelIdx <= 3)
|
|
265
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
266
|
-
}
|
|
267
|
-
info(msg, context = "") {
|
|
268
|
-
if (_Logger.#levelIdx <= 4)
|
|
269
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
270
|
-
}
|
|
271
|
-
warn(msg, context = "") {
|
|
272
|
-
if (_Logger.#levelIdx <= 5)
|
|
273
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
274
|
-
}
|
|
275
|
-
error(msg, context = "") {
|
|
276
|
-
if (_Logger.#levelIdx <= 6)
|
|
277
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
278
|
-
}
|
|
279
|
-
raw(msg, method) {
|
|
280
|
-
_Logger.rawLog(msg, method);
|
|
281
|
-
}
|
|
282
|
-
rawLog(msg, method) {
|
|
283
|
-
_Logger.rawLog(msg, method);
|
|
284
|
-
}
|
|
285
|
-
static trace(msg, context = "") {
|
|
286
|
-
if (_Logger.#levelIdx <= 0)
|
|
287
|
-
_Logger.#printMessages("App", msg, context, "trace");
|
|
288
|
-
}
|
|
289
|
-
static verbose(msg, context = "") {
|
|
290
|
-
if (_Logger.#levelIdx <= 1)
|
|
291
|
-
_Logger.#printMessages("App", msg, context, "verbose");
|
|
292
|
-
}
|
|
293
|
-
static debug(msg, context = "") {
|
|
294
|
-
if (_Logger.#levelIdx <= 2)
|
|
295
|
-
_Logger.#printMessages("App", msg, context, "debug");
|
|
296
|
-
}
|
|
297
|
-
static log(msg, context = "") {
|
|
298
|
-
if (_Logger.#levelIdx <= 3)
|
|
299
|
-
_Logger.#printMessages("App", msg, context, "log");
|
|
300
|
-
}
|
|
301
|
-
static info(msg, context = "") {
|
|
302
|
-
if (_Logger.#levelIdx <= 4)
|
|
303
|
-
_Logger.#printMessages("App", msg, context, "info");
|
|
304
|
-
}
|
|
305
|
-
static warn(msg, context = "") {
|
|
306
|
-
if (_Logger.#levelIdx <= 5)
|
|
307
|
-
_Logger.#printMessages("App", msg, context, "warn");
|
|
308
|
-
}
|
|
309
|
-
static error(msg, context = "") {
|
|
310
|
-
if (_Logger.#levelIdx <= 6)
|
|
311
|
-
_Logger.#printMessages("App", msg, context, "error");
|
|
312
|
-
}
|
|
313
|
-
static #colorize(msg, logLevel) {
|
|
314
|
-
return colorizeMap[logLevel](msg);
|
|
315
|
-
}
|
|
316
|
-
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
317
|
-
if (this.#ignoreCtxSet.has(context))
|
|
318
|
-
return;
|
|
319
|
-
const now = (0, import_dayjs5.default)();
|
|
320
|
-
const processMsg = this.#colorize(
|
|
321
|
-
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
322
|
-
logLevel
|
|
323
|
-
);
|
|
324
|
-
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
325
|
-
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
326
|
-
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
327
|
-
const contentMsg = this.#colorize(content, logLevel);
|
|
328
|
-
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
329
|
-
if (typeof window === "undefined")
|
|
330
|
-
process[writeStreamType].write(
|
|
331
|
-
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
332
|
-
`
|
|
333
|
-
);
|
|
334
|
-
else
|
|
335
|
-
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
336
|
-
`);
|
|
337
|
-
}
|
|
338
|
-
static rawLog(msg, method) {
|
|
339
|
-
this.raw(`${msg}
|
|
340
|
-
`, method);
|
|
341
|
-
}
|
|
342
|
-
static raw(msg, method) {
|
|
343
|
-
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
344
|
-
global.process.stdout.write(msg);
|
|
345
|
-
else
|
|
346
|
-
console.log(msg);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
// pkgs/@akanjs/constant/src/scalar.ts
|
|
351
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
352
|
-
var scalarExampleMap = /* @__PURE__ */ new Map([
|
|
353
|
-
[ID, "1234567890abcdef12345678"],
|
|
354
|
-
[Int, 0],
|
|
355
|
-
[Float, 0],
|
|
356
|
-
[String, "String"],
|
|
357
|
-
[Boolean, true],
|
|
358
|
-
[Date, (/* @__PURE__ */ new Date()).toISOString()],
|
|
359
|
-
[Upload, "FileUpload"],
|
|
360
|
-
[JSON, {}],
|
|
361
|
-
[Map, {}]
|
|
362
|
-
]);
|
|
363
|
-
var getClassMeta = (modelRef) => {
|
|
364
|
-
const [target] = getNonArrayModel(modelRef);
|
|
365
|
-
const classMeta = Reflect.getMetadata("class", target.prototype);
|
|
366
|
-
if (!classMeta)
|
|
367
|
-
throw new Error(`No ClassMeta for this target ${target.name}`);
|
|
368
|
-
return classMeta;
|
|
369
|
-
};
|
|
370
|
-
var getFieldMetas = (modelRef) => {
|
|
371
|
-
const [target] = getNonArrayModel(modelRef);
|
|
372
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
373
|
-
const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
|
|
374
|
-
return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
|
|
375
|
-
};
|
|
376
|
-
var getFieldMetaMapOnPrototype = (prototype) => {
|
|
377
|
-
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
378
|
-
return new Map(metadataMap);
|
|
379
|
-
};
|
|
380
|
-
var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
381
|
-
Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
// pkgs/@akanjs/constant/src/fieldMeta.ts
|
|
385
|
-
var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
386
|
-
const isArray = arrDepth > 0;
|
|
387
|
-
const isClass = !isGqlScalar(modelRef);
|
|
388
|
-
const isMap = isGqlMap(modelRef);
|
|
389
|
-
const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
|
|
390
|
-
const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
|
|
391
|
-
if (isMap && !option.of)
|
|
392
|
-
throw new Error("Map type must have 'of' option");
|
|
393
|
-
return (prototype, key) => {
|
|
394
|
-
const metadata = {
|
|
395
|
-
nullable: option.nullable ?? false,
|
|
396
|
-
ref: option.ref,
|
|
397
|
-
refPath: option.refPath,
|
|
398
|
-
refType: option.refType,
|
|
399
|
-
default: option.default ?? (isArray ? [] : null),
|
|
400
|
-
type: option.type,
|
|
401
|
-
fieldType: option.fieldType ?? "property",
|
|
402
|
-
immutable: option.immutable ?? false,
|
|
403
|
-
min: option.min,
|
|
404
|
-
max: option.max,
|
|
405
|
-
enum: option.enum,
|
|
406
|
-
select: option.select ?? true,
|
|
407
|
-
minlength: option.minlength,
|
|
408
|
-
maxlength: option.maxlength,
|
|
409
|
-
query: option.query,
|
|
410
|
-
accumulate: option.accumulate,
|
|
411
|
-
example: option.example,
|
|
412
|
-
validate: option.validate,
|
|
413
|
-
key,
|
|
414
|
-
name,
|
|
415
|
-
isClass,
|
|
416
|
-
isScalar: type === "scalar",
|
|
417
|
-
modelRef,
|
|
418
|
-
arrDepth,
|
|
419
|
-
isArray,
|
|
420
|
-
optArrDepth: optionArrDepth,
|
|
421
|
-
isMap,
|
|
422
|
-
of: option.of,
|
|
423
|
-
text: option.text
|
|
424
|
-
};
|
|
425
|
-
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
426
|
-
metadataMap.set(key, metadata);
|
|
427
|
-
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
428
|
-
};
|
|
429
|
-
};
|
|
430
|
-
var makeField = (customOption) => (returns, fieldOption) => {
|
|
431
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
432
|
-
if (!fieldOption)
|
|
433
|
-
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
434
|
-
const [opt, optArrDepth] = getNonArrayModel(fieldOption);
|
|
435
|
-
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
436
|
-
};
|
|
437
|
-
var Field = {
|
|
438
|
-
Prop: makeField({ fieldType: "property" }),
|
|
439
|
-
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
440
|
-
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
441
|
-
Resolve: makeField({ fieldType: "resolve" })
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// pkgs/@akanjs/constant/src/constantDecorator.ts
|
|
445
|
-
var import_reflect_metadata2 = require("reflect-metadata");
|
|
446
|
-
|
|
447
|
-
// pkgs/@akanjs/constant/src/filterMeta.ts
|
|
448
|
-
var setFilterMeta = (filterRef, filterMeta) => {
|
|
449
|
-
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
450
|
-
if (existingFilterMeta)
|
|
451
|
-
Object.assign(filterMeta.sort, existingFilterMeta.sort);
|
|
452
|
-
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
453
|
-
};
|
|
454
|
-
var getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
455
|
-
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
456
|
-
return new Map(metadataMap);
|
|
457
|
-
};
|
|
458
|
-
var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
459
|
-
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
460
|
-
};
|
|
461
|
-
var applyFilterKeyMeta = (option) => {
|
|
462
|
-
return (prototype, key, descriptor) => {
|
|
463
|
-
const metadata = { key, ...option, descriptor };
|
|
464
|
-
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
465
|
-
metadataMap.set(key, metadata);
|
|
466
|
-
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
467
|
-
};
|
|
468
|
-
};
|
|
469
|
-
var makeFilter = (customOption) => (fieldOption) => {
|
|
470
|
-
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
471
|
-
};
|
|
472
|
-
var getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
473
|
-
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
474
|
-
return filterArgMetas;
|
|
475
|
-
};
|
|
476
|
-
var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
477
|
-
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
478
|
-
};
|
|
479
|
-
var applyFilterArgMeta = (name, returns, argOption) => {
|
|
480
|
-
return (prototype, key, idx) => {
|
|
481
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
482
|
-
const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
|
|
483
|
-
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
484
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
485
|
-
filterArgMetas[idx] = filterArgMeta;
|
|
486
|
-
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
var Filter = {
|
|
490
|
-
Mongo: makeFilter({ type: "mongo" }),
|
|
491
|
-
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
492
|
-
Arg: applyFilterArgMeta
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
496
|
-
var import_reflect_metadata3 = require("reflect-metadata");
|
|
497
|
-
var defaultFieldMeta = {
|
|
498
|
-
fieldType: "property",
|
|
499
|
-
immutable: false,
|
|
500
|
-
select: true,
|
|
501
|
-
isClass: false,
|
|
502
|
-
isScalar: true,
|
|
503
|
-
nullable: false,
|
|
504
|
-
isArray: false,
|
|
505
|
-
arrDepth: 0,
|
|
506
|
-
optArrDepth: 0,
|
|
507
|
-
default: null,
|
|
508
|
-
isMap: false
|
|
509
|
-
};
|
|
510
|
-
var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
|
|
511
|
-
var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
512
|
-
var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
|
|
513
|
-
var removedAtFieldMeta = {
|
|
514
|
-
...defaultFieldMeta,
|
|
515
|
-
key: "removedAt",
|
|
516
|
-
name: "Date",
|
|
517
|
-
modelRef: Date,
|
|
518
|
-
nullable: true,
|
|
519
|
-
default: null
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
// pkgs/@akanjs/constant/src/classMeta.ts
|
|
523
|
-
var import_reflect_metadata4 = require("reflect-metadata");
|
|
524
|
-
var InputModelStorage = class {
|
|
525
|
-
};
|
|
526
|
-
var LightModelStorage = class {
|
|
527
|
-
};
|
|
528
|
-
var FullModelStorage = class {
|
|
529
|
-
};
|
|
530
|
-
var ScalarModelStorage = class {
|
|
531
|
-
};
|
|
532
|
-
var FilterModelStorage = class {
|
|
533
|
-
};
|
|
534
|
-
var hasTextField = (modelRef) => {
|
|
535
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
536
|
-
return fieldMetas.some(
|
|
537
|
-
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
538
|
-
);
|
|
539
|
-
};
|
|
540
|
-
var applyClassMeta = (type, modelType, storage) => {
|
|
541
|
-
return function(refName) {
|
|
542
|
-
return function(target) {
|
|
543
|
-
const modelRef = target;
|
|
544
|
-
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
545
|
-
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
546
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
547
|
-
};
|
|
548
|
-
};
|
|
549
|
-
};
|
|
550
|
-
var applyFilterMeta = (storage) => {
|
|
551
|
-
return function(refName) {
|
|
552
|
-
return function(target) {
|
|
553
|
-
const modelRef = target;
|
|
554
|
-
setFilterMeta(modelRef, { refName, sort: {} });
|
|
555
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
556
|
-
};
|
|
557
|
-
};
|
|
558
|
-
};
|
|
559
|
-
var Model = {
|
|
560
|
-
Light: applyClassMeta("light", "data", LightModelStorage),
|
|
561
|
-
Object: applyClassMeta("full", "ephemeral", FullModelStorage),
|
|
562
|
-
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
563
|
-
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
564
|
-
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
565
|
-
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
566
|
-
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
567
|
-
Filter: applyFilterMeta(FilterModelStorage)
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
// pkgs/@akanjs/test/src/sample.ts
|
|
571
|
-
var import_chance = __toESM(require("chance"));
|
|
572
|
-
var chance = new import_chance.default();
|
|
573
|
-
var sample = Object.assign(chance, {
|
|
574
|
-
dayjs: (opt) => dayjs(chance.date({ ...opt, min: opt?.min?.toDate(), max: opt?.max?.toDate() })),
|
|
575
|
-
pick: randomPick,
|
|
576
|
-
picks: randomPicks
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
// pkgs/@akanjs/test/src/sampleOf.ts
|
|
580
|
-
var getFieldTypeExample = {
|
|
581
|
-
email: () => sample.email(),
|
|
582
|
-
password: () => sample.string({ length: 8 }),
|
|
583
|
-
url: () => sample.url()
|
|
584
|
-
};
|
|
585
|
-
var scalarSampleMap = /* @__PURE__ */ new Map([
|
|
586
|
-
[ID, () => sample.hash({ length: 24 })],
|
|
587
|
-
[Int, () => sample.integer({ min: -1e4, max: 1e4 })],
|
|
588
|
-
[Float, () => sample.floating({ min: -1e4, max: 1e4 })],
|
|
589
|
-
[String, () => sample.string({ length: 100 })],
|
|
590
|
-
[Boolean, () => sample.bool()],
|
|
591
|
-
[Date, () => sample.dayjs()],
|
|
592
|
-
[Upload, () => "FileUpload"],
|
|
593
|
-
[JSON, () => ({})]
|
|
594
|
-
]);
|
|
595
|
-
var getScalarSample = (ref, fieldMeta) => {
|
|
596
|
-
if (fieldMeta.type) {
|
|
597
|
-
return getFieldTypeExample[fieldMeta.type]();
|
|
598
|
-
} else if (typeof fieldMeta.min === "number") {
|
|
599
|
-
return fieldMeta.min;
|
|
600
|
-
} else if (typeof fieldMeta.max === "number") {
|
|
601
|
-
return fieldMeta.max;
|
|
602
|
-
} else {
|
|
603
|
-
return scalarSampleMap.get(ref)?.() ?? null;
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
var makeSample = (fieldMeta) => {
|
|
607
|
-
if (fieldMeta.default)
|
|
608
|
-
return typeof fieldMeta.default === "function" ? fieldMeta.default() : fieldMeta.default;
|
|
609
|
-
else if (fieldMeta.enum)
|
|
610
|
-
return randomPick([...fieldMeta.enum.values]);
|
|
611
|
-
if (isGqlScalar(fieldMeta.modelRef))
|
|
612
|
-
return getScalarSample(fieldMeta.modelRef, fieldMeta);
|
|
613
|
-
return Object.fromEntries(
|
|
614
|
-
getFieldMetas(fieldMeta.modelRef).map(
|
|
615
|
-
(fieldMeta2) => [
|
|
616
|
-
fieldMeta2.key,
|
|
617
|
-
fieldMeta2.arrDepth ? [] : fieldMeta2.isClass && !fieldMeta2.isScalar ? null : makeSample(fieldMeta2)
|
|
618
|
-
]
|
|
619
|
-
)
|
|
620
|
-
);
|
|
621
|
-
};
|
|
622
|
-
var sampleOf = (modelRef) => {
|
|
623
|
-
return Object.fromEntries(
|
|
624
|
-
getFieldMetas(modelRef).map((fieldMeta) => [
|
|
625
|
-
fieldMeta.key,
|
|
626
|
-
fieldMeta.arrDepth ? [] : fieldMeta.isClass && !fieldMeta.isScalar ? null : makeSample(fieldMeta)
|
|
627
|
-
])
|
|
628
|
-
);
|
|
629
|
-
};
|
|
630
|
-
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
17
|
+
__reExport(test_exports, require("./src"), module.exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,9 +15,14 @@
|
|
|
15
15
|
"node": ">=22"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@nx/devkit": "^20.7.2",
|
|
19
|
+
"@nx/playwright": "^20.7.2",
|
|
20
|
+
"@playwright/test": "^1.51.1",
|
|
18
21
|
"chance": "^1.1.12",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
+
"dotenv": "^16.4.7",
|
|
23
|
+
"mongodb-memory-server": "^10.1.3",
|
|
24
|
+
"mongoose": "^8.9.3",
|
|
25
|
+
"redis-memory-server": "^0.11.0",
|
|
26
|
+
"tsconfig-paths": "^4.2.0"
|
|
22
27
|
}
|
|
23
28
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var src_exports = {};
|
|
19
|
+
__export(src_exports, {
|
|
20
|
+
sample: () => import_sample.sample,
|
|
21
|
+
sampleOf: () => import_sampleOf.sampleOf
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
var import_sampleOf = require("./sampleOf");
|
|
25
|
+
var import_sample = require("./sample");
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var jest_config_base_exports = {};
|
|
19
|
+
__export(jest_config_base_exports, {
|
|
20
|
+
withBase: () => withBase
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(jest_config_base_exports);
|
|
23
|
+
var import_dotenv = require("dotenv");
|
|
24
|
+
const withBase = (name) => {
|
|
25
|
+
(0, import_dotenv.config)();
|
|
26
|
+
process.env.NEXT_PUBLIC_ENV = "testing";
|
|
27
|
+
process.env.NEXT_PUBLIC_OPERATION_MODE = "local";
|
|
28
|
+
process.env.NEXT_PUBLIC_APP_NAME = name;
|
|
29
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
30
|
+
const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? "../../pkgs/" : "";
|
|
31
|
+
return {
|
|
32
|
+
displayName: name,
|
|
33
|
+
resolver: "@nx/jest/plugins/resolver",
|
|
34
|
+
globalSetup: `${akanjsPrefix}@akanjs/test/src/jest.globalSetup.ts`,
|
|
35
|
+
setupFilesAfterEnv: [`${akanjsPrefix}@akanjs/test/src/jest.setupFilesAfterEnv.ts`],
|
|
36
|
+
globalTeardown: `${akanjsPrefix}@akanjs/test/src/jest.globalTeardown.ts`,
|
|
37
|
+
testMatch: ["**/?(*.)+(test).ts?(x)"],
|
|
38
|
+
testPathIgnorePatterns: ["/node_modules/", "/app/"],
|
|
39
|
+
maxWorkers: 1,
|
|
40
|
+
transform: {
|
|
41
|
+
"signal\\.(test)\\.ts$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
|
|
42
|
+
"^.+\\.(ts|js|html)$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }]
|
|
43
|
+
},
|
|
44
|
+
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
|
|
45
|
+
coverageDirectory: `../../coverage/libs/${name}`,
|
|
46
|
+
coverageReporters: ["html"],
|
|
47
|
+
testEnvironment: "node",
|
|
48
|
+
testEnvironmentOptions: {
|
|
49
|
+
customExportConditions: ["node", "require", "default"]
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var jest_globalSetup_exports = {};
|
|
19
|
+
__export(jest_globalSetup_exports, {
|
|
20
|
+
default: () => jest_globalSetup_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(jest_globalSetup_exports);
|
|
23
|
+
var import_register = require("tsconfig-paths/register");
|
|
24
|
+
var import_jest = require("./jest.testServer");
|
|
25
|
+
const setup = async (globalConfig, projectConfig) => {
|
|
26
|
+
const { env } = require(`${globalConfig.rootDir}/env/env.server.testing`);
|
|
27
|
+
const { fetch, registerModules } = require(`${globalConfig.rootDir}/server`);
|
|
28
|
+
const maxWorkers = globalConfig.maxWorkers;
|
|
29
|
+
if (!maxWorkers)
|
|
30
|
+
throw new Error("maxWorkers is not defined");
|
|
31
|
+
const testServers = new Array(maxWorkers).fill(0).map((_, idx) => new import_jest.TestServer(registerModules, env, idx + 1));
|
|
32
|
+
await Promise.all(testServers.map((server) => server.init()));
|
|
33
|
+
global.__TEST_SERVERS__ = testServers;
|
|
34
|
+
global.fetch = fetch;
|
|
35
|
+
global.env = env;
|
|
36
|
+
global.registerModules = registerModules;
|
|
37
|
+
};
|
|
38
|
+
var jest_globalSetup_default = setup;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var jest_globalTeardown_exports = {};
|
|
19
|
+
__export(jest_globalTeardown_exports, {
|
|
20
|
+
default: () => jest_globalTeardown_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(jest_globalTeardown_exports);
|
|
23
|
+
var import_register = require("tsconfig-paths/register");
|
|
24
|
+
const teardown = async (globalConfig, projectConfig) => {
|
|
25
|
+
const testServers = global.__TEST_SERVERS__;
|
|
26
|
+
if (!testServers)
|
|
27
|
+
throw new Error("Test servers are not defined");
|
|
28
|
+
await Promise.all(testServers.map((server) => server.terminate()));
|
|
29
|
+
};
|
|
30
|
+
var jest_globalTeardown_default = teardown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var import_jest = require("./jest.testServer");
|
|
2
|
+
const { env, fetch } = global;
|
|
3
|
+
jest.setTimeout(3e4);
|
|
4
|
+
global.beforeAll(async () => {
|
|
5
|
+
import_jest.TestServer.initClient(env);
|
|
6
|
+
await fetch.cleanup();
|
|
7
|
+
});
|
|
8
|
+
global.afterAll(async () => {
|
|
9
|
+
await fetch.client.terminate();
|
|
10
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type BackendEnv } from "@akanjs/base";
|
|
2
|
+
export declare class TestServer {
|
|
3
|
+
#private;
|
|
4
|
+
workerId: number;
|
|
5
|
+
static initClient(env: BackendEnv, workerId?: number): void;
|
|
6
|
+
constructor(registerModules: (options: any) => any[], env: BackendEnv, workerId?: number);
|
|
7
|
+
init(): Promise<void>;
|
|
8
|
+
startMongo(): Promise<string>;
|
|
9
|
+
cleanup(): Promise<void>;
|
|
10
|
+
terminate(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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 __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var jest_testServer_exports = {};
|
|
29
|
+
__export(jest_testServer_exports, {
|
|
30
|
+
TestServer: () => TestServer
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(jest_testServer_exports);
|
|
33
|
+
var import_common = require("@akanjs/common");
|
|
34
|
+
var import_server = require("@akanjs/server");
|
|
35
|
+
var import_signal = require("@akanjs/signal");
|
|
36
|
+
var import_mongodb_memory_server = require("mongodb-memory-server");
|
|
37
|
+
var import_mongoose = __toESM(require("mongoose"));
|
|
38
|
+
var import_redis_memory_server = require("redis-memory-server");
|
|
39
|
+
const MAX_RETRY = 5;
|
|
40
|
+
const TEST_LISTEN_PORT_BASE = 38080;
|
|
41
|
+
const TEST_MONGODB_PORT_BASE = 38081;
|
|
42
|
+
const TEST_REDIS_PORT_BASE = 38082;
|
|
43
|
+
const MIN_ACTIVATION_TIME = 0;
|
|
44
|
+
const MAX_ACTIVATION_TIME = 3e4;
|
|
45
|
+
class TestServer {
|
|
46
|
+
#logger = new import_common.Logger("TestServer");
|
|
47
|
+
#mongod;
|
|
48
|
+
#redis;
|
|
49
|
+
#registerModules;
|
|
50
|
+
#env;
|
|
51
|
+
workerId;
|
|
52
|
+
#startAt = Date.now();
|
|
53
|
+
#app;
|
|
54
|
+
#portOffset = 0;
|
|
55
|
+
static initClient(env, workerId = parseInt(process.env.JEST_WORKER_ID ?? "0")) {
|
|
56
|
+
if (workerId === 0)
|
|
57
|
+
throw new Error("TestClient should not be used in main thread");
|
|
58
|
+
const portOffset = workerId * 1e3 + env.appCode * 10;
|
|
59
|
+
const port = TEST_LISTEN_PORT_BASE + portOffset;
|
|
60
|
+
const endpoint = `http://localhost:${port}/backend/graphql`;
|
|
61
|
+
import_signal.client.init({ uri: endpoint });
|
|
62
|
+
}
|
|
63
|
+
constructor(registerModules, env, workerId) {
|
|
64
|
+
this.workerId = workerId ?? parseInt(process.env.JEST_WORKER_ID ?? "0");
|
|
65
|
+
if (this.workerId === 0)
|
|
66
|
+
throw new Error("TestServer should not be used in main thread");
|
|
67
|
+
this.#portOffset = this.workerId * 1e3 + env.appCode * 10;
|
|
68
|
+
this.#mongod = new import_mongodb_memory_server.MongoMemoryServer({ instance: { port: TEST_MONGODB_PORT_BASE + this.#portOffset } });
|
|
69
|
+
this.#redis = new import_redis_memory_server.RedisMemoryServer({ instance: { port: TEST_REDIS_PORT_BASE + this.#portOffset } });
|
|
70
|
+
this.#env = { ...env };
|
|
71
|
+
this.#registerModules = registerModules;
|
|
72
|
+
}
|
|
73
|
+
async init() {
|
|
74
|
+
for (let i = 0; i < MAX_RETRY; i++) {
|
|
75
|
+
try {
|
|
76
|
+
const watchdog = setTimeout(() => {
|
|
77
|
+
throw new Error("TestServer Init Timeout");
|
|
78
|
+
}, MAX_ACTIVATION_TIME);
|
|
79
|
+
await this.#init();
|
|
80
|
+
clearTimeout(watchdog);
|
|
81
|
+
return;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
this.#logger.error(e);
|
|
84
|
+
await this.terminate();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async #init() {
|
|
89
|
+
const now = Date.now();
|
|
90
|
+
this.#logger.log(`Test System #${this.workerId} Initializing...`);
|
|
91
|
+
const port = TEST_LISTEN_PORT_BASE + this.#portOffset;
|
|
92
|
+
const [mongoUri, redisHost, redisPort] = await Promise.all([
|
|
93
|
+
this.startMongo(),
|
|
94
|
+
this.#redis.getHost(),
|
|
95
|
+
this.#redis.getPort()
|
|
96
|
+
]);
|
|
97
|
+
this.#env.port = port;
|
|
98
|
+
this.#env.mongoUri = mongoUri;
|
|
99
|
+
this.#env.redisUri = `redis://${redisHost}:${redisPort}`;
|
|
100
|
+
this.#env.meiliUri = "http://localhost:7700/search";
|
|
101
|
+
this.#env.onCleanup = async () => {
|
|
102
|
+
await this.cleanup();
|
|
103
|
+
};
|
|
104
|
+
this.#app = await (0, import_server.createNestApp)({ registerModules: this.#registerModules, env: this.#env });
|
|
105
|
+
this.#logger.log(`Test System #${this.workerId} Initialized, Mongo: ${mongoUri}, Redis: ${redisHost}:${redisPort}`);
|
|
106
|
+
this.#startAt = Date.now();
|
|
107
|
+
this.#logger.log(`Test System #${this.workerId} Activation Time: ${this.#startAt - now}ms`);
|
|
108
|
+
}
|
|
109
|
+
async startMongo() {
|
|
110
|
+
await this.#mongod.start();
|
|
111
|
+
return this.#mongod.getUri();
|
|
112
|
+
}
|
|
113
|
+
async cleanup() {
|
|
114
|
+
const now = Date.now();
|
|
115
|
+
this.#logger.log("Mongo Memory Database Cleaning up...");
|
|
116
|
+
if (this.#mongod.state === "running") {
|
|
117
|
+
await this.#mongod.stop();
|
|
118
|
+
await this.#mongod.start(true);
|
|
119
|
+
}
|
|
120
|
+
this.#logger.log(`Mongo Memory Database Cleaned up in ${Date.now() - now}ms`);
|
|
121
|
+
}
|
|
122
|
+
async terminate() {
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
const elapsed = now - this.#startAt;
|
|
125
|
+
await (0, import_common.sleep)(50);
|
|
126
|
+
import_signal.client.io?.socket.close();
|
|
127
|
+
await this.#app.close();
|
|
128
|
+
if (elapsed < MIN_ACTIVATION_TIME) {
|
|
129
|
+
this.#logger.log(`waiting for ${MIN_ACTIVATION_TIME - elapsed}`);
|
|
130
|
+
await (0, import_common.sleep)(MIN_ACTIVATION_TIME - elapsed);
|
|
131
|
+
}
|
|
132
|
+
await Promise.all([import_mongoose.default.disconnect(), this.#mongod.stop(), this.#redis.stop()]);
|
|
133
|
+
this.#logger.log(`System Terminated in ${Date.now() - now}ms`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type PlaywrightTestConfig } from "@playwright/test";
|
|
2
|
+
/**
|
|
3
|
+
* Read environment variables from file.
|
|
4
|
+
* https://github.com/motdotla/dotenv
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* See https://playwright.dev/docs/test-configuration.
|
|
8
|
+
*/
|
|
9
|
+
export declare const withBase: (filename: string, config?: PlaywrightTestConfig) => PlaywrightTestConfig<{}, {}>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var playwright_config_base_exports = {};
|
|
19
|
+
__export(playwright_config_base_exports, {
|
|
20
|
+
withBase: () => withBase
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(playwright_config_base_exports);
|
|
23
|
+
var import_devkit = require("@nx/devkit");
|
|
24
|
+
var import_preset = require("@nx/playwright/preset");
|
|
25
|
+
var import_test = require("@playwright/test");
|
|
26
|
+
const baseURL = process.env.BASE_URL ?? "http://127.0.0.1:4200";
|
|
27
|
+
const projectName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
|
|
28
|
+
const withBase = (filename, config = {}) => (0, import_test.defineConfig)({
|
|
29
|
+
...(0, import_preset.nxE2EPreset)(filename, { testDir: "./app" }),
|
|
30
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
31
|
+
use: {
|
|
32
|
+
baseURL,
|
|
33
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
34
|
+
trace: "on-first-retry"
|
|
35
|
+
},
|
|
36
|
+
/* Run your local dev server before starting the tests */
|
|
37
|
+
webServer: {
|
|
38
|
+
command: `nx serve ${projectName}`,
|
|
39
|
+
url: "http://127.0.0.1:4200",
|
|
40
|
+
reuseExistingServer: !process.env.CI,
|
|
41
|
+
cwd: import_devkit.workspaceRoot
|
|
42
|
+
},
|
|
43
|
+
projects: [
|
|
44
|
+
{
|
|
45
|
+
name: "chromium",
|
|
46
|
+
use: { ...import_test.devices["Desktop Chrome"] }
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "firefox",
|
|
50
|
+
use: { ...import_test.devices["Desktop Firefox"] }
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "webkit",
|
|
54
|
+
use: { ...import_test.devices["Desktop Safari"] }
|
|
55
|
+
}
|
|
56
|
+
// Uncomment for mobile browsers support
|
|
57
|
+
/* {
|
|
58
|
+
name: 'Mobile Chrome',
|
|
59
|
+
use: { ...devices['Pixel 5'] },
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'Mobile Safari',
|
|
63
|
+
use: { ...devices['iPhone 12'] },
|
|
64
|
+
}, */
|
|
65
|
+
// Uncomment for branded browsers
|
|
66
|
+
/* {
|
|
67
|
+
name: 'Microsoft Edge',
|
|
68
|
+
use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'Google Chrome',
|
|
72
|
+
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
|
73
|
+
} */
|
|
74
|
+
],
|
|
75
|
+
...config
|
|
76
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Page } from "@playwright/test";
|
|
2
|
+
import { test } from "@playwright/test";
|
|
3
|
+
export { expect } from "@playwright/test";
|
|
4
|
+
export { test };
|
|
5
|
+
export declare class PageAgent {
|
|
6
|
+
#private;
|
|
7
|
+
readonly page: Page;
|
|
8
|
+
constructor(page: Page);
|
|
9
|
+
goto(path: string): Promise<void>;
|
|
10
|
+
waitForPathChange(path?: string): Promise<unknown>;
|
|
11
|
+
wait(ms?: number): Promise<void>;
|
|
12
|
+
url(): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var playwright_pageAgent_exports = {};
|
|
19
|
+
__export(playwright_pageAgent_exports, {
|
|
20
|
+
PageAgent: () => PageAgent,
|
|
21
|
+
expect: () => import_test3.expect,
|
|
22
|
+
test: () => import_test2.test
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(playwright_pageAgent_exports);
|
|
25
|
+
var import_test2 = require("@playwright/test");
|
|
26
|
+
var import_test3 = require("@playwright/test");
|
|
27
|
+
class PageAgent {
|
|
28
|
+
page;
|
|
29
|
+
#defaultWaitMs = 500;
|
|
30
|
+
#isInitialized = false;
|
|
31
|
+
constructor(page) {
|
|
32
|
+
this.page = page;
|
|
33
|
+
}
|
|
34
|
+
async goto(path) {
|
|
35
|
+
await Promise.all([this.page.goto(path), this.waitForPathChange(path)]);
|
|
36
|
+
if (!this.#isInitialized) {
|
|
37
|
+
this.#isInitialized = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async waitForPathChange(path) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const timeout = setTimeout(() => {
|
|
43
|
+
reject(new Error("Timeout waiting for pathChange message"));
|
|
44
|
+
}, 3e4);
|
|
45
|
+
this.page.on("console", (msg) => {
|
|
46
|
+
if (msg.type() === "log" && msg.text().startsWith(`%cpathChange-finished:${path ?? ""}`)) {
|
|
47
|
+
clearInterval(timeout);
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
resolve(true);
|
|
50
|
+
}, this.#defaultWaitMs);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async wait(ms = this.#defaultWaitMs) {
|
|
56
|
+
await this.page.waitForTimeout(ms);
|
|
57
|
+
}
|
|
58
|
+
url() {
|
|
59
|
+
return "/" + this.page.url().split("/").slice(4).join("/");
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/sample.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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 __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var sample_exports = {};
|
|
29
|
+
__export(sample_exports, {
|
|
30
|
+
sample: () => sample
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(sample_exports);
|
|
33
|
+
var import_base = require("@akanjs/base");
|
|
34
|
+
var import_common = require("@akanjs/common");
|
|
35
|
+
var import_chance = __toESM(require("chance"));
|
|
36
|
+
const chance = new import_chance.default();
|
|
37
|
+
const sample = Object.assign(chance, {
|
|
38
|
+
dayjs: (opt) => (0, import_base.dayjs)(chance.date({ ...opt, min: opt?.min?.toDate(), max: opt?.max?.toDate() })),
|
|
39
|
+
pick: import_common.randomPick,
|
|
40
|
+
picks: import_common.randomPicks
|
|
41
|
+
});
|
package/src/sampleOf.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var sampleOf_exports = {};
|
|
19
|
+
__export(sampleOf_exports, {
|
|
20
|
+
sampleOf: () => sampleOf
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(sampleOf_exports);
|
|
23
|
+
var import_base = require("@akanjs/base");
|
|
24
|
+
var import_common = require("@akanjs/common");
|
|
25
|
+
var import_constant = require("@akanjs/constant");
|
|
26
|
+
var import_sample = require("./sample");
|
|
27
|
+
const getFieldTypeExample = {
|
|
28
|
+
email: () => import_sample.sample.email(),
|
|
29
|
+
password: () => import_sample.sample.string({ length: 8 }),
|
|
30
|
+
url: () => import_sample.sample.url()
|
|
31
|
+
};
|
|
32
|
+
const scalarSampleMap = /* @__PURE__ */ new Map([
|
|
33
|
+
[import_base.ID, () => import_sample.sample.hash({ length: 24 })],
|
|
34
|
+
[import_base.Int, () => import_sample.sample.integer({ min: -1e4, max: 1e4 })],
|
|
35
|
+
[import_base.Float, () => import_sample.sample.floating({ min: -1e4, max: 1e4 })],
|
|
36
|
+
[String, () => import_sample.sample.string({ length: 100 })],
|
|
37
|
+
[Boolean, () => import_sample.sample.bool()],
|
|
38
|
+
[Date, () => import_sample.sample.dayjs()],
|
|
39
|
+
[import_base.Upload, () => "FileUpload"],
|
|
40
|
+
[import_base.JSON, () => ({})]
|
|
41
|
+
]);
|
|
42
|
+
const getScalarSample = (ref, fieldMeta) => {
|
|
43
|
+
if (fieldMeta.type) {
|
|
44
|
+
return getFieldTypeExample[fieldMeta.type]();
|
|
45
|
+
} else if (typeof fieldMeta.min === "number") {
|
|
46
|
+
return fieldMeta.min;
|
|
47
|
+
} else if (typeof fieldMeta.max === "number") {
|
|
48
|
+
return fieldMeta.max;
|
|
49
|
+
} else {
|
|
50
|
+
return scalarSampleMap.get(ref)?.() ?? null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const makeSample = (fieldMeta) => {
|
|
54
|
+
if (fieldMeta.default)
|
|
55
|
+
return typeof fieldMeta.default === "function" ? fieldMeta.default() : fieldMeta.default;
|
|
56
|
+
else if (fieldMeta.enum)
|
|
57
|
+
return (0, import_common.randomPick)([...fieldMeta.enum.values]);
|
|
58
|
+
if ((0, import_base.isGqlScalar)(fieldMeta.modelRef))
|
|
59
|
+
return getScalarSample(fieldMeta.modelRef, fieldMeta);
|
|
60
|
+
return Object.fromEntries(
|
|
61
|
+
(0, import_constant.getFieldMetas)(fieldMeta.modelRef).map(
|
|
62
|
+
(fieldMeta2) => [
|
|
63
|
+
fieldMeta2.key,
|
|
64
|
+
fieldMeta2.arrDepth ? [] : fieldMeta2.isClass && !fieldMeta2.isScalar ? null : makeSample(fieldMeta2)
|
|
65
|
+
]
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
const sampleOf = (modelRef) => {
|
|
70
|
+
return Object.fromEntries(
|
|
71
|
+
(0, import_constant.getFieldMetas)(modelRef).map((fieldMeta) => [
|
|
72
|
+
fieldMeta.key,
|
|
73
|
+
fieldMeta.arrDepth ? [] : fieldMeta.isClass && !fieldMeta.isScalar ? null : makeSample(fieldMeta)
|
|
74
|
+
])
|
|
75
|
+
);
|
|
76
|
+
};
|