testeranto 0.49.10 → 0.70.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 (250) hide show
  1. package/.nvmrc +1 -0
  2. package/README.md +92 -9
  3. package/dist/cjs-shim.js +12 -0
  4. package/dist/common/Features.js +2 -3
  5. package/dist/common/Node.js +37 -62
  6. package/dist/common/NodeWriter.js +7 -9
  7. package/dist/common/Project.js +130 -627
  8. package/dist/common/SubPackages/puppeteer.js +19 -0
  9. package/dist/common/{subPackages → SubPackages}/react/component/node.js +4 -4
  10. package/dist/common/{subPackages → SubPackages}/react/component/web.js +4 -4
  11. package/dist/common/SubPackages/react/jsx/index.js +13 -0
  12. package/dist/common/SubPackages/react/jsx/node.js +10 -0
  13. package/dist/common/SubPackages/react/jsx/web.js +10 -0
  14. package/dist/common/{subPackages → SubPackages}/react-dom/component/node.js +6 -6
  15. package/dist/common/{subPackages → SubPackages}/react-dom/component/web.js +11 -12
  16. package/dist/common/SubPackages/react-dom/jsx/node.js +39 -0
  17. package/dist/common/{subPackages → SubPackages}/react-dom/jsx/web.js +19 -20
  18. package/dist/common/{subPackages → SubPackages}/react-test-renderer/MemoExoticComponent/node.js +3 -3
  19. package/dist/common/{subPackages → SubPackages}/react-test-renderer/component/index.js +25 -15
  20. package/dist/common/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/component}/node.js +3 -5
  21. package/dist/common/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/component}/web.js +3 -5
  22. package/dist/common/{subPackages → SubPackages}/react-test-renderer/fc/node.js +4 -4
  23. package/dist/common/{subPackages → SubPackages}/react-test-renderer/fc/web.js +4 -4
  24. package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx/index.js +8 -3
  25. package/dist/common/{subPackages/react-test-renderer/jsx-promised → SubPackages/react-test-renderer/jsx}/node.js +4 -4
  26. package/dist/common/{subPackages/react → SubPackages/react-test-renderer}/jsx/web.js +4 -4
  27. package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.js +3 -3
  28. package/dist/common/{subPackages/react/jsx → SubPackages/react-test-renderer/jsx-promised}/node.js +2 -2
  29. package/dist/common/Types.js +2 -0
  30. package/dist/common/Web.js +49 -113
  31. package/dist/common/electron.js +256 -42
  32. package/dist/common/esbuildConfigs/features.js +14 -0
  33. package/dist/common/esbuildConfigs/index.js +20 -0
  34. package/dist/common/esbuildConfigs/node.js +37 -0
  35. package/dist/common/esbuildConfigs/report.js +13 -0
  36. package/dist/common/esbuildConfigs/tests.js +13 -0
  37. package/dist/common/esbuildConfigs/web.js +53 -0
  38. package/dist/common/lib/abstractBase.js +200 -0
  39. package/dist/common/lib/basebuilder.js +86 -0
  40. package/dist/common/lib/classBuilder.js +40 -0
  41. package/dist/common/lib/core.js +81 -0
  42. package/dist/common/lib/index.js +21 -0
  43. package/dist/common/lib/types.js +2 -0
  44. package/dist/common/preload.js +15 -24
  45. package/dist/common/puppeteerConfiger.js +24 -0
  46. package/dist/common/report.html.js +31 -0
  47. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  48. package/dist/common/web.html.js +22 -0
  49. package/dist/module/Features.js +2 -3
  50. package/dist/module/Node.js +37 -62
  51. package/dist/module/NodeWriter.js +7 -9
  52. package/dist/module/Project.js +131 -605
  53. package/dist/module/SubPackages/puppeteer.js +14 -0
  54. package/dist/module/{subPackages → SubPackages}/react/component/node.js +3 -3
  55. package/dist/module/{subPackages → SubPackages}/react/component/web.js +3 -3
  56. package/dist/module/SubPackages/react/jsx/index.js +10 -0
  57. package/dist/module/SubPackages/react/jsx/node.js +5 -0
  58. package/dist/module/SubPackages/react/jsx/web.js +5 -0
  59. package/dist/module/{subPackages → SubPackages}/react-dom/component/node.js +7 -7
  60. package/dist/module/{subPackages → SubPackages}/react-dom/component/web.js +10 -11
  61. package/dist/module/SubPackages/react-dom/jsx/node.js +31 -0
  62. package/dist/module/{subPackages → SubPackages}/react-dom/jsx/web.js +20 -21
  63. package/dist/module/{subPackages → SubPackages}/react-test-renderer/MemoExoticComponent/node.js +3 -3
  64. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/index.js +22 -15
  65. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/node.js +2 -2
  66. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/web.js +2 -2
  67. package/dist/module/{subPackages → SubPackages}/react-test-renderer/fc/node.js +3 -3
  68. package/dist/module/{subPackages → SubPackages}/react-test-renderer/fc/web.js +3 -3
  69. package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx/index.js +8 -3
  70. package/dist/module/SubPackages/react-test-renderer/jsx/node.js +5 -0
  71. package/dist/module/SubPackages/react-test-renderer/jsx/web.js +5 -0
  72. package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.js +3 -3
  73. package/dist/module/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/jsx-promised}/node.js +1 -1
  74. package/dist/module/Types.js +2 -0
  75. package/dist/module/Web.js +49 -113
  76. package/dist/module/electron.js +257 -43
  77. package/dist/module/esbuildConfigs/features.js +12 -0
  78. package/dist/module/esbuildConfigs/index.js +18 -0
  79. package/dist/module/esbuildConfigs/node.js +32 -0
  80. package/dist/module/esbuildConfigs/report.js +11 -0
  81. package/dist/module/esbuildConfigs/tests.js +11 -0
  82. package/dist/module/esbuildConfigs/web.js +48 -0
  83. package/dist/module/lib/abstractBase.js +192 -0
  84. package/dist/module/lib/basebuilder.js +82 -0
  85. package/dist/module/lib/classBuilder.js +36 -0
  86. package/dist/module/lib/core.js +78 -0
  87. package/dist/module/lib/index.js +17 -0
  88. package/dist/module/lib/types.js +1 -0
  89. package/dist/module/preload.js +12 -24
  90. package/dist/module/puppeteerConfiger.js +19 -0
  91. package/dist/module/report.html.js +29 -0
  92. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  93. package/dist/module/web.html.js +20 -0
  94. package/dist/prebuild/Report.css +10326 -0
  95. package/dist/prebuild/Report.js +37456 -0
  96. package/dist/types/Features.d.ts +5 -5
  97. package/dist/types/Node.d.ts +5 -11
  98. package/dist/types/NodeWriter.d.ts +1 -1
  99. package/dist/types/Project.d.ts +2 -28
  100. package/dist/types/SubPackages/puppeteer.d.ts +6 -0
  101. package/dist/types/SubPackages/react/component/node.d.ts +7 -0
  102. package/dist/types/SubPackages/react/component/web.d.ts +7 -0
  103. package/dist/types/SubPackages/react/jsx/index.d.ts +15 -0
  104. package/dist/types/SubPackages/react/jsx/node.d.ts +4 -0
  105. package/dist/types/SubPackages/react/jsx/web.d.ts +4 -0
  106. package/dist/types/SubPackages/react-dom/component/node.d.ts +12 -0
  107. package/dist/types/SubPackages/react-dom/component/web.d.ts +5 -0
  108. package/dist/types/SubPackages/react-dom/jsx/node.d.ts +6 -0
  109. package/dist/types/SubPackages/react-dom/jsx/web.d.ts +5 -0
  110. package/dist/types/SubPackages/react-test-renderer/MemoExoticComponent/node.d.ts +5 -0
  111. package/dist/types/{subPackages → SubPackages}/react-test-renderer/component/index.d.ts +6 -6
  112. package/dist/types/{subPackages → SubPackages}/react-test-renderer/component/node.d.ts +4 -4
  113. package/dist/types/SubPackages/react-test-renderer/component/web.d.ts +4 -0
  114. package/dist/types/SubPackages/react-test-renderer/fc/node.d.ts +8 -0
  115. package/dist/types/SubPackages/react-test-renderer/fc/web.d.ts +8 -0
  116. package/dist/types/{subPackages → SubPackages}/react-test-renderer/jsx/index.d.ts +5 -4
  117. package/dist/types/SubPackages/react-test-renderer/jsx/node.d.ts +9 -0
  118. package/dist/types/SubPackages/react-test-renderer/jsx/web.d.ts +9 -0
  119. package/dist/types/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.d.ts +4 -4
  120. package/dist/types/SubPackages/react-test-renderer/jsx-promised/node.d.ts +5 -0
  121. package/dist/types/SubPackages/react-test-renderer/jsx-promised/web.d.ts +5 -0
  122. package/dist/types/Types.d.ts +49 -17
  123. package/dist/types/Web.d.ts +5 -11
  124. package/dist/types/esbuildConfigs/features.d.ts +4 -0
  125. package/dist/types/esbuildConfigs/index.d.ts +4 -0
  126. package/dist/types/esbuildConfigs/node.d.ts +4 -0
  127. package/dist/types/esbuildConfigs/report.d.ts +4 -0
  128. package/dist/types/esbuildConfigs/tests.d.ts +4 -0
  129. package/dist/types/esbuildConfigs/web.d.ts +4 -0
  130. package/dist/types/lib/abstractBase.d.ts +103 -0
  131. package/dist/types/lib/basebuilder.d.ts +25 -0
  132. package/dist/types/lib/classBuilder.d.ts +7 -0
  133. package/dist/types/lib/core.d.ts +8 -0
  134. package/dist/types/lib/index.d.ts +58 -0
  135. package/dist/types/lib/types.d.ts +70 -0
  136. package/dist/types/puppeteerConfiger.d.ts +4 -0
  137. package/dist/types/report.html.d.ts +2 -0
  138. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  139. package/dist/types/web.html.d.ts +2 -0
  140. package/electronBuild.ts +32 -0
  141. package/index.html +30 -0
  142. package/package.json +123 -87
  143. package/src/Features.ts +2 -4
  144. package/src/Node.ts +79 -155
  145. package/src/NodeWriter.ts +22 -22
  146. package/src/Project.ts +185 -783
  147. package/src/Report.tsx +30 -15
  148. package/src/SubPackages/puppeteer.ts +51 -0
  149. package/src/SubPackages/react/component/node.ts +43 -0
  150. package/src/SubPackages/react/component/web.ts +43 -0
  151. package/src/SubPackages/react/jsx/index.ts +32 -0
  152. package/src/SubPackages/react/jsx/node.ts +29 -0
  153. package/src/SubPackages/react/jsx/web.ts +30 -0
  154. package/src/{subPackages → SubPackages}/react-dom/component/node.ts +24 -44
  155. package/src/SubPackages/react-dom/component/web.ts +104 -0
  156. package/src/{subPackages → SubPackages}/react-dom/jsx/index.ts +0 -1
  157. package/src/SubPackages/react-dom/jsx/node.ts +68 -0
  158. package/src/SubPackages/react-dom/jsx/web.ts +102 -0
  159. package/src/SubPackages/react-test-renderer/MemoExoticComponent/node.ts +38 -0
  160. package/src/{subPackages → SubPackages}/react-test-renderer/component/index.ts +37 -49
  161. package/src/SubPackages/react-test-renderer/component/node.ts +16 -0
  162. package/src/SubPackages/react-test-renderer/component/web.ts +16 -0
  163. package/src/SubPackages/react-test-renderer/fc/node.ts +49 -0
  164. package/src/SubPackages/react-test-renderer/fc/web.ts +48 -0
  165. package/src/SubPackages/react-test-renderer/jsx/index.ts +49 -0
  166. package/src/SubPackages/react-test-renderer/jsx/node.ts +20 -0
  167. package/src/SubPackages/react-test-renderer/jsx/web.ts +20 -0
  168. package/src/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.ts +15 -26
  169. package/src/SubPackages/react-test-renderer/jsx-promised/node.ts +19 -0
  170. package/src/SubPackages/react-test-renderer/jsx-promised/web.ts +22 -0
  171. package/src/Types.ts +114 -17
  172. package/src/Web.ts +100 -225
  173. package/src/cjs-shim.js +12 -0
  174. package/src/electron.ts +303 -45
  175. package/src/esbuildConfigs/features.ts +17 -0
  176. package/src/esbuildConfigs/index.ts +22 -0
  177. package/src/esbuildConfigs/node.ts +60 -0
  178. package/src/esbuildConfigs/report.ts +15 -0
  179. package/src/esbuildConfigs/tests.ts +14 -0
  180. package/src/esbuildConfigs/web.ts +73 -0
  181. package/src/lib/abstractBase.ts +412 -0
  182. package/src/lib/basebuilder.ts +228 -0
  183. package/src/lib/classBuilder.ts +118 -0
  184. package/src/lib/core.ts +214 -0
  185. package/src/lib/index.ts +117 -0
  186. package/src/lib/types.ts +206 -0
  187. package/src/preload.ts +13 -27
  188. package/src/puppeteerConfiger.ts +26 -0
  189. package/src/report.html.ts +29 -0
  190. package/src/web.html.ts +20 -0
  191. package/tests/Rectangle.test.ts +189 -0
  192. package/tsconfig.json +19 -6
  193. package/tsconfig.module.json +15 -4
  194. package/tsconfig.types.json +14 -4
  195. package/yarn-error.log +3144 -0
  196. package/dist/common/core.js +0 -397
  197. package/dist/common/subPackages/react/jsx/index.js +0 -26
  198. package/dist/common/subPackages/react-dom/jsx/node.js +0 -95
  199. package/dist/common/subPackages/react-test-renderer/component/node.js +0 -8
  200. package/dist/common/subPackages/react-test-renderer/component/web.js +0 -8
  201. package/dist/module/Report.js +0 -186
  202. package/dist/module/core.js +0 -388
  203. package/dist/module/subPackages/react/jsx/index.js +0 -22
  204. package/dist/module/subPackages/react/jsx/node.js +0 -5
  205. package/dist/module/subPackages/react/jsx/web.js +0 -5
  206. package/dist/module/subPackages/react-dom/jsx/node.js +0 -87
  207. package/dist/module/subPackages/react-test-renderer/jsx/web.js +0 -5
  208. package/dist/module/subPackages/react-test-renderer/jsx-promised/node.js +0 -5
  209. package/dist/types/core.d.ts +0 -220
  210. package/dist/types/subPackages/react/component/node.d.ts +0 -12
  211. package/dist/types/subPackages/react/component/web.d.ts +0 -12
  212. package/dist/types/subPackages/react/jsx/index.d.ts +0 -15
  213. package/dist/types/subPackages/react/jsx/node.d.ts +0 -4
  214. package/dist/types/subPackages/react/jsx/web.d.ts +0 -4
  215. package/dist/types/subPackages/react-dom/component/node.d.ts +0 -14
  216. package/dist/types/subPackages/react-dom/component/web.d.ts +0 -19
  217. package/dist/types/subPackages/react-dom/jsx/node.d.ts +0 -8
  218. package/dist/types/subPackages/react-dom/jsx/web.d.ts +0 -5
  219. package/dist/types/subPackages/react-test-renderer/MemoExoticComponent/node.d.ts +0 -8
  220. package/dist/types/subPackages/react-test-renderer/component/web.d.ts +0 -9
  221. package/dist/types/subPackages/react-test-renderer/fc/node.d.ts +0 -9
  222. package/dist/types/subPackages/react-test-renderer/fc/web.d.ts +0 -9
  223. package/dist/types/subPackages/react-test-renderer/jsx/node.d.ts +0 -4
  224. package/dist/types/subPackages/react-test-renderer/jsx/web.d.ts +0 -4
  225. package/dist/types/subPackages/react-test-renderer/jsx-promised/node.d.ts +0 -4
  226. package/dist/types/subPackages/react-test-renderer/jsx-promised/web.d.ts +0 -4
  227. package/src/core.ts +0 -1399
  228. package/src/subPackages/react/component/node.ts +0 -75
  229. package/src/subPackages/react/component/web.ts +0 -80
  230. package/src/subPackages/react/jsx/index.ts +0 -64
  231. package/src/subPackages/react/jsx/node.ts +0 -29
  232. package/src/subPackages/react/jsx/web.ts +0 -29
  233. package/src/subPackages/react-dom/component/web.ts +0 -129
  234. package/src/subPackages/react-dom/jsx/node.ts +0 -145
  235. package/src/subPackages/react-dom/jsx/web.ts +0 -145
  236. package/src/subPackages/react-test-renderer/MemoExoticComponent/node.ts +0 -67
  237. package/src/subPackages/react-test-renderer/component/node.ts +0 -30
  238. package/src/subPackages/react-test-renderer/component/web.ts +0 -30
  239. package/src/subPackages/react-test-renderer/fc/node.ts +0 -77
  240. package/src/subPackages/react-test-renderer/fc/web.ts +0 -77
  241. package/src/subPackages/react-test-renderer/jsx/index.ts +0 -51
  242. package/src/subPackages/react-test-renderer/jsx/node.ts +0 -31
  243. package/src/subPackages/react-test-renderer/jsx/web.ts +0 -31
  244. package/src/subPackages/react-test-renderer/jsx-promised/node.ts +0 -31
  245. package/src/subPackages/react-test-renderer/jsx-promised/web.ts +0 -31
  246. /package/dist/common/{subPackages → SubPackages}/react-dom/jsx/index.js +0 -0
  247. /package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx-promised/web.js +0 -0
  248. /package/dist/module/{subPackages → SubPackages}/react-dom/jsx/index.js +0 -0
  249. /package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx-promised/web.js +0 -0
  250. /package/dist/types/{subPackages → SubPackages}/react-dom/jsx/index.d.ts +0 -0
