testeranto 0.49.9 → 0.62.0

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.
Files changed (241) hide show
  1. package/.nvmrc +1 -0
  2. package/README.md +71 -9
  3. package/dist/cjs-shim.js +12 -0
  4. package/dist/common/Features.js +2 -3
  5. package/dist/common/Node.js +53 -61
  6. package/dist/common/Project.js +272 -606
  7. package/dist/common/SubPackages/puppeteer.js +19 -0
  8. package/dist/common/{subPackages → SubPackages}/react/component/node.js +4 -4
  9. package/dist/common/{subPackages → SubPackages}/react/component/web.js +4 -4
  10. package/dist/common/SubPackages/react/jsx/index.js +13 -0
  11. package/dist/common/SubPackages/react/jsx/node.js +10 -0
  12. package/dist/common/SubPackages/react/jsx/web.js +10 -0
  13. package/dist/common/{subPackages → SubPackages}/react-dom/component/node.js +6 -6
  14. package/dist/common/{subPackages → SubPackages}/react-dom/component/web.js +11 -12
  15. package/dist/common/SubPackages/react-dom/jsx/node.js +39 -0
  16. package/dist/common/{subPackages → SubPackages}/react-dom/jsx/web.js +6 -27
  17. package/dist/common/{subPackages → SubPackages}/react-test-renderer/MemoExoticComponent/node.js +2 -2
  18. package/dist/common/{subPackages → SubPackages}/react-test-renderer/component/index.js +26 -15
  19. package/dist/common/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/component}/node.js +3 -5
  20. package/dist/common/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/component}/web.js +3 -5
  21. package/dist/common/{subPackages → SubPackages}/react-test-renderer/fc/node.js +4 -4
  22. package/dist/common/{subPackages → SubPackages}/react-test-renderer/fc/web.js +4 -4
  23. package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx/index.js +8 -2
  24. package/dist/common/{subPackages/react-test-renderer/jsx-promised → SubPackages/react-test-renderer/jsx}/node.js +4 -4
  25. package/dist/common/{subPackages/react → SubPackages/react-test-renderer}/jsx/web.js +4 -4
  26. package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.js +2 -2
  27. package/dist/common/{subPackages/react/jsx → SubPackages/react-test-renderer/jsx-promised}/node.js +2 -2
  28. package/dist/common/Types.js +32 -0
  29. package/dist/common/Web.js +41 -112
  30. package/dist/common/electron.js +188 -44
  31. package/dist/common/esbuildConfigs/features.js +14 -0
  32. package/dist/common/esbuildConfigs/index.js +20 -0
  33. package/dist/common/esbuildConfigs/node.js +35 -0
  34. package/dist/common/esbuildConfigs/report.js +48 -0
  35. package/dist/common/esbuildConfigs/tests.js +14 -0
  36. package/dist/common/esbuildConfigs/web.js +50 -0
  37. package/dist/common/lib/abstractBase.js +193 -0
  38. package/dist/common/lib/basebuilder.js +86 -0
  39. package/dist/common/lib/browser.js +26 -0
  40. package/dist/common/lib/classBuilder.js +41 -0
  41. package/dist/common/lib/core.js +52 -0
  42. package/dist/common/lib/index.js +19 -0
  43. package/dist/common/nodeWriterElectron.js +55 -0
  44. package/dist/common/preload.js +22 -21
  45. package/dist/common/report.html.js +31 -0
  46. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  47. package/dist/common/web.html.js +22 -0
  48. package/dist/module/Features.js +2 -3
  49. package/dist/module/Node.js +53 -61
  50. package/dist/module/Project.js +272 -583
  51. package/dist/module/SubPackages/puppeteer.js +14 -0
  52. package/dist/module/{subPackages → SubPackages}/react/component/node.js +3 -3
  53. package/dist/module/{subPackages → SubPackages}/react/component/web.js +3 -3
  54. package/dist/module/SubPackages/react/jsx/index.js +10 -0
  55. package/dist/module/SubPackages/react/jsx/node.js +5 -0
  56. package/dist/module/SubPackages/react/jsx/web.js +5 -0
  57. package/dist/module/{subPackages → SubPackages}/react-dom/component/node.js +5 -5
  58. package/dist/module/{subPackages → SubPackages}/react-dom/component/web.js +10 -11
  59. package/dist/module/SubPackages/react-dom/jsx/node.js +31 -0
  60. package/dist/module/{subPackages → SubPackages}/react-dom/jsx/web.js +5 -26
  61. package/dist/module/{subPackages → SubPackages}/react-test-renderer/MemoExoticComponent/node.js +2 -2
  62. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/index.js +23 -15
  63. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/node.js +2 -2
  64. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/web.js +2 -2
  65. package/dist/module/{subPackages → SubPackages}/react-test-renderer/fc/node.js +3 -3
  66. package/dist/module/{subPackages → SubPackages}/react-test-renderer/fc/web.js +3 -3
  67. package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx/index.js +8 -2
  68. package/dist/module/SubPackages/react-test-renderer/jsx/node.js +5 -0
  69. package/dist/module/SubPackages/react-test-renderer/jsx/web.js +5 -0
  70. package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.js +2 -2
  71. package/dist/module/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/jsx-promised}/node.js +1 -1
  72. package/dist/module/Types.js +30 -1
  73. package/dist/module/Web.js +41 -112
  74. package/dist/module/electron.js +189 -45
  75. package/dist/module/esbuildConfigs/features.js +12 -0
  76. package/dist/module/esbuildConfigs/index.js +18 -0
  77. package/dist/module/esbuildConfigs/node.js +30 -0
  78. package/dist/module/esbuildConfigs/report.js +48 -0
  79. package/dist/module/esbuildConfigs/tests.js +12 -0
  80. package/dist/module/esbuildConfigs/web.js +45 -0
  81. package/dist/module/lib/abstractBase.js +185 -0
  82. package/dist/module/lib/basebuilder.js +82 -0
  83. package/dist/module/lib/browser.js +22 -0
  84. package/dist/module/lib/classBuilder.js +37 -0
  85. package/dist/module/lib/core.js +49 -0
  86. package/dist/module/lib/index.js +15 -0
  87. package/dist/module/nodeWriterElectron.js +52 -0
  88. package/dist/module/preload.js +22 -21
  89. package/dist/module/report.html.js +29 -0
  90. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  91. package/dist/module/web.html.js +20 -0
  92. package/dist/prebuild/Report.css +10326 -0
  93. package/dist/prebuild/Report.js +37456 -0
  94. package/dist/types/Features.d.ts +5 -5
  95. package/dist/types/Node.d.ts +4 -11
  96. package/dist/types/NodeWriter.d.ts +1 -1
  97. package/dist/types/Project.d.ts +2 -27
  98. package/dist/types/SubPackages/puppeteer.d.ts +6 -0
  99. package/dist/types/SubPackages/react/component/node.d.ts +7 -0
  100. package/dist/types/SubPackages/react/component/web.d.ts +7 -0
  101. package/dist/types/SubPackages/react/jsx/index.d.ts +15 -0
  102. package/dist/types/SubPackages/react/jsx/node.d.ts +4 -0
  103. package/dist/types/SubPackages/react/jsx/web.d.ts +4 -0
  104. package/dist/types/{subPackages → SubPackages}/react-dom/component/node.d.ts +2 -4
  105. package/dist/types/SubPackages/react-dom/component/web.d.ts +5 -0
  106. package/dist/types/{subPackages → SubPackages}/react-dom/jsx/index.d.ts +3 -3
  107. package/dist/types/SubPackages/react-dom/jsx/node.d.ts +6 -0
  108. package/dist/types/SubPackages/react-dom/jsx/web.d.ts +5 -0
  109. package/dist/types/SubPackages/react-test-renderer/MemoExoticComponent/node.d.ts +5 -0
  110. package/dist/types/{subPackages → SubPackages}/react-test-renderer/component/index.d.ts +6 -6
  111. package/dist/types/SubPackages/react-test-renderer/component/node.d.ts +9 -0
  112. package/dist/types/SubPackages/react-test-renderer/component/web.d.ts +4 -0
  113. package/dist/types/SubPackages/react-test-renderer/fc/node.d.ts +8 -0
  114. package/dist/types/SubPackages/react-test-renderer/fc/web.d.ts +8 -0
  115. package/dist/types/{subPackages → SubPackages}/react-test-renderer/jsx/index.d.ts +5 -4
  116. package/dist/types/SubPackages/react-test-renderer/jsx/node.d.ts +9 -0
  117. package/dist/types/SubPackages/react-test-renderer/jsx/web.d.ts +9 -0
  118. package/dist/types/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.d.ts +4 -4
  119. package/dist/types/SubPackages/react-test-renderer/jsx-promised/node.d.ts +5 -0
  120. package/dist/types/SubPackages/react-test-renderer/jsx-promised/web.d.ts +5 -0
  121. package/dist/types/Types.d.ts +116 -3
  122. package/dist/types/Web.d.ts +4 -11
  123. package/dist/types/esbuildConfigs/features.d.ts +4 -0
  124. package/dist/types/esbuildConfigs/index.d.ts +4 -0
  125. package/dist/types/esbuildConfigs/node.d.ts +4 -0
  126. package/dist/types/esbuildConfigs/report.d.ts +0 -0
  127. package/dist/types/esbuildConfigs/tests.d.ts +4 -0
  128. package/dist/types/esbuildConfigs/web.d.ts +4 -0
  129. package/dist/types/lib/abstractBase.d.ts +102 -0
  130. package/dist/types/lib/basebuilder.d.ts +24 -0
  131. package/dist/types/lib/browser.d.ts +6 -0
  132. package/dist/types/lib/classBuilder.d.ts +6 -0
  133. package/dist/types/lib/core.d.ts +7 -0
  134. package/dist/types/lib/index.d.ts +57 -0
  135. package/dist/types/nodeWriterElectron.d.ts +2 -0
  136. package/dist/types/report.html.d.ts +2 -0
  137. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  138. package/dist/types/web.html.d.ts +2 -0
  139. package/electronBuild.ts +32 -0
  140. package/index.html +30 -0
  141. package/package.json +120 -85
  142. package/src/Features.ts +2 -4
  143. package/src/Node.ts +114 -160
  144. package/src/NodeWriter.ts +1 -4
  145. package/src/Project.ts +610 -753
  146. package/src/Report.tsx +30 -15
  147. package/src/SubPackages/puppeteer.ts +46 -0
  148. package/src/{subPackages → SubPackages}/react/component/node.ts +12 -32
  149. package/src/SubPackages/react/component/web.ts +53 -0
  150. package/src/SubPackages/react/jsx/index.ts +43 -0
  151. package/src/SubPackages/react/jsx/node.ts +29 -0
  152. package/src/SubPackages/react/jsx/web.ts +28 -0
  153. package/src/{subPackages → SubPackages}/react-dom/component/node.ts +11 -25
  154. package/src/{subPackages → SubPackages}/react-dom/component/web.ts +27 -32
  155. package/src/{subPackages → SubPackages}/react-dom/jsx/index.ts +3 -5
  156. package/src/SubPackages/react-dom/jsx/node.ts +68 -0
  157. package/src/{subPackages → SubPackages}/react-dom/jsx/web.ts +19 -62
  158. package/src/{subPackages → SubPackages}/react-test-renderer/MemoExoticComponent/node.ts +9 -28
  159. package/src/{subPackages → SubPackages}/react-test-renderer/component/index.ts +31 -29
  160. package/src/SubPackages/react-test-renderer/component/node.ts +22 -0
  161. package/src/SubPackages/react-test-renderer/component/web.ts +22 -0
  162. package/src/{subPackages → SubPackages}/react-test-renderer/fc/node.ts +14 -28
  163. package/src/{subPackages → SubPackages}/react-test-renderer/fc/web.ts +9 -25
  164. package/src/{subPackages → SubPackages}/react-test-renderer/jsx/index.ts +19 -16
  165. package/src/SubPackages/react-test-renderer/jsx/node.ts +24 -0
  166. package/src/SubPackages/react-test-renderer/jsx/web.ts +20 -0
  167. package/src/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.ts +7 -15
  168. package/src/SubPackages/react-test-renderer/jsx-promised/node.ts +19 -0
  169. package/src/SubPackages/react-test-renderer/jsx-promised/web.ts +22 -0
  170. package/src/Types.ts +334 -3
  171. package/src/Web.ts +104 -230
  172. package/src/cjs-shim.js +12 -0
  173. package/src/electron.ts +237 -46
  174. package/src/esbuildConfigs/features.ts +18 -0
  175. package/src/esbuildConfigs/index.ts +22 -0
  176. package/src/esbuildConfigs/node.ts +59 -0
  177. package/src/esbuildConfigs/report.ts +51 -0
  178. package/src/esbuildConfigs/tests.ts +20 -0
  179. package/src/esbuildConfigs/web.ts +73 -0
  180. package/src/lib/abstractBase.ts +459 -0
  181. package/src/lib/basebuilder.ts +253 -0
  182. package/src/lib/browser.ts +34 -0
  183. package/src/lib/classBuilder.ts +137 -0
  184. package/src/lib/core.ts +182 -0
  185. package/src/lib/index.ts +116 -0
  186. package/src/nodeWriterElectron.ts +71 -0
  187. package/src/preload.ts +23 -21
  188. package/src/report.html.ts +29 -0
  189. package/src/web.html.ts +20 -0
  190. package/tests/Rectangle.test.ts +189 -0
  191. package/tsconfig.json +19 -6
  192. package/tsconfig.module.json +15 -4
  193. package/tsconfig.types.json +14 -4
  194. package/yarn-error.log +3144 -0
  195. package/dist/common/core.js +0 -397
  196. package/dist/common/subPackages/react/jsx/index.js +0 -26
  197. package/dist/common/subPackages/react-dom/jsx/node.js +0 -95
  198. package/dist/common/subPackages/react-test-renderer/component/node.js +0 -8
  199. package/dist/common/subPackages/react-test-renderer/component/web.js +0 -8
  200. package/dist/module/Report.js +0 -186
  201. package/dist/module/core.js +0 -388
  202. package/dist/module/subPackages/react/jsx/index.js +0 -22
  203. package/dist/module/subPackages/react/jsx/node.js +0 -5
  204. package/dist/module/subPackages/react/jsx/web.js +0 -5
  205. package/dist/module/subPackages/react-dom/jsx/node.js +0 -87
  206. package/dist/module/subPackages/react-test-renderer/jsx/web.js +0 -5
  207. package/dist/module/subPackages/react-test-renderer/jsx-promised/node.js +0 -5
  208. package/dist/types/core.d.ts +0 -220
  209. package/dist/types/subPackages/react/component/node.d.ts +0 -12
  210. package/dist/types/subPackages/react/component/web.d.ts +0 -12
  211. package/dist/types/subPackages/react/jsx/index.d.ts +0 -15
  212. package/dist/types/subPackages/react/jsx/node.d.ts +0 -4
  213. package/dist/types/subPackages/react/jsx/web.d.ts +0 -4
  214. package/dist/types/subPackages/react-dom/component/web.d.ts +0 -19
  215. package/dist/types/subPackages/react-dom/jsx/node.d.ts +0 -8
  216. package/dist/types/subPackages/react-dom/jsx/web.d.ts +0 -5
  217. package/dist/types/subPackages/react-test-renderer/MemoExoticComponent/node.d.ts +0 -8
  218. package/dist/types/subPackages/react-test-renderer/component/node.d.ts +0 -9
  219. package/dist/types/subPackages/react-test-renderer/component/web.d.ts +0 -9
  220. package/dist/types/subPackages/react-test-renderer/fc/node.d.ts +0 -9
  221. package/dist/types/subPackages/react-test-renderer/fc/web.d.ts +0 -9
  222. package/dist/types/subPackages/react-test-renderer/jsx/node.d.ts +0 -4
  223. package/dist/types/subPackages/react-test-renderer/jsx/web.d.ts +0 -4
  224. package/dist/types/subPackages/react-test-renderer/jsx-promised/node.d.ts +0 -4
  225. package/dist/types/subPackages/react-test-renderer/jsx-promised/web.d.ts +0 -4
  226. package/src/core.ts +0 -1399
  227. package/src/subPackages/react/component/web.ts +0 -80
  228. package/src/subPackages/react/jsx/index.ts +0 -64
  229. package/src/subPackages/react/jsx/node.ts +0 -29
  230. package/src/subPackages/react/jsx/web.ts +0 -29
  231. package/src/subPackages/react-dom/jsx/node.ts +0 -146
  232. package/src/subPackages/react-test-renderer/component/node.ts +0 -30
  233. package/src/subPackages/react-test-renderer/component/web.ts +0 -30
  234. package/src/subPackages/react-test-renderer/jsx/node.ts +0 -31
  235. package/src/subPackages/react-test-renderer/jsx/web.ts +0 -31
  236. package/src/subPackages/react-test-renderer/jsx-promised/node.ts +0 -31
  237. package/src/subPackages/react-test-renderer/jsx-promised/web.ts +0 -31
  238. /package/dist/common/{subPackages → SubPackages}/react-dom/jsx/index.js +0 -0
  239. /package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx-promised/web.js +0 -0
  240. /package/dist/module/{subPackages → SubPackages}/react-dom/jsx/index.js +0 -0
  241. /package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx-promised/web.js +0 -0
