testeranto 0.47.11 → 0.47.13

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 (52) hide show
  1. package/dist/common/Features.js +85 -0
  2. package/dist/common/Node.js +82 -0
  3. package/dist/common/NodeWriter.js +56 -0
  4. package/dist/common/Project.js +648 -0
  5. package/dist/common/Types.js +2 -0
  6. package/dist/common/Web.js +70 -0
  7. package/dist/common/core.js +392 -0
  8. package/dist/common/electron.js +40 -0
  9. package/dist/common/preload.js +8 -0
  10. package/dist/common/subPackages/react/component.js +2 -0
  11. package/dist/common/subPackages/react/node.js +57 -0
  12. package/dist/common/subPackages/react/web.js +57 -0
  13. package/dist/common/subPackages/react-test-render/component.js +2 -0
  14. package/dist/common/subPackages/react-test-render/node.js +46 -0
  15. package/dist/common/subPackages/react-test-render/web.js +46 -0
  16. package/dist/common/tsconfig.common.tsbuildinfo +1 -0
  17. package/dist/module/Features.js +74 -0
  18. package/dist/module/Node.js +77 -0
  19. package/dist/module/NodeWriter.js +50 -0
  20. package/dist/module/Project.js +618 -0
  21. package/dist/module/Report.js +186 -0
  22. package/dist/module/Types.js +1 -0
  23. package/dist/module/Web.js +65 -0
  24. package/dist/module/core.js +383 -0
  25. package/dist/module/electron.js +35 -0
  26. package/dist/module/preload.js +6 -0
  27. package/dist/module/subPackages/react/component.js +1 -0
  28. package/dist/module/subPackages/react/node.js +52 -0
  29. package/dist/module/subPackages/react/web.js +52 -0
  30. package/dist/module/subPackages/react-test-render/component.js +1 -0
  31. package/dist/module/subPackages/react-test-render/node.js +16 -0
  32. package/dist/module/subPackages/react-test-render/web.js +16 -0
  33. package/dist/module/tsconfig.module.tsbuildinfo +1 -0
  34. package/dist/types/Features.d.ts +68 -0
  35. package/dist/types/Node.d.ts +12 -0
  36. package/dist/types/NodeWriter.d.ts +2 -0
  37. package/dist/types/Project.d.ts +32 -0
  38. package/dist/types/Types.d.ts +17 -0
  39. package/dist/types/Web.d.ts +12 -0
  40. package/dist/types/core.d.ts +219 -0
  41. package/dist/types/electron.d.ts +1 -0
  42. package/dist/types/preload.d.ts +1 -0
  43. package/dist/types/subPackages/react/component.d.ts +17 -0
  44. package/dist/types/subPackages/react/node.d.ts +4 -0
  45. package/dist/types/subPackages/react/web.d.ts +4 -0
  46. package/dist/types/subPackages/react-test-render/component.d.ts +17 -0
  47. package/dist/types/subPackages/react-test-render/node.d.ts +4 -0
  48. package/dist/types/subPackages/react-test-render/web.d.ts +4 -0
  49. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  50. package/package.json +9 -5
  51. package/src/subPackages/react/component.ts +1 -0
  52. package/src/subPackages/react-test-render/component.ts +21 -0
