testeranto 0.47.7 → 0.47.8

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.
@@ -6,6 +6,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const core_js_1 = require("./core.js");
7
7
  const core_js_2 = __importDefault(require("./core.js"));
8
8
  const NodeWriter_js_1 = require("./NodeWriter.js");
9
+ const receiveTestResourceConfig = async (t, testresource) => {
10
+ const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(testresource);
11
+ /* @ts-ignore:next-line */
12
+ process.send({
13
+ type: "testeranto:adios",
14
+ data: {
15
+ failed,
16
+ testResourceConfiguration: t.test.testResourceConfiguration,
17
+ results: t.toObj(),
18
+ },
19
+ }, async (err) => {
20
+ if (!err) {
21
+ Promise.all([...artifacts, logPromise]).then(async () => {
22
+ process.exit(await failed ? 1 : 0);
23
+ });
24
+ }
25
+ else {
26
+ console.error(err);
27
+ process.exit(1);
28
+ }
29
+ });
30
+ };
9
31
  exports.default = async (input, testSpecification, testImplementation, testInterface, testResourceRequirement = core_js_1.defaultTestResourceRequirement) => {
10
32
  const mrt = new core_js_2.default(input, testSpecification, testImplementation, testInterface, testResourceRequirement, testInterface.assertioner || (async (t) => t), testInterface.beforeEach || async function (subject, initialValues, testResource) {
11
33
  return subject;
@@ -13,63 +35,32 @@ exports.default = async (input, testSpecification, testImplementation, testInter
13
35
  function (b) {
14
36
  return b;
15
37
  }, NodeWriter_js_1.NodeWriter);
16
- const t = mrt.testJobs[0];
38
+ const tl2 = mrt;
39
+ const t = tl2.testJobs[0];
17
40
  const testResourceArg = process.argv[2] || `{}`;
18
41
  try {
19
42
  const partialTestResource = JSON.parse(testResourceArg);
20
43
  if (testResourceRequirement.ports == 0) {
21
- const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource);
22
- Promise.all([...artifacts, logPromise]).then(async () => {
23
- process.exit(await failed ? 1 : 0);
24
- });
44
+ receiveTestResourceConfig(t, partialTestResource);
25
45
  }
26
46
  else {
27
47
  console.log("test configuration is incomplete", partialTestResource);
28
- if (process.send) {
29
- console.log("requesting test resources via IPC ...", testResourceRequirement);
30
- /* @ts-ignore:next-line */
31
- process.send({
32
- type: "testeranto:hola",
33
- data: {
34
- requirement: Object.assign(Object.assign({}, testResourceRequirement), { name: partialTestResource.name })
35
- },
36
- });
37
- console.log("awaiting test resources via IPC...");
38
- process.on("message", async function (packet) {
39
- console.log("message: ", packet);
40
- const resourcesFromPm2 = packet.data.testResourceConfiguration;
41
- const secondTestResource = Object.assign(Object.assign({ fs: "." }, JSON.parse(JSON.stringify(partialTestResource))), JSON.parse(JSON.stringify(resourcesFromPm2)));
42
- console.log("secondTestResource", secondTestResource);
43
- const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource);
44
- /* @ts-ignore:next-line */
45
- process.send({
46
- type: "testeranto:adios",
47
- data: {
48
- testResourceConfiguration: t.test.testResourceConfiguration,
49
- results: t.toObj(),
50
- },
51
- }, async (err) => {
52
- if (!err) {
53
- Promise.all([...artifacts, logPromise]).then(async () => {
54
- process.exit(await failed ? 1 : 0);
55
- });
56
- }
57
- else {
58
- console.error(err);
59
- process.exit(1);
60
- }
61
- });
62
- });
63
- }
64
- else {
65
- console.log("Pass run-time test resources by STDIN", process.stdin);
66
- process.stdin.on("data", async (data) => {
67
- console.log("data: ", data);
68
- const resourcesFromStdin = JSON.parse(data.toString());
69
- const secondTestResource = Object.assign(Object.assign({}, JSON.parse(JSON.stringify(resourcesFromStdin))), JSON.parse(JSON.stringify(partialTestResource)));
70
- await t.receiveTestResourceConfig(secondTestResource);
71
- });
72
- }
48
+ console.log("requesting test resources via IPC ...", testResourceRequirement);
49
+ /* @ts-ignore:next-line */
50
+ process.send({
51
+ type: "testeranto:hola",
52
+ data: {
53
+ requirement: Object.assign(Object.assign({}, testResourceRequirement), { name: partialTestResource.name })
54
+ },
55
+ });
56
+ console.log("awaiting test resources via IPC...");
57
+ process.on("message", async function (packet) {
58
+ console.log("message: ", packet);
59
+ const resourcesFromPm2 = packet.data.testResourceConfiguration;
60
+ const secondTestResource = Object.assign(Object.assign({ fs: "." }, JSON.parse(JSON.stringify(partialTestResource))), JSON.parse(JSON.stringify(resourcesFromPm2)));
61
+ console.log("secondTestResource", secondTestResource);
62
+ receiveTestResourceConfig(t, secondTestResource);
63
+ });
73
64
  }
74
65
  }
75
66
  catch (e) {
@@ -77,3 +68,15 @@ exports.default = async (input, testSpecification, testImplementation, testInter
77
68
  process.exit(-1);
78
69
  }
79
70
  };
71
+ // else {
72
+ // console.log("Pass run-time test resources by STDIN", process.stdin);
73
+ // process.stdin.on("data", async (data) => {
74
+ // console.log("data: ", data);
75
+ // const resourcesFromStdin = JSON.parse(data.toString());
76
+ // const secondTestResource = {
77
+ // ...JSON.parse(JSON.stringify(resourcesFromStdin)),
78
+ // ...JSON.parse(JSON.stringify(partialTestResource)),
79
+ // } as ITTestResourceConfiguration;
80
+ // await t.receiveTestResourceConfig(secondTestResource);
81
+ // });
82
+ // }
@@ -71,7 +71,14 @@ class ITProject {
71
71
  pm2_1.default.list((err, procs) => {
72
72
  procs.forEach((proc) => {
73
73
  var _a, _b;
74
- procsTable.push({ name: proc.name, pid: proc.pid, pm_id: proc.pm_id, mem: (_a = proc.monit) === null || _a === void 0 ? void 0 : _a.memory, cpu: (_b = proc.monit) === null || _b === void 0 ? void 0 : _b.cpu });
74
+ procsTable.push({
75
+ name: proc.name,
76
+ pid: proc.pid,
77
+ pm_id: proc.pm_id,
78
+ mem: (_a = proc.monit) === null || _a === void 0 ? void 0 : _a.memory,
79
+ cpu: (_b = proc.monit) === null || _b === void 0 ? void 0 : _b.cpu,
80
+ "exit code": this.exitCodes[proc.name]
81
+ });
75
82
  });
76
83
  console.table(procsTable);
77
84
  console.table(this.resourceQueue);
@@ -203,6 +210,7 @@ class ITProject {
203
210
  setup(build) {
204
211
  build.onEnd(result => {
205
212
  console.log(`node build ended with ${result.errors.length} errors`);
213
+ result.errors.length !== 0 && process.exit(-1);
206
214
  // HERE: somehow restart the server from here, e.g., by sending a signal that you trap and react to inside the server.
207
215
  });
208
216
  }
@@ -219,7 +227,8 @@ class ITProject {
219
227
  react: path_1.default.resolve("./node_modules/react")
220
228
  },
221
229
  external: [
222
- // "url", "path", "fs",
230
+ // "url",
231
+ "path", "fs",
223
232
  // "react",
224
233
  "stream",
225
234
  "tests.test.js", "features.test.js"
@@ -248,6 +257,7 @@ class ITProject {
248
257
  setup(build) {
249
258
  build.onEnd(result => {
250
259
  console.log(`web build ended with ${result.errors.length} errors`);
260
+ result.errors.length !== 0 && process.exit(-1);
251
261
  // HERE: somehow restart the server from here, e.g., by sending a signal that you trap and react to inside the server.
252
262
  });
253
263
  }
@@ -345,7 +355,7 @@ class ITProject {
345
355
  }
346
356
  else if (messageType === "testeranto:adios") {
347
357
  console.log("adios WS", name);
348
- this.releaseTestResources(name);
358
+ this.releaseTestResources(payload);
349
359
  }
350
360
  });
351
361
  });
@@ -375,9 +385,9 @@ class ITProject {
375
385
  console.log("hola IPC", packet);
376
386
  this.requestResource(packet.data.requirement, 'ipc');
377
387
  });
378
- pm2_bus.on("testeranto:adios", (packet) => {
379
- console.log("adios IPC", packet);
380
- this.releaseTestResources(packet.data.name);
388
+ pm2_bus.on("testeranto:adios", (payload) => {
389
+ console.log("adios IPC", payload);
390
+ this.releaseTestResources(payload.data);
381
391
  });
382
392
  });
383
393
  this
@@ -432,6 +442,7 @@ class ITProject {
432
442
  }
433
443
  });