@@ -0,0 +1,412 @@
1
+ import { IBaseTest } from "../Types";
2
+
3
+ import { ITTestResourceConfiguration, ITestArtifactory, ITLog } from ".";
4
+ import { IUtils } from "./types";
5
+
6
+ export type IGivens<ITestShape extends IBaseTest> = Record<
7
+ string,
8
+ BaseGiven<ITestShape>
9
+ >;
10
+
11
+ export abstract class BaseSuite<ITestShape extends IBaseTest> {
12
+ name: string;
13
+ givens: IGivens<ITestShape>;
14
+ checks: BaseCheck<ITestShape>[];
15
+ store: ITestShape["istore"];
16
+ fails: BaseGiven<ITestShape>[];
17
+ testResourceConfiguration: ITTestResourceConfiguration;
18
+ index: number;
19
+
20
+ constructor(
21
+ name: string,
22
+ index: number,
23
+ givens: IGivens<ITestShape> = {},
24
+ checks: BaseCheck<ITestShape>[] = []
25
+ ) {
26
+ this.name = name;
27
+ this.index = index;
28
+ this.givens = givens;
29
+ this.checks = checks;
30
+ this.fails = [];
31
+ }
32
+
33
+ public toObj() {
34
+ return {
35
+ name: this.name,
36
+ givens: Object.keys(this.givens).map((k) => this.givens[k].toObj()),
37
+ fails: this.fails,
38
+ };
39
+ }
40
+
41
+ setup(
42
+ s: ITestShape["iinput"],
43
+ artifactory: ITestArtifactory,
44
+ tr: ITTestResourceConfiguration,
45
+ utils: IUtils
46
+ ): Promise<ITestShape["isubject"]> {
47
+ return new Promise((res) => res(s as unknown as ITestShape["isubject"]));
48
+ }
49
+
50
+ assertThat(t: ITestShape["then"]): unknown {
51
+ // console.log("base assertThat")
52
+ return t;
53
+ }
54
+
55
+ async run(
56
+ input: ITestShape["iinput"],
57
+ testResourceConfiguration: ITTestResourceConfiguration,
58
+ artifactory: (fPath: string, value: unknown) => void,
59
+ tLog: (...string) => void,
60
+ utils: IUtils
61
+ ): Promise<BaseSuite<ITestShape>> {
62
+ this.testResourceConfiguration = testResourceConfiguration;
63
+ tLog("test resources: ", testResourceConfiguration);
64
+
65
+ const suiteArtifactory = (fPath: string, value: unknown) =>
66
+ artifactory(`suite-${this.index}-${this.name}/${fPath}`, value);
67
+ const subject = await this.setup(
68
+ input,
69
+ suiteArtifactory,
70
+ testResourceConfiguration,
71
+ utils
72
+ );
73
+
74
+ tLog("\nSuite:", this.index, this.name);
75
+ for (const k of Object.keys(this.givens)) {
76
+ const giver = this.givens[k];
77
+ try {
78
+ this.store = await giver.give(
79
+ subject,
80
+ k,
81
+ testResourceConfiguration,
82
+ this.assertThat,
83
+ suiteArtifactory,
84
+ tLog,
85
+ utils
86
+ );
87
+ } catch (e) {
88
+ console.error(e);
89
+ this.fails.push(giver);
90
+ return this;
91
+ }
92
+ }
93
+ for (const [ndx, thater] of this.checks.entries()) {
94
+ await thater.check(
95
+ subject,
96
+ thater.name,
97
+ testResourceConfiguration,
98
+ this.assertThat,
99
+ suiteArtifactory,
100
+ tLog,
101
+ utils
102
+ );
103
+ }
104
+
105
+ // @TODO fix me
106
+ for (const k of Object.keys(this.givens)) {
107
+ const giver = this.givens[k];
108
+
109
+ try {
110
+ giver.afterAll(this.store, artifactory, utils);
111
+ } catch (e) {
112
+ console.error(e);
113
+ this.fails.push(giver);
114
+ return this;
115
+ }
116
+ }
117
+ ////////////////
118
+
119
+ return this;
120
+ }
121
+ }
122
+
123
+ export abstract class BaseGiven<ITestShape extends IBaseTest> {
124
+ name: string;
125
+ features: string[];
126
+ whens: BaseWhen<ITestShape>[];
127
+ thens: BaseThen<ITestShape>[];
128
+ error: Error;
129
+ store: ITestShape["istore"];
130
+ recommendedFsPath: string;
131
+ givenCB: ITestShape["given"];
132
+ initialValues: any;
133
+
134
+ constructor(
135
+ name: string,
136
+ features: string[],
137
+ whens: BaseWhen<ITestShape>[],
138
+ thens: BaseThen<ITestShape>[],
139
+ givenCB: ITestShape["given"],
140
+ initialValues: any
141
+ ) {
142
+ this.name = name;
143
+ this.features = features;
144
+ this.whens = whens;
145
+ this.thens = thens;
146
+ this.givenCB = givenCB;
147
+ this.initialValues = initialValues;
148
+ }
149
+
150
+ beforeAll(store: ITestShape["istore"], artifactory: ITestArtifactory) {
151
+ return store;
152
+ }
153
+
154
+ afterAll(
155
+ store: ITestShape["istore"],
156
+ artifactory: ITestArtifactory,
157
+ utils: IUtils
158
+ ) {
159
+ return store;
160
+ }
161
+
162
+ toObj() {
163
+ return {
164
+ name: this.name,
165
+ whens: this.whens.map((w) => w.toObj()),
166
+ thens: this.thens.map((t) => t.toObj()),
167
+ error: this.error ? [this.error, this.error.stack] : null,
168
+ features: this.features,
169
+ };
170
+ }
171
+
172
+ abstract givenThat(
173
+ subject: ITestShape["isubject"],
174
+ testResourceConfiguration,
175
+ artifactory: ITestArtifactory,
176
+ givenCB: ITestShape["given"]
177
+ ): Promise<ITestShape["istore"]>;
178
+
179
+ async afterEach(
180
+ store: ITestShape["istore"],
181
+ key: string,
182
+ artifactory: ITestArtifactory,
183
+ utils: IUtils
184
+ ): Promise<unknown> {
185
+ return store;
186
+ }
187
+
188
+ async give(
189
+ subject: ITestShape["isubject"],
190
+ key: string,
191
+ testResourceConfiguration,
192
+ tester,
193
+ artifactory: ITestArtifactory,
194
+ tLog: ITLog,
195
+ utils: IUtils
196
+ ) {
197
+ tLog(`\n Given: ${this.name}`);
198
+
199
+ const givenArtifactory = (fPath: string, value: unknown) =>
200
+ artifactory(`given-${key}/${fPath}`, value);
201
+ try {
202
+ this.store = await this.givenThat(
203
+ subject,
204
+ testResourceConfiguration,
205
+ givenArtifactory,
206
+ this.givenCB
207
+ );
208
+
209
+ // tLog(`\n Given this.store`, this.store);
210
+ for (const whenStep of this.whens) {
211
+ await whenStep.test(this.store, testResourceConfiguration, tLog, utils);
212
+ }
213
+ for (const thenStep of this.thens) {
214
+ const t = await thenStep.test(
215
+ this.store,
216
+ testResourceConfiguration,
217
+ tLog,
218
+ utils
219
+ );
220
+ tester(t);
221
+ }
222
+ } catch (e) {
223
+ this.error = e;
224
+ tLog(e);
225
+ tLog("\u0007"); // bell
226
+ // throw e;
227
+ } finally {
228
+ try {
229
+ await this.afterEach(this.store, key, givenArtifactory, utils);
230
+ } catch (e) {
231
+ console.error("afterEach failed! no error will be recorded!", e);
232
+ }
233
+ }
234
+ return this.store;
235
+ }
236
+ }
237
+
238
+ export abstract class BaseWhen<ITestShape extends IBaseTest> {
239
+ public name: string;
240
+ whenCB: (x: ITestShape["iselection"]) => ITestShape["then"];
241
+ error: boolean;
242
+
243
+ constructor(
244
+ name: string,
245
+ whenCB: (xyz: ITestShape["iselection"]) => ITestShape["then"]
246
+ ) {
247
+ this.name = name;
248
+ this.whenCB = whenCB;
249
+ }
250
+
251
+ abstract andWhen(
252
+ store: ITestShape["istore"],
253
+ whenCB: (x: ITestShape["iselection"]) => ITestShape["then"],
254
+ testResource
255
+ );
256
+
257
+ toObj() {
258
+ return {
259
+ name: this.name,
260
+ error: this.error,
261
+ };
262
+ }
263
+
264
+ async test(
265
+ store: ITestShape["istore"],
266
+ testResourceConfiguration,
267
+ tLog: ITLog,
268
+ utils: IUtils
269
+ ) {
270
+ tLog(" When:", this.name);
271
+ try {
272
+ return await this.andWhen(store, this.whenCB, testResourceConfiguration);
273
+ } catch (e) {
274
+ this.error = true;
275
+ throw e;
276
+ }
277
+ }
278
+ }
279
+
280
+ export abstract class BaseThen<ITestShape extends IBaseTest> {
281
+ public name: string;
282
+ thenCB: (storeState: ITestShape["iselection"]) => ITestShape["then"];
283
+ error: boolean;
284
+
285
+ constructor(
286
+ name: string,
287
+ thenCB: (val: ITestShape["iselection"]) => ITestShape["then"]
288
+ ) {
289
+ this.name = name;
290
+ this.thenCB = thenCB;
291
+ }
292
+
293
+ toObj() {
294
+ return {
295
+ name: this.name,
296
+ error: this.error,
297
+ };
298
+ }
299
+
300
+ abstract butThen(
301
+ store: ITestShape["istore"],
302
+ thenCB,
303
+ testResourceConfiguration?
304
+ ): Promise<ITestShape["iselection"]>;
305
+
306
+ async test(
307
+ store: ITestShape["istore"],
308
+ testResourceConfiguration,
309
+ tLog: ITLog,
310
+ utils: IUtils
311
+ ): Promise<ITestShape["then"] | undefined> {
312
+ tLog(" Then:", this.name);
313
+ try {
314
+ const x = await this.butThen(
315
+ store,
316
+ this.thenCB,
317
+ testResourceConfiguration
318
+ );
319
+ return x;
320
+ } catch (e) {
321
+ console.log("test failed", e);
322
+ this.error = true;
323
+ throw e;
324
+ }
325
+ }
326
+ }
327
+
328
+ export abstract class BaseCheck<ITestShape extends IBaseTest> {
329
+ name: string;
330
+ features: string[];
331
+ checkCB: (whens, thens) => any;
332
+ whens: {
333
+ [K in keyof ITestShape["whens"]]: (p, tc) => BaseWhen<ITestShape>;
334
+ };
335
+ thens: {
336
+ [K in keyof ITestShape["thens"]]: (p, tc) => BaseThen<ITestShape>;
337
+ };
338
+
339
+ constructor(
340
+ name: string,
341
+ features: string[],
342
+ checkCB: (whens, thens) => any,
343
+ whens,
344
+ thens
345
+ ) {
346
+ this.name = name;
347
+ this.features = features;
348
+ this.checkCB = checkCB;
349
+ this.whens = whens;
350
+ this.thens = thens;
351
+ }
352
+
353
+ abstract checkThat(
354
+ subject: ITestShape["isubject"],
355
+ testResourceConfiguration,
356
+ artifactory: ITestArtifactory
357
+ ): Promise<ITestShape["istore"]>;
358
+
359
+ async afterEach(
360
+ store: ITestShape["istore"],
361
+ key: string,
362
+ cb,
363
+ utils: IUtils
364
+ ): Promise<unknown> {
365
+ return;
366
+ }
367
+
368
+ async check(
369
+ subject: ITestShape["isubject"],
370
+ key: string,
371
+ testResourceConfiguration,
372
+ tester,
373
+ artifactory: ITestArtifactory,
374
+ tLog: ITLog,
375
+ utils: IUtils
376
+ ) {
377
+ tLog(`\n Check: ${this.name}`);
378
+ const store = await this.checkThat(
379
+ subject,
380
+ testResourceConfiguration,
381
+ artifactory
382
+ );
383
+ await this.checkCB(
384
+ Object.entries(this.whens).reduce((a, [key, when]) => {
385
+ a[key] = async (payload) => {
386
+ return await when(payload, testResourceConfiguration).test(
387
+ store,
388
+ testResourceConfiguration,
389
+ tLog,
390
+ utils
391
+ );
392
+ };
393
+ return a;
394
+ }, {}),
395
+ Object.entries(this.thens).reduce((a, [key, then]) => {
396
+ a[key] = async (payload) => {
397
+ const t = await then(payload, testResourceConfiguration).test(
398
+ store,
399
+ testResourceConfiguration,
400
+ tLog,
401
+ utils
402
+ );
403
+ tester(t);
404
+ };
405
+ return a;
406
+ }, {})
407
+ );
408
+
409
+ await this.afterEach(store, key, () => {}, utils);
410
+ return;
411
+ }
412
+ }
@@ -0,0 +1,228 @@
1
+ import {
2
+ ITTestResourceRequest,
3
+ ITestJob,
4
+ ITLog,
5
+ ILogWriter,
6
+ ITTestResourceConfiguration,
7
+ } from ".";
8
+ import { IBaseTest, ITestSpecification } from "../Types.js";
9
+
10
+ import {
11
+ ISuiteKlasser,
12
+ IGivenKlasser,
13
+ IWhenKlasser,
14
+ IThenKlasser,
15
+ ICheckKlasser,
16
+ IUtils,
17
+ } from "./types.js";
18
+
19
+ import {
20
+ BaseCheck,
21
+ BaseSuite,
22
+ BaseWhen,
23
+ BaseThen,
24
+ BaseGiven,
25
+ } from "./abstractBase.js";
26
+
27
+ export abstract class BaseBuilder<
28
+ ITestShape extends IBaseTest,
29
+ SuiteExtensions,
30
+ GivenExtensions,
31
+ WhenExtensions,
32
+ ThenExtensions,
33
+ CheckExtensions
34
+ > {
35
+ specs: any;
36
+
37
+ assertThis: (t: ITestShape["then"]) => {};
38
+
39
+ testResourceRequirement: ITTestResourceRequest;
40
+ artifacts: Promise<unknown>[] = [];
41
+ testJobs: ITestJob[];
42
+ testSpecification: ITestSpecification<ITestShape>;
43
+ suitesOverrides: Record<keyof SuiteExtensions, ISuiteKlasser<ITestShape>>;
44
+ givenOverides: Record<keyof GivenExtensions, IGivenKlasser<ITestShape>>;
45
+ whenOverides: Record<keyof WhenExtensions, IWhenKlasser<ITestShape>>;
46
+ thenOverides: Record<keyof ThenExtensions, IThenKlasser<ITestShape>>;
47
+ checkOverides: Record<keyof CheckExtensions, ICheckKlasser<ITestShape>>;
48
+
49
+ constructor(
50
+ public readonly input: ITestShape["iinput"],
51
+ suitesOverrides: Record<keyof SuiteExtensions, ISuiteKlasser<ITestShape>>,
52
+ givenOverides: Record<keyof GivenExtensions, IGivenKlasser<ITestShape>>,
53
+ whenOverides: Record<keyof WhenExtensions, IWhenKlasser<ITestShape>>,
54
+ thenOverides: Record<keyof ThenExtensions, IThenKlasser<ITestShape>>,
55
+ checkOverides: Record<keyof CheckExtensions, ICheckKlasser<ITestShape>>,
56
+ logWriter: ILogWriter,
57
+ testResourceRequirement: ITTestResourceRequest,
58
+ testSpecification: any
59
+ ) {
60
+ this.artifacts = [];
61
+ this.testResourceRequirement = testResourceRequirement;
62
+ this.suitesOverrides = suitesOverrides;
63
+ this.givenOverides = givenOverides;
64
+ this.whenOverides = whenOverides;
65
+ this.thenOverides = thenOverides;
66
+ this.checkOverides = checkOverides;
67
+ this.testSpecification = testSpecification;
68
+
69
+ this.specs = testSpecification(
70
+ this.Suites(),
71
+ this.Given(),
72
+ this.When(),
73
+ this.Then(),
74
+ this.Check()
75
+ );
76
+
77
+ const suiteRunner =
78
+ (suite: BaseSuite<ITestShape>, utils: IUtils) =>
79
+ async (
80
+ testResourceConfiguration: ITTestResourceConfiguration,
81
+ tLog: ITLog,
82
+ utils: IUtils
83
+ ): Promise<BaseSuite<ITestShape>> => {
84
+ return await suite.run(
85
+ input,
86
+ testResourceConfiguration,
87
+ (fPath: string, value: unknown) =>
88
+ logWriter.testArtiFactoryfileWriter(tLog, (p: Promise<void>) => {
89
+ this.artifacts.push(p);
90
+ })(testResourceConfiguration.fs + "/" + fPath, value),
91
+ tLog,
92
+ utils
93
+ );
94
+ };
95
+
96
+ this.testJobs = this.specs.map(
97
+ (suite: BaseSuite<ITestShape>, utils: IUtils) => {
98
+ const runner = suiteRunner(suite, utils);
99
+
100
+ return {
101
+ test: suite,
102
+ testResourceRequirement,
103
+
104
+ toObj: () => {
105
+ return suite.toObj();
106
+ },
107
+
108
+ runner,
109
+
110
+ receiveTestResourceConfig: async function (
111
+ testResourceConfiguration = {
112
+ name: "",
113
+ fs: ".",
114
+ ports: [],
115
+ scheduled: false,
116
+ },
117
+ y: IUtils
118
+ ) {
119
+ console.log(
120
+ `testResourceConfiguration ${JSON.stringify(
121
+ testResourceConfiguration,
122
+ null,
123
+ 2
124
+ )}`
125
+ );
126
+
127
+ // await logWriter.mkdirSync(testResourceConfiguration.fs);
128
+ // if (!fs.existsSync(destFolder)) {
129
+ // fs.mkdirSync(destFolder, { recursive: true });
130
+ // }
131
+
132
+ logWriter.writeFileSync(
133
+ `${testResourceConfiguration.fs}/tests.json`,
134
+ JSON.stringify(this.toObj(), null, 2)
135
+ );
136
+
137
+ const logFilePath = `${testResourceConfiguration.fs}/log.txt`;
138
+
139
+ const access = await logWriter.createWriteStream(logFilePath);
140
+
141
+ const tLog = (...l: string[]) => access.write(`${l.toString()}\n`);
142
+
143
+ const suiteDone: BaseSuite<ITestShape> = await runner(
144
+ testResourceConfiguration,
145
+ tLog,
146
+ y
147
+ );
148
+
149
+ const logPromise = new Promise((res, rej) => {
150
+ access.on("finish", () => {
151
+ res(true);
152
+ });
153
+ });
154
+ access.end();
155
+
156
+ const numberOfFailures = Object.keys(suiteDone.givens).filter(
157
+ (k) => {
158
+ return suiteDone.givens[k].error;
159
+ }
160
+ ).length;
161
+ logWriter.writeFileSync(
162
+ `${testResourceConfiguration.fs}/exitcode`,
163
+ numberOfFailures.toString()
164
+ );
165
+ console.log(
166
+ `exiting gracefully with ${numberOfFailures} failures.`
167
+ );
168
+ return {
169
+ failed: numberOfFailures,
170
+ artifacts: this.artifacts || [],
171
+ logPromise,
172
+ };
173
+ },
174
+ };
175
+ }
176
+ );
177
+ }
178
+
179
+ Specs() {
180
+ return this.specs;
181
+ }
182
+ Suites() {
183
+ return this.suitesOverrides;
184
+ }
185
+
186
+ Given(): Record<
187
+ keyof GivenExtensions,
188
+ (
189
+ name: string,
190
+ features: string[],
191
+ whens: BaseWhen<ITestShape>[],
192
+ thens: BaseThen<ITestShape>[],
193
+ gcb
194
+ ) => BaseGiven<ITestShape>
195
+ > {
196
+ return this.givenOverides;
197
+ }
198
+
199
+ When(): Record<
200
+ keyof WhenExtensions,
201
+ (arg0: ITestShape["istore"], ...arg1: any) => BaseWhen<ITestShape>
202
+ > {
203
+ return this.whenOverides;
204
+ }
205
+
206
+ Then(): Record<
207
+ keyof ThenExtensions,
208
+ (
209
+ selection: ITestShape["iselection"],
210
+ expectation: any
211
+ ) => BaseThen<ITestShape>
212
+ > {
213
+ return this.thenOverides;
214
+ }
215
+
216
+ Check(): Record<
217
+ keyof CheckExtensions,
218
+ (
219
+ feature: string,
220
+ callback: (whens, thens) => any,
221
+ whens,
222
+ thens,
223
+ x
224
+ ) => BaseCheck<ITestShape>
225
+ > {
226
+ return this.checkOverides;
227
+ }
228
+ }