@akanjs/test 0.0.39 → 0.0.40
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.d.ts +3 -0
- package/index.js +21 -626
- package/package.json +2 -7
- package/src/index.d.ts +3 -0
- package/src/index.js +30 -0
- package/src/jest.config.base.d.ts +5 -0
- package/src/jest.config.base.js +85 -0
- package/src/jest.globalSetup.d.ts +5 -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 +2 -0
- package/src/jest.setupFilesAfterEnv.js +10 -0
- package/src/jest.testServer.d.ts +44 -0
- package/src/jest.testServer.js +160 -0
- package/src/playwright.config.base.d.ts +12 -0
- package/src/playwright.config.base.js +71 -0
- package/src/playwright.pageAgent.d.ts +14 -0
- package/src/playwright.pageAgent.js +74 -0
- package/src/sample.d.ts +17 -0
- package/src/sample.js +50 -0
- package/src/sampleOf.d.ts +33 -0
- package/src/sampleOf.js +110 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
|
|
3
|
+
type Type<T = any> = new (...args: any[]) => T;
|
|
4
|
+
|
|
5
|
+
declare class BaseObject {
|
|
6
|
+
id: string;
|
|
7
|
+
createdAt: Dayjs;
|
|
8
|
+
updatedAt: Dayjs;
|
|
9
|
+
removedAt: Dayjs | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
13
|
+
type OptionalKeys<T> = T extends {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
} ? {
|
|
16
|
+
[K in keyof T]-?: null extends T[K] ? K : never;
|
|
17
|
+
}[keyof T] : never;
|
|
18
|
+
type ObjectToId<O, D = Dayjs> = O extends BaseObject ? string : O extends BaseObject[] ? string[] : O extends Dayjs ? D : O extends {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
} ? DocumentModel<O> : O;
|
|
21
|
+
type DocumentModel<T, D = Dayjs> = T extends (infer S)[] ? DocumentModel<S>[] : T extends string ? T : T extends number ? T : T extends boolean ? T : T extends Dayjs ? T : T extends Map<infer K, infer V> ? Map<K, DocumentModel<V, D>> : Optional<{
|
|
22
|
+
[K in keyof GetStateObject<T>]: T[K] extends infer S ? S extends null ? undefined : ObjectToId<T[K], D> : never;
|
|
23
|
+
}, OptionalKeys<GetStateObject<T>>>;
|
|
24
|
+
type GetStateObject<T> = Omit<{
|
|
25
|
+
[K in keyof T as T[K] extends (...args: any) => any ? never : K]: T[K];
|
|
26
|
+
}, "prototype">;
|
|
27
|
+
|
|
28
|
+
type SampleOf<Model> = DocumentModel<{
|
|
29
|
+
[K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>;
|
|
30
|
+
}>;
|
|
31
|
+
declare const sampleOf: <Model>(modelRef: Type<Model>) => DocumentModel<{ [K in keyof Model as Model[K] extends BaseObject ? never : K]: NonNullable<Model[K]>; }>;
|
|
32
|
+
|
|
33
|
+
export { type SampleOf, sampleOf };
|
package/src/sampleOf.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sampleOf_exports = {};
|
|
20
|
+
__export(sampleOf_exports, {
|
|
21
|
+
sampleOf: () => sampleOf
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sampleOf_exports);
|
|
24
|
+
var import_base = require("@akanjs/base");
|
|
25
|
+
var import_common = require("@akanjs/common");
|
|
26
|
+
var import_constant = require("@akanjs/constant");
|
|
27
|
+
var import_sample = require("./sample");
|
|
28
|
+
const getFieldTypeExample = {
|
|
29
|
+
email: /* @__PURE__ */ __name(() => import_sample.sample.email(), "email"),
|
|
30
|
+
password: /* @__PURE__ */ __name(() => import_sample.sample.string({
|
|
31
|
+
length: 8
|
|
32
|
+
}), "password"),
|
|
33
|
+
url: /* @__PURE__ */ __name(() => import_sample.sample.url(), "url")
|
|
34
|
+
};
|
|
35
|
+
const scalarSampleMap = /* @__PURE__ */ new Map([
|
|
36
|
+
[
|
|
37
|
+
import_base.ID,
|
|
38
|
+
() => import_sample.sample.hash({
|
|
39
|
+
length: 24
|
|
40
|
+
})
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
import_base.Int,
|
|
44
|
+
() => import_sample.sample.integer({
|
|
45
|
+
min: -1e4,
|
|
46
|
+
max: 1e4
|
|
47
|
+
})
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
import_base.Float,
|
|
51
|
+
() => import_sample.sample.floating({
|
|
52
|
+
min: -1e4,
|
|
53
|
+
max: 1e4
|
|
54
|
+
})
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
String,
|
|
58
|
+
() => import_sample.sample.string({
|
|
59
|
+
length: 100
|
|
60
|
+
})
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
Boolean,
|
|
64
|
+
() => import_sample.sample.bool()
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
Date,
|
|
68
|
+
() => import_sample.sample.dayjs()
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
import_base.Upload,
|
|
72
|
+
() => "FileUpload"
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
import_base.JSON,
|
|
76
|
+
() => ({})
|
|
77
|
+
]
|
|
78
|
+
]);
|
|
79
|
+
const getScalarSample = /* @__PURE__ */ __name((ref, fieldMeta) => {
|
|
80
|
+
if (fieldMeta.type) {
|
|
81
|
+
return getFieldTypeExample[fieldMeta.type]();
|
|
82
|
+
} else if (typeof fieldMeta.min === "number") {
|
|
83
|
+
return fieldMeta.min;
|
|
84
|
+
} else if (typeof fieldMeta.max === "number") {
|
|
85
|
+
return fieldMeta.max;
|
|
86
|
+
} else {
|
|
87
|
+
return scalarSampleMap.get(ref)?.() ?? null;
|
|
88
|
+
}
|
|
89
|
+
}, "getScalarSample");
|
|
90
|
+
const makeSample = /* @__PURE__ */ __name((fieldMeta) => {
|
|
91
|
+
if (fieldMeta.default) return typeof fieldMeta.default === "function" ? fieldMeta.default() : fieldMeta.default;
|
|
92
|
+
else if (fieldMeta.enum) return (0, import_common.randomPick)([
|
|
93
|
+
...fieldMeta.enum.values
|
|
94
|
+
]);
|
|
95
|
+
if ((0, import_base.isGqlScalar)(fieldMeta.modelRef)) return getScalarSample(fieldMeta.modelRef, fieldMeta);
|
|
96
|
+
return Object.fromEntries((0, import_constant.getFieldMetas)(fieldMeta.modelRef).map((fieldMeta2) => [
|
|
97
|
+
fieldMeta2.key,
|
|
98
|
+
fieldMeta2.arrDepth ? [] : fieldMeta2.isClass && !fieldMeta2.isScalar ? null : makeSample(fieldMeta2)
|
|
99
|
+
]));
|
|
100
|
+
}, "makeSample");
|
|
101
|
+
const sampleOf = /* @__PURE__ */ __name((modelRef) => {
|
|
102
|
+
return Object.fromEntries((0, import_constant.getFieldMetas)(modelRef).map((fieldMeta) => [
|
|
103
|
+
fieldMeta.key,
|
|
104
|
+
fieldMeta.arrDepth ? [] : fieldMeta.isClass && !fieldMeta.isScalar ? null : makeSample(fieldMeta)
|
|
105
|
+
]));
|
|
106
|
+
}, "sampleOf");
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
sampleOf
|
|
110
|
+
});
|