package/src/core.ts DELETED
@@ -1,1399 +0,0 @@
1
- const defaultTestResource: ITTestResourceConfiguration = {
2
- name: "",
3
- fs: ".",
4
- ports: [],
5
- scheduled: false
6
- };
7
-
8
- export type IImplementer<IImplementation> = {
9
- name: string;
10
- fs: string;
11
- ports: number[];
12
- };
13
-
14
- export type ITTestResourceConfiguration = {
15
- name: string;
16
- fs: string;
17
- ports: number[];
18
- scheduled: boolean;
19
- };
20
-
21
- export type ITTestResourceRequirement = {
22
- name: string;
23
- ports: number;
24
- fs: string;
25
- };
26
-
27
- export type ITTestResourceRequest = {
28
- ports: number;
29
- };
30
-
31
- export type Modify<Type, Replace> = Omit<Type, keyof Replace> & Replace;
32
-
33
- export type ITTestShape = {
34
- suites;
35
- givens;
36
- whens;
37
- thens;
38
- checks;
39
- };
40
-
41
- export type ILogWriter = {
42
- createWriteStream: (line: string) => any | any,
43
- writeFileSync: (fp: string, contents: string) => any
44
- mkdirSync: (fp: string) => any
45
- testArtiFactoryfileWriter: (tLog: ITLog, n: (Promise) => void) =>
46
- (fPath: string, value: unknown) =>
47
- void
48
- }
49
-
50
- type IGivens<
51
- ISubject,
52
- IStore,
53
- ISelection,
54
- IThenShape
55
- > = Record<
56
- string,
57
- BaseGiven<
58
- ISubject,
59
- IStore,
60
- ISelection,
61
- IThenShape
62
- >
63
- >;
64
-
65
- type ITestCheckCallback<ITestShape extends ITTestShape> = {
66
- [K in keyof ITestShape["checks"]]: (
67
- name: string,
68
- features: string[],
69
- callbackA: (
70
- whens: {
71
- [K in keyof ITestShape["whens"]]: (
72
- ...unknown
73
- ) => BaseWhen<unknown, unknown, unknown>;
74
- },
75
- thens: {
76
- [K in keyof ITestShape["thens"]]: (
77
- ...unknown
78
- ) => BaseThen<unknown, unknown, unknown>;
79
- }
80
- ) => Promise<any>,
81
- ...xtrasA: ITestShape["checks"][K]
82
- ) => BaseCheck<unknown, unknown, unknown, unknown, ITestShape>;
83
- };
84
-
85
- export type ITestArtificer = (key: string, data: any) => void;
86
- export type IRunTimeAndSubject = {
87
- runtime: "just node" | "just web" | "both web and node";
88
- entrypoint: string;
89
- };
90
-
91
- type IRunner = (x: ITTestResourceConfiguration, t: ITLog) => Promise<
92
- BaseSuite<any, any, any, any, any, any>
93
- >;
94
-
95
- export type IT = {
96
- toObj(): object;
97
- name: string;
98
- givens: IGivens<unknown, unknown, unknown, unknown>;
99
- checks: BaseCheck<unknown, unknown, unknown, unknown, ITTestShape>[];
100
- testResourceConfiguration: ITTestResourceConfiguration;
101
- };
102
-
103
- export type ITestJob = {
104
- toObj(): object;
105
- test: IT;
106
- runner: IRunner;
107
- testResourceRequirement: ITTestResourceRequirement;
108
- receiveTestResourceConfig: (testResource?) => Promise<{
109
- failed: number,
110
- artifacts: Promise<unknown>[],
111
- logPromise: Promise<unknown>
112
- }>
113
- };
114
-
115
- export type ITestResults = Promise<{ test: IT }>[];
116
-
117
- export const defaultTestResourceRequirement: ITTestResourceRequest = {
118
- ports: 0
119
- };
120
-
121
- export type ITestArtifactory = (key: string, value: unknown) => unknown;
122
- export type ITLog = (...string) => void;
123
-
124
- export abstract class BaseSuite<
125
- IInput,
126
- ISubject,
127
- IStore,
128
- ISelection,
129
- IThenShape,
130
- ITestShape extends ITTestShape
131
- > {
132
- name: string;
133
- givens: IGivens<ISubject, IStore, ISelection, IThenShape>;
134
- checks: BaseCheck<ISubject, IStore, ISelection, IThenShape, ITestShape>[];
135
- store: IStore;
136
- fails: BaseGiven<ISubject, IStore, ISelection, IThenShape>[];
137
- testResourceConfiguration: ITTestResourceConfiguration;
138
- index: number;
139
-
140
- constructor(
141
- name: string,
142
- index: number,
143
- givens: IGivens<ISubject, IStore, ISelection, IThenShape> = {},
144
- checks: BaseCheck<
145
- ISubject,
146
- IStore,
147
- ISelection,
148
- IThenShape,
149
- ITestShape
150
- >[] = []
151
- ) {
152
- this.name = name;
153
- this.index = index;
154
- this.givens = givens;
155
- this.checks = checks;
156
- this.fails = [];
157
- }
158
-
159
- public toObj() {
160
- return {
161
- name: this.name,
162
- givens: Object.keys(this.givens).map((k) => this.givens[k].toObj()),
163
- fails: this.fails,
164
- };
165
- }
166
-
167
- setup(s: IInput, artifactory: ITestArtifactory): Promise<ISubject> {
168
- return new Promise((res) => res(s as unknown as ISubject));
169
- }
170
-
171
- test(t: IThenShape): unknown {
172
- return t;
173
- }
174
-
175
- async run(
176
- input,
177
- testResourceConfiguration: ITTestResourceConfiguration,
178
- artifactory: (
179
- fPath: string,
180
- value: unknown
181
- ) => void,
182
- tLog: (...string) => void
183
- ): Promise<
184
- BaseSuite<IInput, ISubject, IStore, ISelection, IThenShape, ITestShape>
185
- > {
186
- this.testResourceConfiguration = testResourceConfiguration;
187
-
188
- const suiteArtifactory = (fPath: string, value: unknown) =>
189
- artifactory(`suite-${this.index}-${this.name}/${fPath}`, value)
190
- const subject = await this.setup(input, suiteArtifactory);
191
-
192
- tLog("\nSuite:", this.index, this.name);
193
- for (const k of Object.keys(this.givens)) {
194
- const giver = this.givens[k];
195
- try {
196
- this.store = await giver.give(
197
- subject,
198
- k,
199
- testResourceConfiguration,
200
- this.test,
201
- suiteArtifactory,
202
- tLog
203
- );
204
- } catch (e) {
205
- console.error(e);
206
- this.fails.push(giver);
207
- return this;
208
- }
209
- }
210
- for (const [ndx, thater] of this.checks.entries()) {
211
- await thater.check(
212
- subject,
213
- thater.name,
214
- testResourceConfiguration,
215
- this.test,
216
- suiteArtifactory,
217
- tLog
218
- );
219
- }
220
-
221
- // @TODO fix me
222
- for (const k of Object.keys(this.givens)) {
223
- const giver = this.givens[k];
224
- giver.afterAll(this.store, artifactory);
225
- }
226
- ////////////////
227
-
228
- return this;
229
- }
230
- }
231
-
232
- export abstract class BaseGiven<ISubject, IStore, ISelection, IThenShape> {
233
- name: string;
234
- features: string[];
235
- whens: BaseWhen<IStore, ISelection, IThenShape>[];
236
- thens: BaseThen<ISelection, IStore, IThenShape>[];
237
- error: Error;
238
- store: IStore;
239
- recommendedFsPath: string;
240
-
241
- constructor(
242
- name: string,
243
- features: string[],
244
- whens: BaseWhen<IStore, ISelection, IThenShape>[],
245
- thens: BaseThen<ISelection, IStore, IThenShape>[]
246
- ) {
247
- this.name = name;
248
- this.features = features;
249
- this.whens = whens;
250
- this.thens = thens;
251
- }
252
-
253
- beforeAll(store: IStore, artifactory: ITestArtifactory) {
254
- return store;
255
- }
256
-
257
- afterAll(store: IStore, artifactory: ITestArtifactory) {
258
- return store;
259
- }
260
-
261
- toObj() {
262
- return {
263
- name: this.name,
264
- whens: this.whens.map((w) => w.toObj()),
265
- thens: this.thens.map((t) => t.toObj()),
266
- error: this.error ? [this.error, this.error.stack] : null,
267
- features: this.features,
268
- };
269
- }
270
-
271
- abstract givenThat(
272
- subject: ISubject,
273
- testResourceConfiguration,
274
- artifactory: ITestArtifactory
275
- ): Promise<IStore>;
276
-
277
- async afterEach(
278
- store: IStore,
279
- key: string,
280
- artifactory: ITestArtifactory
281
- ): Promise<unknown> {
282
- return store;
283
- }
284
-
285
- async give(
286
- subject: ISubject,
287
- key: string,
288
- testResourceConfiguration,
289
- tester,
290
- artifactory: ITestArtifactory,
291
- tLog: ITLog
292
- ) {
293
- tLog(`\n Given: ${this.name}`);
294
-
295
- const givenArtifactory = (fPath: string, value: unknown) =>
296
- artifactory(`given-${key}/${fPath}`, value)
297
-
298
- try {
299
- this.store = await this.givenThat(
300
- subject,
301
- testResourceConfiguration,
302
- givenArtifactory
303
- );
304
-
305
- // tLog(`\n Given this.store`, this.store);
306
- for (const whenStep of this.whens) {
307
- await whenStep.test(this.store, testResourceConfiguration, tLog);
308
- }
309
- for (const thenStep of this.thens) {
310
- const t = await thenStep.test(
311
- this.store,
312
- testResourceConfiguration,
313
- tLog
314
- );
315
- tester(t);
316
- }
317
- } catch (e) {
318
- this.error = e;
319
- tLog(e);
320
- tLog("\u0007"); // bell
321
- // throw e;
322
- } finally {
323
- try {
324
- await this.afterEach(this.store, key, givenArtifactory);
325
- } catch (e) {
326
- console.error("afterEach failed! no error will be recorded!", e);
327
- }
328
- }
329
- return this.store;
330
- }
331
- }
332
-
333
- export abstract class BaseWhen<IStore, ISelection, IThenShape> {
334
- public name: string;
335
- actioner: (x: ISelection) => IThenShape;
336
- error: boolean;
337
-
338
- constructor(
339
- name: string,
340
- actioner: (xyz: ISelection) => IThenShape) {
341
- this.name = name;
342
- this.actioner = actioner;
343
- }
344
-
345
- abstract andWhen(
346
- store: IStore,
347
- actioner: (x: ISelection) => IThenShape,
348
- testResource
349
- );
350
-
351
- toObj() {
352
- return {
353
- name: this.name,
354
- error: this.error,
355
- };
356
- }
357
-
358
- async test(store: IStore, testResourceConfiguration, tLog: ITLog) {
359
- tLog(" When:", this.name);
360
- try {
361
- return await this.andWhen(
362
- store,
363
- this.actioner,
364
- testResourceConfiguration
365
- );
366
- } catch (e) {
367
- this.error = true;
368
- throw e;
369
- }
370
- }
371
- }
372
-
373
- export abstract class BaseThen<ISelection, IStore, IThenShape> {
374
- public name: string;
375
- thenCB: (storeState: ISelection) => IThenShape;
376
- error: boolean;
377
-
378
- constructor(name: string, thenCB: (val: ISelection) => IThenShape) {
379
- this.name = name;
380
- this.thenCB = thenCB;
381
- }
382
-
383
- toObj() {
384
- return {
385
- name: this.name,
386
- error: this.error,
387
- };
388
- }
389
-
390
- abstract butThen(store: any, testResourceConfiguration?): Promise<ISelection>;
391
-
392
- async test(
393
- store: IStore,
394
- testResourceConfiguration,
395
- tLog: ITLog
396
- ): Promise<IThenShape | undefined> {
397
- tLog(" Then:", this.name);
398
- try {
399
- return this.thenCB(await this.butThen(store, testResourceConfiguration));
400
- } catch (e) {
401
- console.log("test failed", e);
402
- this.error = true;
403
- throw e;
404
- }
405
-
406
- // try {
407
- // return await (this.thenCB(
408
- // await (async () => {
409
- // try {
410
- // return await (
411
- // (() => {
412
- // try {
413
- // return this.butThen(store, testResourceConfiguration)
414
- // } catch (e) {
415
- // this.error = true;
416
- // throw e
417
- // }
418
- // })()
419
- // );
420
- // } catch (e) {
421
- // this.error = true;
422
- // throw e
423
- // }
424
- // })()
425
- // ));
426
- // } catch (e) {
427
- // this.error = true;
428
- // throw e
429
- // }
430
- }
431
- }
432
-
433
- export abstract class BaseCheck<
434
- ISubject,
435
- IStore,
436
- ISelection,
437
- IThenShape,
438
- ITestShape extends ITTestShape
439
- > {
440
- name: string;
441
- features: string[];
442
- checkCB: (whens, thens) => any;
443
- whens: {
444
- [K in keyof ITestShape["whens"]]: (
445
- p,
446
- tc
447
- ) => BaseWhen<IStore, ISelection, IThenShape>;
448
- };
449
- thens: {
450
- [K in keyof ITestShape["thens"]]: (
451
- p,
452
- tc
453
- ) => BaseThen<ISelection, IStore, IThenShape>;
454
- };
455
-
456
- constructor(
457
- name: string,
458
- features: string[],
459
- checkCB: (whens, thens) => any,
460
- whens,
461
- thens
462
- ) {
463
- this.name = name;
464
- this.features = features;
465
- this.checkCB = checkCB;
466
- this.whens = whens;
467
- this.thens = thens;
468
- }
469
-
470
- abstract checkThat(
471
- subject: ISubject,
472
- testResourceConfiguration,
473
- artifactory: ITestArtifactory
474
- ): Promise<IStore>;
475
-
476
- async afterEach(store: IStore, key: string, cb?): Promise<unknown> {
477
- return;
478
- }
479
-
480
- async check(
481
- subject: ISubject,
482
- key: string,
483
- testResourceConfiguration,
484
- tester,
485
- artifactory: ITestArtifactory,
486
- tLog: ITLog
487
- ) {
488
- tLog(`\n Check: ${this.name}`);
489
- const store = await this.checkThat(
490
- subject,
491
- testResourceConfiguration,
492
- artifactory
493
- );
494
- await this.checkCB(
495
- Object.entries(this.whens).reduce((a, [key, when]) => {
496
- a[key] = async (payload) => {
497
- return await when(payload, testResourceConfiguration).test(
498
- store,
499
- testResourceConfiguration,
500
- tLog
501
- );
502
- };
503
- return a;
504
- }, {}),
505
- Object.entries(this.thens).reduce((a, [key, then]) => {
506
- a[key] = async (payload) => {
507
- const t = await then(payload, testResourceConfiguration).test(
508
- store,
509
- testResourceConfiguration,
510
- tLog
511
- );
512
- tester(t);
513
- };
514
- return a;
515
- }, {})
516
- );
517
-
518
- await this.afterEach(store, key);
519
- return;
520
- }
521
- }
522
-
523
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
524
-
525
- abstract class TesterantoLevelZero<
526
- IInput,
527
- ISubject,
528
- IStore,
529
- ISelection,
530
- SuiteExtensions,
531
- GivenExtensions,
532
- WhenExtensions,
533
- ThenExtensions,
534
- CheckExtensions,
535
- IThenShape
536
- > {
537
- constructorator: IStore;
538
-
539
- suitesOverrides: Record<
540
- keyof SuiteExtensions,
541
- (
542
- name: string,
543
- index: number,
544
- givens: IGivens<ISubject, IStore, ISelection, IThenShape>,
545
- checks: BaseCheck<ISubject, IStore, ISelection, IThenShape, ITTestShape>[]
546
- ) => BaseSuite<
547
- IInput,
548
- ISubject,
549
- IStore,
550
- ISelection,
551
- IThenShape,
552
- ITTestShape
553
- >
554
- >;
555
-
556
- givenOverides: Record<
557
- keyof GivenExtensions,
558
- (
559
- name: string,
560
- features: string[],
561
- whens: BaseWhen<IStore, ISelection, IThenShape>[],
562
- thens: BaseThen<ISelection, IStore, IThenShape>[],
563
- ...xtraArgs
564
- ) => BaseGiven<ISubject, IStore, ISelection, IThenShape>
565
- >;
566
-
567
- whenOverides: Record<
568
- keyof WhenExtensions,
569
- (any) => BaseWhen<IStore, ISelection, IThenShape>
570
- >;
571
-
572
- thenOverides: Record<
573
- keyof ThenExtensions,
574
- (
575
- selection: ISelection,
576
- expectation: any
577
- ) => BaseThen<ISelection, IStore, IThenShape>
578
- >;
579
-
580
- checkOverides: Record<
581
- keyof CheckExtensions,
582
- (
583
- feature: string,
584
- callback: (whens, thens) => any,
585
- ...xtraArgs
586
- ) => BaseCheck<ISubject, IStore, ISelection, IThenShape, ITTestShape>
587
- >;
588
-
589
- constructor(
590
- public readonly cc: IStore,
591
- suitesOverrides: Record<
592
- keyof SuiteExtensions,
593
- (
594
- name: string,
595
- index: number,
596
- givens: IGivens<ISubject, IStore, ISelection, IThenShape>,
597
- checks: BaseCheck<
598
- ISubject,
599
- IStore,
600
- ISelection,
601
- IThenShape,
602
- ITTestShape
603
- >[]
604
- ) => BaseSuite<
605
- IInput,
606
- ISubject,
607
- IStore,
608
- ISelection,
609
- IThenShape,
610
- ITTestShape
611
- >
612
- >,
613
-
614
- givenOverides: Record<
615
- keyof GivenExtensions,
616
- (
617
- name: string,
618
- features: string[],
619
- whens: BaseWhen<IStore, ISelection, IThenShape>[],
620
- thens: BaseThen<ISelection, IStore, IThenShape>[],
621
- ...xtraArgs
622
- ) => BaseGiven<ISubject, IStore, ISelection, IThenShape>
623
- >,
624
-
625
- whenOverides: Record<
626
- keyof WhenExtensions,
627
- (c: any) => BaseWhen<IStore, ISelection, IThenShape>
628
- >,
629
-
630
- thenOverides: Record<
631
- keyof ThenExtensions,
632
- (
633
- selection: ISelection,
634
- expectation: any
635
- ) => BaseThen<ISelection, IStore, IThenShape>
636
- >,
637
-
638
- checkOverides: Record<
639
- keyof CheckExtensions,
640
- (
641
- feature: string,
642
- callback: (whens, thens) => any,
643
- ...xtraArgs
644
- ) => BaseCheck<ISubject, IStore, ISelection, IThenShape, ITTestShape>
645
- >
646
- ) {
647
- this.constructorator = cc;
648
- this.suitesOverrides = suitesOverrides;
649
- this.givenOverides = givenOverides;
650
- this.whenOverides = whenOverides;
651
- this.thenOverides = thenOverides;
652
- this.checkOverides = checkOverides;
653
- }
654
-
655
- Suites() {
656
- return this.suitesOverrides;
657
- }
658
-
659
- Given(): Record<
660
- keyof GivenExtensions,
661
- (
662
- name: string,
663
- features: string[],
664
- whens: BaseWhen<IStore, ISelection, IThenShape>[],
665
- thens: BaseThen<ISelection, IStore, IThenShape>[],
666
- ...xtraArgs
667
- ) => BaseGiven<ISubject, IStore, ISelection, IThenShape>
668
- > {
669
- return this.givenOverides;
670
- }
671
-
672
- When(): Record<
673
- keyof WhenExtensions,
674
- (arg0: IStore, ...arg1: any) => BaseWhen<IStore, ISelection, IThenShape>
675
- > {
676
- return this.whenOverides;
677
- }
678
-
679
- Then(): Record<
680
- keyof ThenExtensions,
681
- (
682
- selection: ISelection,
683
- expectation: any
684
- ) => BaseThen<ISelection, IStore, IThenShape>
685
- > {
686
- return this.thenOverides;
687
- }
688
-
689
- Check(): Record<
690
- keyof CheckExtensions,
691
- (
692
- feature: string,
693
- callback: (whens, thens) => any,
694
- whens,
695
- thens
696
- ) => BaseCheck<ISubject, IStore, ISelection, IThenShape, ITTestShape>
697
- > {
698
- return this.checkOverides;
699
- }
700
- }
701
-
702
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
703
-
704
- abstract class TesterantoLevelOne<
705
- ITestShape extends ITTestShape,
706
- IInitialState,
707
- ISelection,
708
- IStore,
709
- ISubject,
710
- IWhenShape,
711
- IThenShape,
712
- IInput
713
- > {
714
-
715
- artifacts: Promise<unknown>[] = [];
716
- testJobs: ITestJob[];
717
-
718
- constructor(
719
- testImplementation: ITestImplementation<
720
- IInitialState,
721
- ISelection,
722
- IWhenShape,
723
- IThenShape,
724
- ITestShape
725
- >,
726
-
727
- testSpecification: (
728
- Suite: {
729
- [K in keyof ITestShape["suites"]]: (
730
- feature: string,
731
- givens: IGivens<ISubject, IStore, ISelection, IThenShape>,
732
- checks: BaseCheck<
733
- ISubject,
734
- IStore,
735
- ISelection,
736
- IThenShape,
737
- ITestShape
738
- >[]
739
- ) => BaseSuite<
740
- IInput,
741
- ISubject,
742
- IStore,
743
- ISelection,
744
- IThenShape,
745
- ITestShape
746
- >;
747
- },
748
- Given: {
749
- [K in keyof ITestShape["givens"]]: (
750
- features: string[],
751
- whens: BaseWhen<IStore, ISelection, IThenShape>[],
752
- thens: BaseThen<ISelection, IStore, IThenShape>[],
753
- ...a: ITestShape["givens"][K]
754
- ) => BaseGiven<ISubject, IStore, ISelection, IThenShape>;
755
- },
756
- When: {
757
- [K in keyof ITestShape["whens"]]: (
758
- ...a: ITestShape["whens"][K]
759
- ) => BaseWhen<IStore, ISelection, IThenShape>;
760
- },
761
- Then: {
762
- [K in keyof ITestShape["thens"]]: (
763
- ...a: ITestShape["thens"][K]
764
- ) => BaseThen<ISelection, IStore, IThenShape>;
765
- },
766
- Check: ITestCheckCallback<ITestShape>,
767
- logWriter: ILogWriter
768
- ) => BaseSuite<
769
- IInput,
770
- ISubject,
771
- IStore,
772
- ISelection,
773
- IThenShape,
774
- ITestShape
775
- >[],
776
-
777
- input: IInput,
778
-
779
- suiteKlasser: (
780
- name: string,
781
- index: number,
782
- givens: IGivens<ISubject, IStore, ISelection, IThenShape>,
783
- checks: BaseCheck<ISubject, IStore, ISelection, IThenShape, ITestShape>[]
784
- ) => BaseSuite<
785
- IInput,
786
- ISubject,
787
- IStore,
788
- ISelection,
789
- IThenShape,
790
- ITestShape
791
- >,
792
- givenKlasser: (
793
- n,
794
- f,
795
- w,
796
- t,
797
- z?
798
- ) => BaseGiven<ISubject, IStore, ISelection, IThenShape>,
799
- whenKlasser: (s, o) => BaseWhen<IStore, ISelection, IThenShape>,
800
- thenKlasser: (s, o) => BaseThen<IStore, ISelection, IThenShape>,
801
- checkKlasser: (
802
- n,
803
- f,
804
- cb,
805
- w,
806
- t
807
- ) => BaseCheck<ISubject, IStore, ISelection, IThenShape, ITestShape>,
808
-
809
- testResourceRequirement,
810
- logWriter: ILogWriter
811
- ) {
812
-
813
- console.log("core TesterantoLevelOne logWriter", logWriter);
814
-
815
- const classySuites = Object.entries(testImplementation.Suites).reduce(
816
- (a, [key], index) => {
817
- a[key] = (somestring, givens, checks) => {
818
- return new suiteKlasser.prototype.constructor(
819
- somestring,
820
- index,
821
- givens,
822
- checks
823
- );
824
- };
825
- return a;
826
- },
827
- {}
828
- );
829
-
830
- const classyGivens = Object.keys(testImplementation.Givens)
831
- .reduce(
832
- (a, key: string) => {
833
- a[key] = (
834
- features,
835
- whens,
836
- thens,
837
- ...xtrasW
838
- ) => {
839
- return new givenKlasser.prototype.constructor(
840
- key,
841
- features,
842
- whens,
843
- thens,
844
- testImplementation.Givens[key](...xtrasW)
845
- );
846
- };
847
- return a;
848
- },
849
- {}
850
- );
851
-
852
- const classyWhens = Object.entries(testImplementation.Whens).reduce(
853
- (a, [key, whEn]) => {
854
- a[key] = (payload?: any) => {
855
- return new whenKlasser.prototype.constructor(
856
- `${whEn.name}: ${payload && payload.toString()}`,
857
- whEn(payload)
858
- );
859
- };
860
- return a;
861
- },
862
- {}
863
- );
864
-
865
- const classyThens = Object.entries(testImplementation.Thens).reduce(
866
- (a, [key, thEn]) => {
867
- a[key] = (expected: any, x) => {
868
- return new thenKlasser.prototype.constructor(
869
- `${thEn.name}: ${expected && expected.toString()}`,
870
- thEn(expected)
871
- );
872
- };
873
- return a;
874
- },
875
- {}
876
- );
877
-
878
- const classyChecks = Object.entries(testImplementation.Checks).reduce(
879
- (a, [key, z]) => {
880
- a[key] = (somestring, features, callback) => {
881
- return new checkKlasser.prototype.constructor(
882
- somestring,
883
- features,
884
- callback,
885
- classyWhens,
886
- classyThens
887
- );
888
- };
889
- return a;
890
- },
891
- {}
892
- );
893
-
894
- const classyTesteranto = new (class <
895
- IInput,
896
- ISubject,
897
- IStore,
898
- ISelection,
899
- SuiteExtensions,
900
- GivenExtensions,
901
- WhenExtensions,
902
- ThenExtensions,
903
- ICheckExtensions,
904
- IThenShape
905
- > extends TesterantoLevelZero<
906
- IInput,
907
- ISubject,
908
- IStore,
909
- ISelection,
910
- SuiteExtensions,
911
- GivenExtensions,
912
- WhenExtensions,
913
- ThenExtensions,
914
- ICheckExtensions,
915
- IThenShape
916
- > { })(
917
- input,
918
- classySuites,
919
- classyGivens,
920
- classyWhens,
921
- classyThens,
922
- classyChecks
923
- );
924
-
925
- const suites = testSpecification(
926
- /* @ts-ignore:next-line */
927
- classyTesteranto.Suites(),
928
- classyTesteranto.Given(),
929
- classyTesteranto.When(),
930
- classyTesteranto.Then(),
931
- classyTesteranto.Check(),
932
- logWriter
933
- );
934
-
935
- const suiteRunner =
936
- (suite: BaseSuite<
937
- IInput,
938
- ISubject,
939
- IStore,
940
- ISelection,
941
- IThenShape,
942
- ITestShape
943
- >) =>
944
- async (
945
- testResourceConfiguration: ITTestResourceConfiguration,
946
- tLog: ITLog
947
- ): Promise<BaseSuite<
948
- IInput, ISubject, IStore, ISelection, IThenShape, ITestShape
949
- >> => {
950
- return await suite.run(
951
- input,
952
- testResourceConfiguration,
953
- (
954
- fPath: string,
955
- value: unknown
956
- ) =>
957
- logWriter.testArtiFactoryfileWriter(tLog, (p: Promise<void>) => {
958
- artifacts.push(p);
959
- })(
960
- testResourceConfiguration.fs + "/" + fPath,
961
- value
962
- ),
963
- tLog
964
- );
965
- };
966
-
967
- const artifacts = this.artifacts;
968
-
969
- this.testJobs = suites.map((suite) => {
970
- const runner = suiteRunner(suite);
971
-
972
- return {
973
- test: suite,
974
- testResourceRequirement,
975
-
976
- toObj: () => {
977
- return suite.toObj();
978
- },
979
-
980
- runner,
981
-
982
- receiveTestResourceConfig: async function (
983
- testResourceConfiguration = defaultTestResource
984
- ) {
985
- console.log(
986
- `testResourceConfiguration ${JSON.stringify(
987
- testResourceConfiguration,
988
- null,
989
- 2
990
- )}`
991
- );
992
-
993
- await logWriter.mkdirSync(testResourceConfiguration.fs);
994
-
995
- const logFilePath = (
996
- `${testResourceConfiguration.fs}/log.txt`
997
- );
998
-
999
- const access = await logWriter.createWriteStream(logFilePath);
1000
-
1001
- const tLog = (...l: string[]) => {
1002
- console.log(...l);
1003
- access.write(`${l.toString()}\n`);
1004
- };
1005
- const suiteDone: BaseSuite<
1006
- IInput,
1007
- ISubject,
1008
- IStore,
1009
- ISelection,
1010
- IThenShape,
1011
- ITestShape
1012
- > = await runner(testResourceConfiguration, tLog);
1013
- const resultsFilePath = (
1014
- `${testResourceConfiguration.fs}/results.json`
1015
- );
1016
-
1017
- logWriter.writeFileSync(
1018
- resultsFilePath,
1019
- JSON.stringify(suiteDone.toObj(), null, 2)
1020
- );
1021
-
1022
- const logPromise = new Promise((res, rej) => {
1023
- access.on("finish", () => { res(true); });
1024
- })
1025
- access.end();
1026
-
1027
- const numberOfFailures = Object.keys(suiteDone.givens).filter(
1028
- (k) => {
1029
- // console.log(`suiteDone.givens[k].error`, suiteDone.givens[k].error);
1030
- return suiteDone.givens[k].error
1031
- }
1032
- ).length;
1033
- console.log(`exiting gracefully with ${numberOfFailures} failures.`);
1034
- return {
1035
- failed: numberOfFailures,
1036
- artifacts,
1037
- logPromise
1038
- };
1039
- },
1040
- };
1041
- });
1042
- }
1043
-
1044
- }
1045
-
1046
- ////////////////////////////////////////////////////////////////////////////////////////////////
1047
-
1048
- export default class TesterantoLevelTwo<TestShape extends ITTestShape,
1049
- IState,
1050
- ISelection,
1051
- IStore,
1052
- ISubject,
1053
- WhenShape,
1054
- ThenShape,
1055
- IInput
1056
- > extends TesterantoLevelOne<
1057
- TestShape,
1058
- IState,
1059
- ISelection,
1060
- IStore,
1061
- ISubject,
1062
- WhenShape,
1063
- ThenShape,
1064
- IInput
1065
- > {
1066
- constructor(
1067
- input: IInput,
1068
- testSpecification: ITestSpecification<
1069
- TestShape,
1070
- ISubject,
1071
- IStore,
1072
- ISelection,
1073
- ThenShape
1074
- >,
1075
- testImplementation,
1076
- testInterface: {
1077
- actionHandler?: (b: (...any) => any) => any;
1078
- andWhen: (
1079
- store: IStore,
1080
- actioner,
1081
- testResource: ITTestResourceConfiguration
1082
- ) => Promise<ISelection>;
1083
- butThen?: (
1084
- store: IStore,
1085
- callback,
1086
- testResource: ITTestResourceConfiguration
1087
- ) => Promise<ISelection>;
1088
- assertioner?: (t: ThenShape) => any;
1089
-
1090
- afterAll?: (store: IStore, artificer: ITestArtificer) => any;
1091
- afterEach?: (
1092
- store: IStore,
1093
- key: string,
1094
- artificer: ITestArtificer
1095
- ) => Promise<unknown>;
1096
-
1097
- beforeAll?: (
1098
- input: IInput,
1099
- artificer: ITestArtificer,
1100
- testResource: ITTestResourceConfiguration
1101
- ) => Promise<ISubject>;
1102
-
1103
- beforeEach?: (
1104
- subject: ISubject,
1105
- initialValues,
1106
- testResource: ITTestResourceConfiguration,
1107
- artificer: ITestArtificer
1108
- ) => Promise<IStore>;
1109
- },
1110
- testResourceRequirement: ITTestResourceRequest = defaultTestResourceRequirement,
1111
- assertioner: (t: ThenShape) => any,
1112
- beforeEach: (
1113
- subject: ISubject,
1114
- initialValues,
1115
- testResource: ITTestResourceConfiguration,
1116
- artificer: ITestArtificer
1117
- ) => Promise<IStore>,
1118
- afterEach: (
1119
- store: IStore,
1120
- key: string,
1121
- artificer: ITestArtificer
1122
- ) => Promise<unknown>,
1123
- afterAll: (store: IStore, artificer: ITestArtificer) => any,
1124
- butThen: (
1125
- s: IStore,
1126
- bt: (storeState: ISelection) => ThenShape,
1127
- testResource: ITTestResourceConfiguration,
1128
- ) => any,
1129
- andWhen: (
1130
- store: IStore,
1131
- actioner,
1132
- testResource: ITTestResourceConfiguration
1133
- ) => Promise<ISelection>,
1134
- actionHandler: (b: (...any) => any) => any,
1135
- logWriter: ILogWriter
1136
- ) {
1137
- super(
1138
- testImplementation,
1139
- testSpecification,
1140
- input,
1141
-
1142
- class extends BaseSuite<
1143
- IInput,
1144
- ISubject,
1145
- IStore,
1146
- ISelection,
1147
- ThenShape,
1148
- TestShape
1149
- > {
1150
- async setup(s: IInput, artifactory): Promise<ISubject> {
1151
- return (testInterface.beforeAll || (async (
1152
- input: IInput,
1153
- artificer: ITestArtificer,
1154
- ) => input as any))(
1155
- s,
1156
- artifactory,
1157
- this.testResourceConfiguration
1158
- );
1159
- }
1160
- test(t: ThenShape): unknown {
1161
- return assertioner(t);
1162
- }
1163
- } as any,
1164
-
1165
- class Given extends BaseGiven<ISubject, IStore, ISelection, ThenShape> {
1166
- initialValues: any;
1167
- constructor(
1168
- name: string,
1169
- features: string[],
1170
- whens: BaseWhen<IStore, ISelection, ThenShape>[],
1171
- thens: BaseThen<ISelection, IStore, ThenShape>[],
1172
- initialValues: any
1173
- ) {
1174
- super(
1175
- name,
1176
- features,
1177
- whens,
1178
- thens
1179
- );
1180
- this.initialValues = initialValues;
1181
- }
1182
- async givenThat(subject, testResource, artifactory) {
1183
- return beforeEach(
1184
- subject,
1185
- this.initialValues,
1186
- testResource,
1187
- (fPath: string, value: unknown) =>
1188
- // TODO does not work?
1189
- artifactory(`beforeEach/${fPath}`, value)
1190
- );
1191
- }
1192
- afterEach(
1193
- store: IStore,
1194
- key: string,
1195
- artifactory
1196
- ): Promise<unknown> {
1197
- return new Promise((res) =>
1198
- res(afterEach(store, key, (fPath: string, value: unknown) =>
1199
- artifactory(`after/${fPath}`, value)))
1200
- );
1201
- }
1202
- afterAll(store, artifactory) {
1203
- return afterAll(store, (fPath: string, value: unknown) =>
1204
- // TODO does not work?
1205
- artifactory(`afterAll4-${this.name}/${fPath}`, value));
1206
- }
1207
- } as any,
1208
-
1209
- class When extends BaseWhen<IStore, ISelection, WhenShape> {
1210
- payload?: any;
1211
-
1212
- constructor(
1213
- name: string,
1214
- actioner: (...any) => any, payload?: any) {
1215
- super(
1216
- name,
1217
- (store) => {
1218
- return actionHandler(actioner);
1219
- });
1220
- this.payload = payload;
1221
- }
1222
-
1223
- async andWhen(store, actioner, testResource) {
1224
- return await andWhen(store, actioner, testResource);
1225
- }
1226
- } as any,
1227
-
1228
- class Then extends BaseThen<ISelection, IStore, ThenShape> {
1229
- constructor(name: string, callback: (val: ISelection) => ThenShape) {
1230
- super(name, callback);
1231
- }
1232
-
1233
- async butThen(
1234
- store: any,
1235
- testResourceConfiguration?: any
1236
- ): Promise<ISelection> {
1237
- return await butThen(store, this.thenCB, testResourceConfiguration);
1238
- }
1239
- } as any,
1240
-
1241
- class Check extends BaseCheck<
1242
- ISubject,
1243
- IStore,
1244
- ISelection,
1245
- ThenShape,
1246
- TestShape
1247
- > {
1248
- initialValues: any;
1249
-
1250
- constructor(
1251
- name: string,
1252
- features: string[],
1253
- checkCallback: (a, b) => any,
1254
- whens,
1255
- thens,
1256
- initialValues: any
1257
- ) {
1258
- super(name, features, checkCallback, whens, thens);
1259
- this.initialValues = initialValues;
1260
- }
1261
-
1262
- async checkThat(subject, testResourceConfiguration, artifactory) {
1263
- return beforeEach(
1264
- subject,
1265
- this.initialValues,
1266
- testResourceConfiguration,
1267
- (fPath: string, value: unknown) => artifactory(`before/${fPath}`, value)
1268
- );
1269
- }
1270
-
1271
- afterEach(
1272
- store: IStore,
1273
- key: string,
1274
- artifactory
1275
- ): Promise<unknown> {
1276
- return new Promise((res) =>
1277
- res(afterEach(store, key, (fPath: string, value: unknown) =>
1278
- // TODO does not work?
1279
- artifactory(`afterEach2-${this.name}/${fPath}`, value)))
1280
- );
1281
- }
1282
- } as any,
1283
-
1284
- testResourceRequirement,
1285
- logWriter
1286
- );
1287
- }
1288
- }
1289
-
1290
- ////////////////////////////////////////////////////////////////////////////////////////////////
1291
-
1292
- export type ITestSpecification<
1293
- ITestShape extends ITTestShape,
1294
- ISubject,
1295
- IStore,
1296
- ISelection,
1297
- IThenShape
1298
- > = (
1299
- Suite: {
1300
- [K in keyof ITestShape["suites"]]: (
1301
- name: string,
1302
- givens: IGivens<
1303
- ISubject,
1304
- IStore,
1305
- ISelection,
1306
- IThenShape
1307
- >,
1308
- checks: BaseCheck<
1309
- ISubject,
1310
- IStore,
1311
- ISelection,
1312
- IThenShape,
1313
- ITestShape
1314
- >[]
1315
- ) => BaseSuite<
1316
- unknown,
1317
- ISubject,
1318
- IStore,
1319
- ISelection,
1320
- IThenShape,
1321
- ITestShape
1322
- >;
1323
- },
1324
- Given: {
1325
- [K in keyof ITestShape["givens"]]: (
1326
- features: string[],
1327
- whens: BaseWhen<
1328
- IStore,
1329
- ISelection,
1330
- IThenShape
1331
- >[],
1332
- thens: BaseThen<
1333
- ISelection,
1334
- IStore,
1335
- IThenShape
1336
- >[],
1337
- ...xtrasB: ITestShape["givens"][K]
1338
- ) => BaseGiven<
1339
- ISubject,
1340
- IStore,
1341
- ISelection,
1342
- IThenShape
1343
- >;
1344
- },
1345
- When: {
1346
- [K in keyof ITestShape["whens"]]: (
1347
- ...xtrasC: ITestShape["whens"][K]
1348
- ) => BaseWhen<
1349
- IStore,
1350
- ISelection,
1351
- IThenShape
1352
- >;
1353
- },
1354
- Then: {
1355
- [K in keyof ITestShape["thens"]]: (
1356
- ...xtrasD: ITestShape["thens"][K]
1357
- ) => BaseThen<
1358
- ISelection,
1359
- IStore,
1360
- IThenShape>;
1361
- },
1362
- Check: ITestCheckCallback<ITestShape>
1363
- ) => any[];
1364
-
1365
- ////////////////////////////////////////////////////////////////////////////////////////////////
1366
-
1367
- export type ITestImplementation<
1368
- IState,
1369
- ISelection,
1370
- IWhenShape,
1371
- IThenShape,
1372
- ITestShape extends ITTestShape
1373
- > = {
1374
- Suites: {
1375
- [K in keyof ITestShape["suites"]]: string;
1376
- };
1377
- Givens: {
1378
- [K in keyof ITestShape["givens"]]: (
1379
- ...Ig: ITestShape["givens"][K]
1380
- ) => IState;
1381
- };
1382
- Whens: {
1383
- [K in keyof ITestShape["whens"]]: (
1384
- ...Iw: ITestShape["whens"][K]
1385
- ) =>
1386
- (zel: ISelection) =>
1387
- IWhenShape;
1388
- };
1389
- Thens: {
1390
- [K in keyof ITestShape["thens"]]: (
1391
- ...It: ITestShape["thens"][K]
1392
- ) => (ssel: ISelection) => IThenShape;
1393
- };
1394
- Checks: {
1395
- [K in keyof ITestShape["checks"]]: (
1396
- ...Ic: ITestShape["checks"][K]
1397
- ) => IState;
1398
- };
1399
- };