434
444
  }
445
+ this.exitCodes[inputFilePath] = null;
435
446
  return [inputFilePath, ...m];
436
447
  }, []);
437
448
  setInterval(this.mainLoop, TIMEOUT).unref();
@@ -470,7 +481,11 @@ class ITProject {
470
481
  this.spinCycle = (this.spinCycle + 1) % this.spinAnimation.length;
471
482
  return this.spinAnimation[this.spinCycle];
472
483
  }
473
- async releaseTestResources(name) {
484
+ async releaseTestResources(payload) {
485
+ const name = payload.testResourceConfiguration.name;
486
+ const failed = payload.failed;
487
+ console.log("releaseTestResources", name, failed);
488
+ // reset ports
474
489
  pm2_1.default.list((err, processes) => {
475
490
  processes.forEach((proc) => {
476
491
  if (proc.name === name) {
@@ -482,6 +497,7 @@ class ITProject {
482
497
  }
483
498
  });
484
499
  });
500
+ this.exitCodes[name] = failed;
485
501
  }
486
502
  allocateViaWs(resourceRequest) {
487
503
  const pName = resourceRequest.requirement.name;
@@ -5,7 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const core_1 = require("./core");
7
7
  const core_2 = __importDefault(require("./core"));
8
+ const electron_1 = require("electron");
8
9
  const webSocket = new WebSocket("ws://localhost:8080");
10
+ const receiveTestResourceConfig = async (t, testresource) => {
11
+ const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(testresource);
12
+ webSocket.send(JSON.stringify({
13
+ type: "testeranto:adios",
14
+ failed,
15
+ data: {
16
+ testResourceConfiguration: t.test.testResourceConfiguration,
17
+ results: t.toObj(),
18
+ },
19
+ }));
20
+ Promise.all([...artifacts, logPromise]).then(async () => {
21
+ electron_1.ipcRenderer.invoke('quit-app', failed);
22
+ });
23
+ };
9
24
  exports.default = async (input, testSpecification, testImplementation, testInterface, testResourceRequirement = core_1.defaultTestResourceRequirement) => {
10
25
  const mrt = new core_2.default(input, testSpecification, testImplementation, testInterface, testResourceRequirement, testInterface.assertioner || (async (t) => t), testInterface.beforeEach ||
11
26
  async function (subject, initialValues, testResource) {
@@ -20,13 +35,7 @@ exports.default = async (input, testSpecification, testImplementation, testInter
20
35
  try {
21
36
  const partialTestResource = JSON.parse(testResourceArg);
22
37
  if (partialTestResource.fs && partialTestResource.ports) {
23
- // const failed = await t.receiveTestResourceConfig(partialTestResource);
24
- // (window as any).exit(failed)
25
- const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource);
26
- Promise.all([...artifacts, logPromise]).then(async () => {
27
- // process.exit(await failed ? 1 : 0);
28
- window.exit(failed);
29
- });
38
+ receiveTestResourceConfig(t, partialTestResource);
30
39
  }
31
40
  else {
32
41
  console.log("test configuration is incomplete", partialTestResource);
@@ -48,21 +57,7 @@ exports.default = async (input, testSpecification, testImplementation, testInter
48
57
  const resourcesFromPm2 = msg.data.testResourceConfiguration;
49
58
  const secondTestResource = Object.assign(Object.assign({ fs: "." }, JSON.parse(JSON.stringify(partialTestResource))), JSON.parse(JSON.stringify(resourcesFromPm2)));
50
59
  console.log("secondTestResource", secondTestResource);
51
- const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource);
52
- Promise.all([...artifacts, logPromise]).then(async () => {
53
- // process.exit(await failed ? 1 : 0);
54
- window.exit(failed);
55
- });
56
- webSocket.send(JSON.stringify({
57
- type: "testeranto:adios",
58
- data: {
59
- testResourceConfiguration: t.test.testResourceConfiguration,
60
- results: t.toObj(),
61
- },
62
- }));
63
- document.write("all done");
64
- // app.exit(failed ? 1 : 0);
65
- // process.exit(failed ? 1 : 0);
60
+ receiveTestResourceConfig(t, secondTestResource);
66
61
  });
67
62
  });
68
63
  }