@@ -0,0 +1,186 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import ReactDom from "react-dom/client";
3
+ import Col from 'react-bootstrap/Col';
4
+ import Nav from 'react-bootstrap/Nav';
5
+ import Row from 'react-bootstrap/Row';
6
+ import Tab from 'react-bootstrap/Tab';
7
+ import Tabs from 'react-bootstrap/Tabs';
8
+ import { Sigma, RandomizeNodePositions, RelativeSize } from 'react-sigma';
9
+ import 'bootstrap/dist/css/bootstrap.min.css';
10
+ import { TesterantoFeatures } from "./Features";
11
+ const graphToIGraphData = (g) => {
12
+ return {
13
+ nodes: g.nodes().map((n) => {
14
+ return {
15
+ id: n,
16
+ label: n
17
+ };
18
+ }),
19
+ edges: g.mapEdges((id, attributes, source, target) => {
20
+ return {
21
+ id,
22
+ label: id,
23
+ source,
24
+ target,
25
+ };
26
+ })
27
+ };
28
+ };
29
+ document.addEventListener("DOMContentLoaded", function () {
30
+ const elem = document.getElementById("root");
31
+ if (elem) {
32
+ ReactDom.createRoot(elem).render(React.createElement(Report, {}));
33
+ }
34
+ });
35
+ const Report = () => {
36
+ const [tests, setTests] = useState([]);
37
+ const [features, setFeatures] = useState(new TesterantoFeatures({}, {
38
+ undirected: [],
39
+ directed: [],
40
+ dags: []
41
+ }));
42
+ useEffect(() => {
43
+ const importTests = async () => {
44
+ const module = await import('tests.test.js');
45
+ setTests(module.default);
46
+ };
47
+ importTests();
48
+ }, []);
49
+ useEffect(() => {
50
+ const importFeatures = async () => {
51
+ const module = await import('features.test.js');
52
+ setFeatures(module.default);
53
+ };
54
+ importFeatures();
55
+ }, []);
56
+ return (React.createElement("div", null,
57
+ React.createElement("style", null, `
58
+ pre, code, p {
59
+ max-width: 30rem;
60
+ }
61
+ footer {
62
+ background-color: lightgray;
63
+ margin: 0.5rem;
64
+ padding: 0.5rem;
65
+ position: fixed;
66
+ bottom: 0;
67
+ right: 0;
68
+ }
69
+ `),
70
+ features && tests && React.createElement(Tabs, { defaultActiveKey: "home" },
71
+ React.createElement(Tab, { eventKey: "home", title: "config" },
72
+ React.createElement("pre", null, JSON.stringify(features, null, 2)),
73
+ React.createElement("pre", null, JSON.stringify(tests, null, 2))),
74
+ React.createElement(Tab, { eventKey: "features", title: "features" },
75
+ React.createElement(Tab.Container, { id: "left-tabs-example5", defaultActiveKey: "feature-0" },
76
+ React.createElement(Row, null,
77
+ React.createElement(Col, { sm: 2 },
78
+ React.createElement(Nav, { variant: "pills", className: "flex-column" }, Object.keys(features.features).map((featureKey, ndx) => React.createElement(Nav.Item, { key: ndx },
79
+ React.createElement(Nav.Link, { eventKey: `feature-${ndx}` }, featureKey))))),
80
+ React.createElement(Col, { sm: 6 },
81
+ React.createElement(Tab.Content, null, Object.keys(features.features).map((featureKey, ndx) => {
82
+ const feature = features[featureKey];
83
+ return (React.createElement(Tab.Pane, { eventKey: `feature-${ndx}`, key: ndx },
84
+ React.createElement("pre", null, JSON.stringify(feature, null, 2))));
85
+ }))),
86
+ React.createElement(Col, { sm: 4 },
87
+ React.createElement(Tabs, { defaultActiveKey: "feature.networks" },
88
+ React.createElement(Tab, { eventKey: "feature.networks", title: "networks" },
89
+ React.createElement(Tabs, { defaultActiveKey: "dag" },
90
+ React.createElement(Tab, { eventKey: "dag", title: "DAG" },
91
+ React.createElement(Tab.Content, null,
92
+ React.createElement("pre", null, JSON.stringify(features.graphs.dags, null, 2)))),
93
+ React.createElement(Tab, { eventKey: "directed", title: "Directed" },
94
+ React.createElement(Tab.Content, null,
95
+ React.createElement("pre", null, JSON.stringify(features.graphs.directed, null, 2)))),
96
+ React.createElement(Tab, { eventKey: "undirected", title: "Undirected" },
97
+ React.createElement(Tab.Content, null,
98
+ React.createElement("pre", null, JSON.stringify(features.graphs.undirected, null, 2)))))),
99
+ React.createElement(Tab, { eventKey: "feature.tests", title: "tests" },
100
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(tests, null, 2)))))))),
101
+ React.createElement(Tab, { eventKey: "networks", title: "networks" },
102
+ React.createElement(Tab.Container, { id: "left-tabs-example88", defaultActiveKey: `dag` },
103
+ React.createElement(Row, null,
104
+ React.createElement(Tabs, { defaultActiveKey: "dag" },
105
+ React.createElement(Tab, { eventKey: "dag", title: "DAG" },
106
+ React.createElement(Tab.Content, null,
107
+ React.createElement(Row, null,
108
+ React.createElement(Col, { sm: 2 },
109
+ React.createElement(Nav, { variant: "pills", className: "flex-column" }, features.graphs.dags.map((g, ndx2) => React.createElement(Nav.Item, { key: ndx2 },
110
+ React.createElement(Nav.Link, { eventKey: `networks-dags-${ndx2}` }, g.name))))),
111
+ React.createElement(Col, { sm: 6 },
112
+ React.createElement(Tab.Content, null, features.graphs.dags[0] && React.createElement(React.Fragment, null,
113
+ React.createElement(Sigma, { graph: graphToIGraphData(features.graphs.dags[0].graph), settings: { drawEdges: true, clone: false } },
114
+ React.createElement(RelativeSize, { initialSize: 25 }),
115
+ React.createElement(RandomizeNodePositions, null)),
116
+ React.createElement("pre", null, JSON.stringify(features.graphs.dags[0].graph, null, 2))))),
117
+ React.createElement(Col, { sm: 4 },
118
+ React.createElement(Tabs, { defaultActiveKey: "networks.features" },
119
+ React.createElement(Tab, { eventKey: "networks.features", title: "features" },
120
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(features, null, 2))),
121
+ React.createElement(Tab, { eventKey: "feature.tests", title: "tests" },
122
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(tests, null, 2)))))))),
123
+ React.createElement(Tab, { eventKey: "directed", title: "Directed" },
124
+ React.createElement(Tab.Content, null,
125
+ React.createElement(Row, null,
126
+ React.createElement(Col, { sm: 2 },
127
+ React.createElement(Nav, { variant: "pills", className: "flex-column" }, features.graphs.directed.map((g, ndx2) => React.createElement(Nav.Item, { key: ndx2 },
128
+ React.createElement(Nav.Link, { eventKey: `networks-directed-${ndx2}` }, g.name))))),
129
+ React.createElement(Col, { sm: 6 },
130
+ React.createElement(Tab.Content, null, features.graphs.directed[0] && React.createElement(React.Fragment, null,
131
+ React.createElement(Sigma, { graph: graphToIGraphData(features.graphs.directed[0].graph), settings: { drawEdges: true, clone: false } },
132
+ React.createElement(RelativeSize, { initialSize: 25 }),
133
+ React.createElement(RandomizeNodePositions, null)),
134
+ React.createElement("pre", null, JSON.stringify(features.graphs.directed[0].graph, null, 2))))),
135
+ React.createElement(Col, { sm: 4 },
136
+ React.createElement(Tabs, { defaultActiveKey: "networks.features" },
137
+ React.createElement(Tab, { eventKey: "networks.features", title: "features" },
138
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(features, null, 2))),
139
+ React.createElement(Tab, { eventKey: "feature.tests", title: "tests" },
140
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(tests, null, 2)))))))),
141
+ React.createElement(Tab, { eventKey: "undirected", title: "Undirected" },
142
+ React.createElement(Tab.Content, null,
143
+ React.createElement(Row, null,
144
+ React.createElement(Col, { sm: 2 },
145
+ React.createElement(Nav, { variant: "pills", className: "flex-column" }, features.graphs.undirected.map((g, ndx2) => React.createElement(Nav.Item, { key: ndx2 },
146
+ React.createElement(Nav.Link, { eventKey: `networks-undirected-${ndx2}` }, g.name))))),
147
+ React.createElement(Col, { sm: 6 },
148
+ React.createElement(Tab.Content, null, features.graphs.undirected[0] && React.createElement(React.Fragment, null,
149
+ React.createElement(Sigma, { graph: graphToIGraphData(features.graphs.undirected[0].graph), settings: { drawEdges: true, clone: false } },
150
+ React.createElement(RelativeSize, { initialSize: 25 }),
151
+ React.createElement(RandomizeNodePositions, null)),
152
+ React.createElement("pre", null, JSON.stringify(features.graphs.undirected[0].graph, null, 2))))),
153
+ React.createElement(Col, { sm: 4 },
154
+ React.createElement(Tabs, { defaultActiveKey: "networks.features" },
155
+ React.createElement(Tab, { eventKey: "networks.features", title: "features" },
156
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(features, null, 2))),
157
+ React.createElement(Tab, { eventKey: "feature.tests", title: "tests" },
158
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(tests, null, 2)))))))))))),
159
+ React.createElement(Tab, { eventKey: "results", title: "tests" },
160
+ React.createElement(Tab.Container, { id: "left-tabs-example5", defaultActiveKey: "feature-0" },
161
+ React.createElement(Row, null,
162
+ React.createElement(Col, { sm: 2 }),
163
+ React.createElement(Col, { sm: 6 },
164
+ React.createElement(Tab.Content, null, tests.map((t, ndx) => {
165
+ return (React.createElement(Tab.Pane, { eventKey: `feature-${ndx}`, key: ndx },
166
+ React.createElement("pre", null, JSON.stringify(t, null, 2))));
167
+ }))),
168
+ React.createElement(Col, { sm: 4 },
169
+ React.createElement(Tabs, { defaultActiveKey: "feature.networks" },
170
+ React.createElement(Tab, { eventKey: "feature.networks", title: "networks" },
171
+ React.createElement(Tabs, { defaultActiveKey: "dag" },
172
+ React.createElement(Tab, { eventKey: "dag", title: "DAG" },
173
+ React.createElement(Tab.Content, null,
174
+ React.createElement("pre", null, JSON.stringify(features.graphs.dags, null, 2)))),
175
+ React.createElement(Tab, { eventKey: "directed", title: "Directed" },
176
+ React.createElement(Tab.Content, null,
177
+ React.createElement("pre", null, JSON.stringify(features.graphs.directed, null, 2)))),
178
+ React.createElement(Tab, { eventKey: "undirected", title: "Undirected" },
179
+ React.createElement(Tab.Content, null,
180
+ React.createElement("pre", null, JSON.stringify(features.graphs.undirected, null, 2)))))),
181
+ React.createElement(Tab, { eventKey: "tests.features", title: "features" },
182
+ React.createElement("pre", { id: "theProps" }, JSON.stringify(features, null, 2))))))))),
183
+ React.createElement("footer", null,
184
+ "made with \u2764\uFE0F and ",
185
+ React.createElement("a", { href: "https://adamwong246.github.io/testeranto/" }, "testeranto "))));
186
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ import { defaultTestResourceRequirement, } from "./core";
2
+ import TesterantoLevelTwo from "./core";
3
+ // import { ipcRenderer } from "electron";
4
+ const webSocket = new WebSocket("ws://localhost:8080");
5
+ const receiveTestResourceConfig = async (t, testresource) => {
6
+ const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(testresource);
7
+ webSocket.send(JSON.stringify({
8
+ type: "testeranto:adios",
9
+ data: {
10
+ failed,
11
+ testResourceConfiguration: t.test.testResourceConfiguration,
12
+ results: t.toObj(),
13
+ },
14
+ }));
15
+ Promise.all([...artifacts, logPromise]).then(async () => {
16
+ // ipcRenderer.invoke('quit-app', failed);
17
+ window.exit(failed);
18
+ });
19
+ };
20
+ export default async (input, testSpecification, testImplementation, testInterface, testResourceRequirement = defaultTestResourceRequirement) => {
21
+ const mrt = new TesterantoLevelTwo(input, testSpecification, testImplementation, testInterface, testResourceRequirement, testInterface.assertioner || (async (t) => t), testInterface.beforeEach ||
22
+ async function (subject, initialValues, testResource) {
23
+ return subject;
24
+ }, testInterface.afterEach || (async (s) => s), testInterface.afterAll || ((store) => undefined), testInterface.butThen || (async (a) => a), testInterface.andWhen, testInterface.actionHandler ||
25
+ function (b) {
26
+ return b;
27
+ }, window.NodeWriter);
28
+ const tl2 = mrt;
29
+ const t = tl2.testJobs[0];
30
+ const testResourceArg = decodeURIComponent(new URLSearchParams(location.search).get('requesting') || '');
31
+ try {
32
+ const partialTestResource = JSON.parse(testResourceArg);
33
+ if (partialTestResource.fs && partialTestResource.ports) {
34
+ receiveTestResourceConfig(t, partialTestResource);
35
+ }
36
+ else {
37
+ console.log("test configuration is incomplete", partialTestResource);
38
+ console.log("requesting test resources via ws", testResourceRequirement);
39
+ webSocket.addEventListener("open", (event) => {
40
+ webSocket.addEventListener("message", (event) => {
41
+ console.log("Message from server ", event.data);
42
+ });
43
+ const r = JSON.stringify({
44
+ type: "testeranto:hola",
45
+ data: {
46
+ testResourceRequirement,
47
+ },
48
+ });
49
+ webSocket.send(r);
50
+ console.log("awaiting test resources via websocket...", r);
51
+ webSocket.onmessage = (async (msg) => {
52
+ console.log("message: ", msg);
53
+ const resourcesFromPm2 = msg.data.testResourceConfiguration;
54
+ const secondTestResource = Object.assign(Object.assign({ fs: "." }, JSON.parse(JSON.stringify(partialTestResource))), JSON.parse(JSON.stringify(resourcesFromPm2)));
55
+ console.log("secondTestResource", secondTestResource);
56
+ receiveTestResourceConfig(t, secondTestResource);
57
+ });
58
+ });
59
+ }
60
+ }
61
+ catch (e) {
62
+ console.error(e);
63
+ // process.exit(-1);
64
+ }
65
+ };
@@ -0,0 +1,383 @@
1
+ const defaultTestResource = { name: "", fs: ".", ports: [] };
2
+ export const defaultTestResourceRequirement = {
3
+ ports: 0
4
+ };
5
+ export class BaseSuite {
6
+ constructor(name, index, givens = {}, checks = []) {
7
+ this.name = name;
8
+ this.index = index;
9
+ this.givens = givens;
10
+ this.checks = checks;
11
+ this.fails = [];
12
+ }
13
+ toObj() {
14
+ return {
15
+ name: this.name,
16
+ givens: Object.keys(this.givens).map((k) => this.givens[k].toObj()),
17
+ fails: this.fails,
18
+ };
19
+ }
20
+ setup(s, artifactory) {
21
+ return new Promise((res) => res(s));
22
+ }
23
+ test(t) {
24
+ return t;
25
+ }
26
+ async run(input, testResourceConfiguration, artifactory, tLog) {
27
+ this.testResourceConfiguration = testResourceConfiguration;
28
+ const suiteArtifactory = (fPath, value) => artifactory(`suite-${this.index}-${this.name}/${fPath}`, value);
29
+ const subject = await this.setup(input, suiteArtifactory);
30
+ tLog("\nSuite:", this.index, this.name);
31
+ for (const k of Object.keys(this.givens)) {
32
+ const giver = this.givens[k];
33
+ try {
34
+ this.store = await giver.give(subject, k, testResourceConfiguration, this.test, suiteArtifactory, tLog);
35
+ }
36
+ catch (e) {
37
+ console.error(e);
38
+ this.fails.push(giver);
39
+ return this;
40
+ }
41
+ }
42
+ for (const [ndx, thater] of this.checks.entries()) {
43
+ await thater.check(subject, thater.name, testResourceConfiguration, this.test, suiteArtifactory, tLog);
44
+ }
45
+ // @TODO fix me
46
+ for (const k of Object.keys(this.givens)) {
47
+ const giver = this.givens[k];
48
+ giver.afterAll(this.store, artifactory);
49
+ }
50
+ ////////////////
51
+ return this;
52
+ }
53
+ }
54
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////
55
+ export class BaseGiven {
56
+ constructor(name, features, whens, thens) {
57
+ this.name = name;
58
+ this.features = features;
59
+ this.whens = whens;
60
+ this.thens = thens;
61
+ }
62
+ beforeAll(store, artifactory) {
63
+ return store;
64
+ }
65
+ afterAll(store, artifactory) {
66
+ return store;
67
+ }
68
+ toObj() {
69
+ return {
70
+ name: this.name,
71
+ whens: this.whens.map((w) => w.toObj()),
72
+ thens: this.thens.map((t) => t.toObj()),
73
+ error: this.error ? [this.error, this.error.stack] : null,
74
+ features: this.features,
75
+ };
76
+ }
77
+ async afterEach(store, key, artifactory) {
78
+ return store;
79
+ }
80
+ async give(subject, key, testResourceConfiguration, tester, artifactory, tLog) {
81
+ tLog(`\n Given: ${this.name}`);
82
+ const givenArtifactory = (fPath, value) => artifactory(`given-${key}/${fPath}`, value);
83
+ try {
84
+ this.store = await this.givenThat(subject, testResourceConfiguration, givenArtifactory);
85
+ // tLog(`\n Given this.store`, this.store);
86
+ for (const whenStep of this.whens) {
87
+ await whenStep.test(this.store, testResourceConfiguration, tLog);
88
+ }
89
+ for (const thenStep of this.thens) {
90
+ const t = await thenStep.test(this.store, testResourceConfiguration, tLog);
91
+ tester(t);
92
+ }
93
+ }
94
+ catch (e) {
95
+ this.error = e;
96
+ tLog(e);
97
+ tLog("\u0007"); // bell
98
+ // throw e;
99
+ }
100
+ finally {
101
+ try {
102
+ await this.afterEach(this.store, key, givenArtifactory);
103
+ }
104
+ catch (e) {
105
+ console.error("afterEach failed! no error will be recorded!", e);
106
+ }
107
+ }
108
+ return this.store;
109
+ }
110
+ }
111
+ export class BaseWhen {
112
+ constructor(name, actioner) {
113
+ this.name = name;
114
+ this.actioner = actioner;
115
+ }
116
+ toObj() {
117
+ return {
118
+ name: this.name,
119
+ error: this.error,
120
+ };
121
+ }
122
+ async test(store, testResourceConfiguration, tLog) {
123
+ tLog(" When:", this.name);
124
+ try {
125
+ return await this.andWhen(store, this.actioner, testResourceConfiguration);
126
+ }
127
+ catch (e) {
128
+ this.error = true;
129
+ throw e;
130
+ }
131
+ }
132
+ }
133
+ export class BaseThen {
134
+ constructor(name, thenCB) {
135
+ this.name = name;
136
+ this.thenCB = thenCB;
137
+ }
138
+ toObj() {
139
+ return {
140
+ name: this.name,
141
+ error: this.error,
142
+ };
143
+ }
144
+ async test(store, testResourceConfiguration, tLog) {
145
+ tLog(" Then:", this.name);
146
+ try {
147
+ return this.thenCB(await this.butThen(store, testResourceConfiguration));
148
+ }
149
+ catch (e) {
150
+ console.log("test failed", e);
151
+ this.error = true;
152
+ throw e;
153
+ }
154
+ // try {
155
+ // return await (this.thenCB(
156
+ // await (async () => {
157
+ // try {
158
+ // return await (
159
+ // (() => {
160
+ // try {
161
+ // return this.butThen(store, testResourceConfiguration)
162
+ // } catch (e) {
163
+ // this.error = true;
164
+ // throw e
165
+ // }
166
+ // })()
167
+ // );
168
+ // } catch (e) {
169
+ // this.error = true;
170
+ // throw e
171
+ // }
172
+ // })()
173
+ // ));
174
+ // } catch (e) {
175
+ // this.error = true;
176
+ // throw e
177
+ // }
178
+ }
179
+ }
180
+ export class BaseCheck {
181
+ constructor(name, features, checkCB, whens, thens) {
182
+ this.name = name;
183
+ this.features = features;
184
+ this.checkCB = checkCB;
185
+ this.whens = whens;
186
+ this.thens = thens;
187
+ }
188
+ async afterEach(store, key, cb) {
189
+ return;
190
+ }
191
+ async check(subject, key, testResourceConfiguration, tester, artifactory, tLog) {
192
+ tLog(`\n Check: ${this.name}`);
193
+ const store = await this.checkThat(subject, testResourceConfiguration, artifactory);
194
+ await this.checkCB(Object.entries(this.whens).reduce((a, [key, when]) => {
195
+ a[key] = async (payload) => {
196
+ return await when(payload, testResourceConfiguration).test(store, testResourceConfiguration, tLog);
197
+ };
198
+ return a;
199
+ }, {}), Object.entries(this.thens).reduce((a, [key, then]) => {
200
+ a[key] = async (payload) => {
201
+ const t = await then(payload, testResourceConfiguration).test(store, testResourceConfiguration, tLog);
202
+ tester(t);
203
+ };
204
+ return a;
205
+ }, {}));
206
+ await this.afterEach(store, key);
207
+ return;
208
+ }
209
+ }
210
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////
211
+ class TesterantoLevelZero {
212
+ constructor(cc, suitesOverrides, givenOverides, whenOverides, thenOverides, checkOverides) {
213
+ this.cc = cc;
214
+ this.constructorator = cc;
215
+ this.suitesOverrides = suitesOverrides;
216
+ this.givenOverides = givenOverides;
217
+ this.whenOverides = whenOverides;
218
+ this.thenOverides = thenOverides;
219
+ this.checkOverides = checkOverides;
220
+ }
221
+ Suites() {
222
+ return this.suitesOverrides;
223
+ }
224
+ Given() {
225
+ return this.givenOverides;
226
+ }
227
+ When() {
228
+ return this.whenOverides;
229
+ }
230
+ Then() {
231
+ return this.thenOverides;
232
+ }
233
+ Check() {
234
+ return this.checkOverides;
235
+ }
236
+ }
237
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////
238
+ class TesterantoLevelOne {
239
+ constructor(testImplementation, testSpecification, input, suiteKlasser, givenKlasser, whenKlasser, thenKlasser, checkKlasser, testResourceRequirement, logWriter) {
240
+ this.artifacts = [];
241
+ const classySuites = Object.entries(testImplementation.Suites).reduce((a, [key], index) => {
242
+ a[key] = (somestring, givens, checks) => {
243
+ return new suiteKlasser.prototype.constructor(somestring, index, givens, checks);
244
+ };
245
+ return a;
246
+ }, {});
247
+ const classyGivens = Object.keys(testImplementation.Givens)
248
+ .reduce((a, key) => {
249
+ a[key] = (features, whens, thens, ...xtrasW) => {
250
+ return new givenKlasser.prototype.constructor(key, features, whens, thens, testImplementation.Givens[key](...xtrasW));
251
+ };
252
+ return a;
253
+ }, {});
254
+ const classyWhens = Object.entries(testImplementation.Whens).reduce((a, [key, whEn]) => {
255
+ a[key] = (payload) => {
256
+ return new whenKlasser.prototype.constructor(`${whEn.name}: ${payload && payload.toString()}`, whEn(payload));
257
+ };
258
+ return a;
259
+ }, {});
260
+ const classyThens = Object.entries(testImplementation.Thens).reduce((a, [key, thEn]) => {
261
+ a[key] = (expected, x) => {
262
+ return new thenKlasser.prototype.constructor(`${thEn.name}: ${expected && expected.toString()}`, thEn(expected));
263
+ };
264
+ return a;
265
+ }, {});
266
+ const classyChecks = Object.entries(testImplementation.Checks).reduce((a, [key, z]) => {
267
+ a[key] = (somestring, features, callback) => {
268
+ return new checkKlasser.prototype.constructor(somestring, features, callback, classyWhens, classyThens);
269
+ };
270
+ return a;
271
+ }, {});
272
+ const classyTesteranto = new (class extends TesterantoLevelZero {
273
+ })(input, classySuites, classyGivens, classyWhens, classyThens, classyChecks);
274
+ const suites = testSpecification(
275
+ /* @ts-ignore:next-line */
276
+ classyTesteranto.Suites(), classyTesteranto.Given(), classyTesteranto.When(), classyTesteranto.Then(), classyTesteranto.Check(), logWriter);
277
+ const suiteRunner = (suite) => async (testResourceConfiguration, tLog) => {
278
+ return await suite.run(input, testResourceConfiguration, (fPath, value) => logWriter.testArtiFactoryfileWriter(tLog, (p) => {
279
+ artifacts.push(p);
280
+ })(testResourceConfiguration.fs + "/" + fPath, value), tLog);
281
+ };
282
+ const artifacts = this.artifacts;
283
+ this.testJobs = suites.map((suite) => {
284
+ const runner = suiteRunner(suite);
285
+ return {
286
+ test: suite,
287
+ testResourceRequirement,
288
+ toObj: () => {
289
+ return suite.toObj();
290
+ },
291
+ runner,
292
+ receiveTestResourceConfig: async function (testResourceConfiguration = defaultTestResource) {
293
+ console.log(`testResourceConfiguration ${JSON.stringify(testResourceConfiguration, null, 2)}`);
294
+ await logWriter.mkdirSync(testResourceConfiguration.fs);
295
+ const logFilePath = (`${testResourceConfiguration.fs}/log.txt`);
296
+ const access = await logWriter.createWriteStream(logFilePath);
297
+ const tLog = (...l) => {
298
+ console.log(...l);
299
+ access.write(`${l.toString()}\n`);
300
+ };
301
+ const suiteDone = await runner(testResourceConfiguration, tLog);
302
+ const resultsFilePath = (`${testResourceConfiguration.fs}/results.json`);
303
+ logWriter.writeFileSync(resultsFilePath, JSON.stringify(suiteDone.toObj(), null, 2));
304
+ const logPromise = new Promise((res, rej) => {
305
+ access.on("finish", () => { res(true); });
306
+ });
307
+ access.end();
308
+ const numberOfFailures = Object.keys(suiteDone.givens).filter((k) => {
309
+ // console.log(`suiteDone.givens[k].error`, suiteDone.givens[k].error);
310
+ return suiteDone.givens[k].error;
311
+ }).length;
312
+ console.log(`exiting gracefully with ${numberOfFailures} failures.`);
313
+ return {
314
+ failed: numberOfFailures,
315
+ artifacts,
316
+ logPromise
317
+ };
318
+ },
319
+ };
320
+ });
321
+ }
322
+ }
323
+ ////////////////////////////////////////////////////////////////////////////////////////////////
324
+ export default class TesterantoLevelTwo extends TesterantoLevelOne {
325
+ constructor(input, testSpecification, testImplementation, testInterface, testResourceRequirement = defaultTestResourceRequirement, assertioner, beforeEach, afterEach, afterAll, butThen, andWhen, actionHandler, logWriter) {
326
+ super(testImplementation, testSpecification, input, class extends BaseSuite {
327
+ async setup(s, artifactory) {
328
+ return (testInterface.beforeAll || (async (input, artificer) => input))(s, artifactory, this.testResourceConfiguration);
329
+ }
330
+ test(t) {
331
+ return assertioner(t);
332
+ }
333
+ }, class Given extends BaseGiven {
334
+ constructor(name, features, whens, thens, initialValues) {
335
+ super(name, features, whens, thens);
336
+ this.initialValues = initialValues;
337
+ }
338
+ async givenThat(subject, testResource, artifactory) {
339
+ return beforeEach(subject, this.initialValues, testResource, (fPath, value) =>
340
+ // TODO does not work?
341
+ artifactory(`beforeEach/${fPath}`, value));
342
+ }
343
+ afterEach(store, key, artifactory) {
344
+ return new Promise((res) => res(afterEach(store, key, (fPath, value) => artifactory(`after/${fPath}`, value))));
345
+ }
346
+ afterAll(store, artifactory) {
347
+ return afterAll(store, (fPath, value) =>
348
+ // TODO does not work?
349
+ artifactory(`afterAll4-${this.name}/${fPath}`, value));
350
+ }
351
+ }, class When extends BaseWhen {
352
+ constructor(name, actioner, payload) {
353
+ super(name, (store) => {
354
+ return actionHandler(actioner);
355
+ });
356
+ this.payload = payload;
357
+ }
358
+ async andWhen(store, actioner, testResource) {
359
+ return await andWhen(store, actioner, testResource);
360
+ }
361
+ }, class Then extends BaseThen {
362
+ constructor(name, callback) {
363
+ super(name, callback);
364
+ }
365
+ async butThen(store, testResourceConfiguration) {
366
+ return await butThen(store, this.thenCB, testResourceConfiguration);
367
+ }
368
+ }, class Check extends BaseCheck {
369
+ constructor(name, features, checkCallback, whens, thens, initialValues) {
370
+ super(name, features, checkCallback, whens, thens);
371
+ this.initialValues = initialValues;
372
+ }
373
+ async checkThat(subject, testResourceConfiguration, artifactory) {
374
+ return beforeEach(subject, this.initialValues, testResourceConfiguration, (fPath, value) => artifactory(`before/${fPath}`, value));
375
+ }
376
+ afterEach(store, key, artifactory) {
377
+ return new Promise((res) => res(afterEach(store, key, (fPath, value) =>
378
+ // TODO does not work?
379
+ artifactory(`afterEach2-${this.name}/${fPath}`, value))));
380
+ }
381
+ }, testResourceRequirement, logWriter);
382
+ }
383
+ }