testeranto 0.73.0 → 0.75.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.
@@ -5,18 +5,11 @@ class NodeTesteranto extends Testeranto {
5
5
  constructor(input, testSpecification, testImplementation, testResourceRequirement, testInterface) {
6
6
  super(input, testSpecification, testImplementation, testResourceRequirement, testInterface);
7
7
  }
8
- async receiveTestResourceConfig(
9
- // t: ITestJob,
10
- partialTestResource) {
11
- console.log("receiveTestResourceConfig!!", this.testJobs[0].receiveTestResourceConfig);
8
+ async receiveTestResourceConfig(partialTestResource) {
12
9
  const t = JSON.parse(partialTestResource);
13
10
  const pm = new PM_Node(t);
14
11
  const { failed, artifacts, logPromise } = await this.testJobs[0].receiveTestResourceConfig(pm);
15
- console.log("test is done, awaiting test result write to fs");
16
12
  pm.customclose();
17
- // Promise.all([...artifacts, logPromise]).then(async () => {
18
- // // process.exit((await failed) ? 1 : 0);
19
- // });
20
13
  }
21
14
  }
22
15
  export default async (input, testSpecification, testImplementation, testInterface, testResourceRequirement = defaultTestResourceRequirement) => {
@@ -4,17 +4,13 @@ import puppeteer from "puppeteer-core";
4
4
  import { PM } from "./index.js";
5
5
  const fPaths = [];
6
6
  const fileStreams3 = [];
7
- const screenshots3 = [];
8
- const doneFileStream3 = [];
7
+ const files = {}; // = new Set<string>();
8
+ const screenshots = {};
9
9
  export class PM_Main extends PM {
10
- // testResourceConfiguration: ITTestResourceConfiguration;
11
- constructor(configs
12
- // testResourceConfig: ITTestResourceConfiguration
13
- ) {
10
+ constructor(configs) {
14
11
  super();
15
12
  this.launchNode = async (src, dest) => {
16
13
  console.log("launchNode", src);
17
- // childProcesses[src] = "running";
18
14
  const destFolder = dest.replace(".mjs", "");
19
15
  let argz = "";
20
16
  const testConfig = this.configs.tests.find((t) => {
@@ -25,7 +21,6 @@ export class PM_Main extends PM {
25
21
  process.exit(-1);
26
22
  }
27
23
  const testConfigResource = testConfig[2];
28
- console.log("mark22 testConfigResource", testConfigResource);
29
24
  let portsToUse = [];
30
25
  if (testConfigResource.ports === 0) {
31
26
  argz = JSON.stringify({
@@ -81,8 +76,6 @@ export class PM_Main extends PM {
81
76
  };
82
77
  this.launchWeb = (t, dest) => {
83
78
  console.log("launchWeb", t, dest);
84
- const testResourceConfiguration = this.testResourceConfiguration;
85
- // childProcesses[t] = "running";
86
79
  const destFolder = dest.replace(".mjs", "");
87
80
  const webArgz = JSON.stringify({
88
81
  name: dest,
@@ -99,54 +92,49 @@ export class PM_Main extends PM {
99
92
  }
100
93
  })`;
101
94
  const fileStreams2 = [];
102
- const screenshots2 = [];
95
+ // const screenshots2: Promise<any>[] = [];
103
96
  const doneFileStream2 = [];
104
97
  this.browser
105
98
  .newPage()
106
99
  .then((page) => {
107
- page.exposeFunction("custom-screenshot", async (ssOpts) => {
100
+ page.exposeFunction("custom-screenshot", async (ssOpts, testName) => {
101
+ console.log("main.ts browser custom-screenshot", testName);
108
102
  const p = ssOpts.path;
109
- console.log("custom-screenshot", ssOpts);
110
103
  const dir = path.dirname(p);
111
- console.log("dir", dir);
112
104
  fs.mkdirSync(dir, {
113
105
  recursive: true,
114
106
  });
115
- return page.screenshot(Object.assign(Object.assign({}, ssOpts), { path: p }));
116
- // screenshots.push(
117
- // page.screenshot({
118
- // ...ssOpts,
119
- // path: ssOpts.path,
120
- // })
121
- // );
122
- // const sPromise = page.screenshot({
123
- // ...ssOpts,
124
- // path: p,
125
- // });
126
- // await sPromise;
107
+ files[testName].add(ssOpts.path);
108
+ const sPromise = page.screenshot(Object.assign(Object.assign({}, ssOpts), { path: p }));
109
+ if (!screenshots[testName]) {
110
+ screenshots[testName] = [];
111
+ }
112
+ screenshots[testName].push(sPromise);
113
+ // sPromise.then(())
114
+ await sPromise;
115
+ return sPromise;
127
116
  // page.evaluate(`window["screenshot done"]`);
128
117
  });
129
- page.exposeFunction("writeFileSync", (fp, contents) => {
130
- console.log("writeFileSync", fp);
131
- // Create directories if they don't exist
118
+ page.exposeFunction("writeFileSync", (fp, contents, testName) => {
132
119
  const dir = path.dirname(fp);
133
- console.log("dir", dir);
134
120
  fs.mkdirSync(dir, {
135
121
  recursive: true,
136
122
  });
137
- // return fs.writeFileSync(fp, contents);
138
123
  const p = new Promise(async (res, rej) => {
139
124
  fs.writeFileSync(fp, contents);
140
125
  res(fp);
141
126
  });
142
127
  doneFileStream2.push(p);
128
+ if (!files[testName]) {
129
+ files[testName] = new Set();
130
+ }
131
+ files[testName].add(fp);
143
132
  return p;
144
133
  });
145
134
  page.exposeFunction("existsSync", (fp, contents) => {
146
135
  return fs.existsSync(fp);
147
136
  });
148
137
  page.exposeFunction("mkdirSync", (fp) => {
149
- console.log("mkdirsync", fp);
150
138
  if (!fs.existsSync(fp)) {
151
139
  return fs.mkdirSync(fp, {
152
140
  recursive: true,
@@ -154,8 +142,12 @@ export class PM_Main extends PM {
154
142
  }
155
143
  return false;
156
144
  });
157
- page.exposeFunction("createWriteStream", (fp) => {
145
+ page.exposeFunction("createWriteStream", (fp, testName) => {
158
146
  const f = fs.createWriteStream(fp);
147
+ if (!files[testName]) {
148
+ files[testName] = new Set();
149
+ }
150
+ files[testName].add(fp);
159
151
  const p = new Promise((res, rej) => {
160
152
  res(fp);
161
153
  });
@@ -172,13 +164,23 @@ export class PM_Main extends PM {
172
164
  page.exposeFunction("end", async (uid) => {
173
165
  return fileStreams2[uid].end();
174
166
  });
175
- page.exposeFunction("customclose", () => {
176
- console.log("closing doneFileStream2", doneFileStream2);
177
- // console.log("closing doneFileStream2", doneFileStream2);
178
- Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
167
+ page.exposeFunction("customclose", (p, testName) => {
168
+ fs.writeFileSync(p + "/manifest.json", JSON.stringify(Array.from(files[testName])));
169
+ delete files[testName];
170
+ Promise.all(screenshots[testName] || []).then(() => {
171
+ delete screenshots[testName];
179
172
  page.close();
180
173
  });
181
- // page.close();
174
+ // globalThis["writeFileSync"](
175
+ // p + "/manifest.json",
176
+ // // files.entries()
177
+ // JSON.stringify(Array.from(files[testName]))
178
+ // );
179
+ // console.log("closing doneFileStream2", doneFileStream2);
180
+ // console.log("closing doneFileStream2", doneFileStream2);
181
+ // Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
182
+ // page.close();
183
+ // });
182
184
  // Promise.all(screenshots).then(() => {
183
185
  // page.close();
184
186
  // });
@@ -191,22 +193,13 @@ export class PM_Main extends PM {
191
193
  return page;
192
194
  })
193
195
  .then(async (page) => {
194
- await page.goto(`file://${`${dest}.html`}`, {
195
- // waitUntil: "load",
196
- // timeout: 0,
197
- });
196
+ await page.goto(`file://${`${dest}.html`}`, {});
198
197
  page.evaluate(evaluation).finally(() => {
199
198
  console.log("evaluation failed.", dest);
200
199
  });
201
200
  return page;
202
- })
203
- .then((page) => {
204
- // console.log("qwe", page);
205
- // page.close();
206
201
  });
207
202
  };
208
- // this.testResourceConfiguration = testResourceConfig;
209
- // console.log("mkdirsync4", testResourceConfig);
210
203
  this.server = {};
211
204
  this.configs = configs;
212
205
  this.ports = {};
@@ -221,29 +214,45 @@ export class PM_Main extends PM {
221
214
  }
222
215
  return false;
223
216
  };
224
- globalThis["writeFileSync"] = (fp, contents) => {
217
+ globalThis["writeFileSync"] = (filepath, contents, testName) => {
225
218
  // Create directories if they don't exist
226
- const dir = path.dirname(fp.split("/").slice(0, -1).join("/"));
227
- console.log("dir", dir);
219
+ const dir = path.dirname(filepath.split("/").slice(0, -1).join("/"));
228
220
  fs.mkdirSync(dir, {
229
221
  recursive: true,
230
222
  });
231
- return fs.writeFileSync(fp, contents);
223
+ if (!files[testName]) {
224
+ files[testName] = new Set();
225
+ }
226
+ files[testName].add(filepath);
227
+ return fs.writeFileSync(filepath, contents);
232
228
  };
233
- globalThis["createWriteStream"] = (filepath) => {
229
+ globalThis["createWriteStream"] = (filepath, testName) => {
234
230
  const f = fs.createWriteStream(filepath);
235
231
  fileStreams3.push(f);
232
+ // files.add(filepath);
233
+ if (!files[testName]) {
234
+ files[testName] = new Set();
235
+ }
236
+ files[testName].add(filepath);
236
237
  return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(f))), { uid: fileStreams3.length - 1 });
237
238
  };
238
239
  globalThis["write"] = (uid, contents) => {
239
- console.log("write", uid, contents);
240
- // process.exit();
241
240
  fileStreams3[uid].write(contents);
242
241
  };
243
242
  globalThis["end"] = (uid) => {
244
243
  fileStreams3[uid].end();
245
244
  };
246
- globalThis["customclose"] = () => {
245
+ globalThis["customclose"] = (p, testName) => {
246
+ if (!files[testName]) {
247
+ files[testName] = new Set();
248
+ }
249
+ fs.writeFileSync(p + "/manifest.json", JSON.stringify(Array.from(files[testName])));
250
+ delete files[testName];
251
+ // globalThis["writeFileSync"](
252
+ // p + "/manifest.json",
253
+ // // files.entries()
254
+ // JSON.stringify(Array.from(files[testName]))
255
+ // );
247
256
  // fileStreams3[uid].end();
248
257
  };
249
258
  // page.exposeFunction("customclose", () => {
@@ -1,54 +1,8 @@
1
- // import puppeteer from "puppeteer";
2
1
  import fs from "fs";
3
2
  import path from "path";
4
- // import puppeteer from "puppeteer-core/lib/esm/puppeteer/puppeteer-core";
5
3
  import puppeteer from "puppeteer-core";
6
4
  import { PM } from "./index.js";
7
5
  const fPaths = [];
8
- export function addPageBinding(type, name, prefix) {
9
- // Depending on the frame loading state either Runtime.evaluate or
10
- // Page.addScriptToEvaluateOnNewDocument might succeed. Let's check that we
11
- // don't re-wrap Puppeteer's binding.
12
- if (globalThis[name]) {
13
- return;
14
- }
15
- // We replace the CDP binding with a Puppeteer binding.
16
- Object.assign(globalThis, {
17
- [name](...args) {
18
- var _a, _b, _c;
19
- // This is the Puppeteer binding.
20
- const callPuppeteer = globalThis[name];
21
- (_a = callPuppeteer.args) !== null && _a !== void 0 ? _a : (callPuppeteer.args = new Map());
22
- (_b = callPuppeteer.callbacks) !== null && _b !== void 0 ? _b : (callPuppeteer.callbacks = new Map());
23
- const seq = ((_c = callPuppeteer.lastSeq) !== null && _c !== void 0 ? _c : 0) + 1;
24
- callPuppeteer.lastSeq = seq;
25
- callPuppeteer.args.set(seq, args);
26
- // Needs to be the same as CDP_BINDING_PREFIX.
27
- globalThis[prefix + name](JSON.stringify({
28
- type,
29
- name,
30
- seq,
31
- args,
32
- isTrivial: !args.some((value) => {
33
- return value instanceof Node;
34
- }),
35
- }));
36
- return new Promise((resolve, reject) => {
37
- callPuppeteer.callbacks.set(seq, {
38
- resolve(value) {
39
- callPuppeteer.args.delete(seq);
40
- resolve(value);
41
- },
42
- reject(value) {
43
- callPuppeteer.args.delete(seq);
44
- reject(value);
45
- },
46
- });
47
- });
48
- },
49
- });
50
- }
51
- const files = new Set();
52
6
  export class PM_Node extends PM {
53
7
  constructor(t) {
54
8
  super();
@@ -65,44 +19,17 @@ export class PM_Node extends PM {
65
19
  return globalThis["write"](writeObject.uid, contents);
66
20
  }
67
21
  writeFileSync(filepath, contents) {
68
- files.add(filepath);
69
- return globalThis["writeFileSync"](this.testResourceConfiguration.fs + "/" + filepath, contents);
22
+ return globalThis["writeFileSync"](this.testResourceConfiguration.fs + "/" + filepath, contents, this.testResourceConfiguration.name);
70
23
  }
71
24
  createWriteStream(filepath) {
72
- files.add(filepath);
73
- return globalThis["createWriteStream"](this.testResourceConfiguration.fs + "/" + filepath);
25
+ return globalThis["createWriteStream"](this.testResourceConfiguration.fs + "/" + filepath, this.testResourceConfiguration.name);
74
26
  }
75
27
  end(writeObject) {
76
28
  return globalThis["end"](writeObject.uid);
77
29
  }
78
30
  customclose() {
79
- console.log("node-customclose");
80
- // globalThis["writeFileSync"](
81
- // this.testResourceConfiguration.fs + "/manifest.json",
82
- // // files.entries()
83
- // JSON.stringify(Array.from(files))
84
- // ).then(() => {
85
- // globalThis["customclose"]();
86
- // });
31
+ globalThis["customclose"](this.testResourceConfiguration.fs, this.testResourceConfiguration.name);
87
32
  }
88
- // write(accessObject: { uid: number; }, contents: string): boolean {
89
- // throw new Error("Method not implemented.");
90
- // }
91
- // existsSync(destFolder: string): boolean {
92
- // return fs.existsSync(destFolder);
93
- // }
94
- // async mkdirSync(destFolder: string) {
95
- // if (!fs.existsSync(destFolder)) {
96
- // return fs.mkdirSync(destFolder, { recursive: true });
97
- // }
98
- // return false;
99
- // }
100
- // writeFileSync(fp: string, contents: string) {
101
- // fs.writeFileSync(fp, contents);
102
- // }
103
- // createWriteStream(filepath: string): fs.WriteStream {
104
- // return fs.createWriteStream(filepath);
105
- // }
106
33
  testArtiFactoryfileWriter(tLog, callback) {
107
34
  return (fPath, value) => {
108
35
  callback(new Promise((res, rej) => {
@@ -143,26 +70,8 @@ export class PM_Node extends PM {
143
70
  }
144
71
  // launch(options?: PuppeteerLaunchOptions): Promise<Browser>;
145
72
  startPuppeteer(options) {
146
- console.log("start1");
147
73
  return puppeteer.connect(options).then((b) => {
148
74
  this.browser = b;
149
75
  });
150
- // return new Promise<Browser>((res, rej) => {
151
- // // this.browser = await puppeteer.connect(options);
152
- // // console.log("start2", this.browser);
153
- // // console.log("mark5", this.browser);
154
- // // res(this.browser);
155
- // });
156
76
  }
157
77
  }
158
- // class PuppetMasterServer extends AbstractPuppetMaster {
159
- // // constructor(...z: []) {
160
- // // super(...z);
161
- // // }
162
- // // // pages(): Promise<Page[]>;
163
- // // pages(): Promise<Page[]> {
164
- // // return new Promise<Page[]>((res, rej) => {
165
- // // res(super.pages());
166
- // // });
167
- // // }
168
- // }
@@ -1,17 +1,6 @@
1
- import { PM } from "./index.js";
2
1
  import puppeteer from "puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js";
3
- function waitForFunctionCall() {
4
- return new Promise((resolve) => {
5
- window["myFunction"] = () => {
6
- // Do something when myFunction is called
7
- console.log("myFunction was called!");
8
- resolve(); // Resolve the promise
9
- };
10
- });
11
- }
12
- const files = new Set();
2
+ import { PM } from "./index.js";
13
3
  export class PM_Web extends PM {
14
- // testResourceConfiguration: ITTestResourceConfiguration;
15
4
  constructor(t) {
16
5
  super();
17
6
  this.server = {};
@@ -27,23 +16,16 @@ export class PM_Web extends PM {
27
16
  return window["write"](writeObject.uid, contents);
28
17
  }
29
18
  writeFileSync(filepath, contents) {
30
- console.log("WEB writeFileSync", filepath);
31
- files.add(filepath);
32
- return window["writeFileSync"](this.testResourceConfiguration.fs + "/" + filepath, contents);
19
+ return window["writeFileSync"](this.testResourceConfiguration.fs + "/" + filepath, contents, this.testResourceConfiguration.name);
33
20
  }
34
21
  createWriteStream(filepath) {
35
- files.add(filepath);
36
- return window["createWriteStream"](this.testResourceConfiguration.fs + "/" + filepath);
22
+ return window["createWriteStream"](this.testResourceConfiguration.fs + "/" + filepath, this.testResourceConfiguration.name);
37
23
  }
38
24
  end(writeObject) {
39
25
  return window["end"](writeObject.uid);
40
26
  }
41
27
  customclose() {
42
- window["writeFileSync"](this.testResourceConfiguration.fs + "/manifest.json",
43
- // files.entries()
44
- JSON.stringify(Array.from(files))).then(() => {
45
- window["customclose"]();
46
- });
28
+ window["customclose"](this.testResourceConfiguration.fs, this.testResourceConfiguration.name);
47
29
  }
48
30
  testArtiFactoryfileWriter(tLog, callback) {
49
31
  return (fPath, value) => {
@@ -89,12 +71,12 @@ export class PM_Web extends PM {
89
71
  };
90
72
  }
91
73
  startPuppeteer(options, destFolder) {
74
+ const name = this.testResourceConfiguration.name;
92
75
  return fetch(`http://localhost:3234/json/version`)
93
76
  .then((v) => {
94
77
  return v.json();
95
78
  })
96
79
  .then((json) => {
97
- console.log("found endpoint", json.webSocketDebuggerUrl);
98
80
  return puppeteer
99
81
  .connect({
100
82
  browserWSEndpoint: json.webSocketDebuggerUrl,
@@ -105,10 +87,9 @@ export class PM_Web extends PM {
105
87
  get(target, prop, receiver) {
106
88
  if (prop === "screenshot") {
107
89
  return async (x) => {
108
- // debugger;
109
- files.add(x.path);
110
- console.log("aloha", files);
111
- return await window["custom-screenshot"](Object.assign(Object.assign({}, x), { path: destFolder + "/" + x.path }));
90
+ return await window["custom-screenshot"](Object.assign(Object.assign({}, x), {
91
+ // path: destFolder + "/" + x.path,
92
+ path: x.path }), name);
112
93
  };
113
94
  }
114
95
  else if (prop === "mainFrame") {
@@ -137,31 +118,5 @@ export class PM_Web extends PM {
137
118
  this.browser = proxy3;
138
119
  });
139
120
  });
140
- // console.log("connecting to ws://localhost:3234/devtools/browser/RANDOM");
141
- // return puppeteer
142
- // .connect({
143
- // ...options,
144
- // })
145
- // .finally(() => {
146
- // console.log("idk");
147
- // });
148
- // return new Promise<Browser>(async (res, rej) => {
149
- // console.log("connecting with options", options);
150
- // this.browser = await puppeteer.connect({
151
- // ...options,
152
- // });
153
- // res(this.browser);
154
- // });
155
121
  }
156
122
  }
157
- // class PuppetMasterServer extends AbstractPuppetMaster {
158
- // // constructor(...z: []) {
159
- // // super(...z);
160
- // // }
161
- // // // pages(): Promise<Page[]>;
162
- // // pages(): Promise<Page[]> {
163
- // // return new Promise<Page[]>((res, rej) => {
164
- // // res(super.pages());
165
- // // });
166
- // // }
167
- // }
@@ -1,7 +1,16 @@
1
+ import React from "react";
1
2
  export const testInterface = {
2
- beforeEach: async (x, ndx, testRsource, artificer) => {
3
+ // beforeAll: async (proto, testResource, artificer, pm): Promise<IStore> => {
4
+ // return React.createElement(proto);
5
+ // // return new Promise((resolve, rej) => {
6
+ // // resolve(x());
7
+ // // });
8
+ // },
9
+ beforeEach: async (subject, initializer, artificer) => {
3
10
  return new Promise((resolve, rej) => {
4
- resolve(x());
11
+ const x = React.createElement(subject);
12
+ console.log("react-element", x);
13
+ resolve(x);
5
14
  });
6
15
  },
7
16
  andWhen: function (s, whenCB) {
@@ -9,7 +9,6 @@ class WebTesteranto extends Testeranto {
9
9
  const t = partialTestResource; //JSON.parse(partialTestResource);
10
10
  const pm = new PM_Web(t);
11
11
  const { failed, artifacts, logPromise } = await this.testJobs[0].receiveTestResourceConfig(pm);
12
- console.log("test is done, awaiting test result write to fs");
13
12
  pm.customclose();
14
13
  // Promise.all([...artifacts, logPromise]).then(async () => {
15
14
  // console.log("hello world");
@@ -214,7 +214,7 @@ export class BaseGiven {
214
214
  // "custom-screenshot-MARK-afterEachProxy",
215
215
  // window["custom-screenshot"].toString()
216
216
  // );
217
- return await window["custom-screenshot"](Object.assign(Object.assign({}, x), { path: `${testResourceConfiguration.fs}/suite-${suiteNdx}/given-${key}/afterEach` +
217
+ return await pTarget[pProp](Object.assign(Object.assign({}, x), { path: `${testResourceConfiguration.fs}/suite-${suiteNdx}/given-${key}/afterEach` +
218
218
  "/" +
219
219
  x.path }));
220
220
  };