testeranto 0.47.34 → 0.48.1

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.
package/src/Project.ts CHANGED
@@ -1,19 +1,17 @@
1
- import WebSocket, { WebSocketServer } from 'ws';
2
1
  import esbuild, { BuildOptions } from "esbuild";
3
2
  import fs from "fs";
4
- import path from "path";
5
3
  import fsExists from "fs.promises.exists";
4
+ import path from "path";
6
5
  import pm2 from "pm2";
7
6
  import readline from 'readline';
7
+ import WebSocket, { WebSocketServer } from 'ws';
8
8
 
9
9
  import { TesterantoFeatures } from "./Features";
10
10
  import { IBaseConfig, IRunTime, ITestTypes } from "./Types";
11
11
  import { ITTestResourceRequirement } from './core';
12
12
 
13
13
  readline.emitKeypressEvents(process.stdin);
14
-
15
- if (process.stdin.isTTY)
16
- process.stdin.setRawMode(true);
14
+ if (process.stdin.isTTY) process.stdin.setRawMode(true);
17
15
 
18
16
  const TIMEOUT = 2000;
19
17
  const OPEN_PORT = "";
@@ -90,6 +88,7 @@ export class ITProject {
90
88
  this.clearScreen = config.clearScreen;
91
89
  this.devMode = config.devMode;
92
90
 
91
+ // mark each port as open
93
92
  Object.values(config.ports).forEach((port) => {
94
93
  this.ports[port] = OPEN_PORT;
95
94
  });
@@ -97,10 +96,6 @@ export class ITProject {
97
96
  const testPath = `${process.cwd()}/${config.tests}`;
98
97
  const featurePath = `${process.cwd()}/${config.features}`;
99
98
 
100
- process.on('SIGINT', () => this.initiateShutdown("CTRL+C"));
101
- process.on('SIGQUIT', () => this.initiateShutdown("Keyboard quit"));
102
- process.on('SIGTERM', () => this.initiateShutdown("'kill' command"));
103
-
104
99
  process.stdin.on('keypress', (str, key) => {
105
100
  if (key.name === 'q') {
106
101
  this.initiateShutdown("'q' command")
@@ -162,14 +157,13 @@ export class ITProject {
162
157
  js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
163
158
  },
164
159
  target: "esnext",
165
-
166
- // packages: "external",
167
160
  format: "esm",
168
161
  splitting: true,
169
162
  outExtension: { '.js': '.mjs' },
170
163
  platform: "node",
171
-
172
- external: ["tests.test.js", "features.test.js", "react"],
164
+ external: [
165
+ "tests.test.js",
166
+ "features.test.js", "react"],
173
167
 
174
168
  outbase: config.outbase,
175
169
  outdir: config.outdir,
@@ -184,7 +178,7 @@ export class ITProject {
184
178
  '.jpg': 'binary',
185
179
  },
186
180
  plugins: [
187
- ...(config.plugins || []),
181
+ ...(config.nodePlugins || []),
188
182
  {
189
183
  name: 'rebuild-notify',
190
184
  setup(build) {
@@ -192,14 +186,12 @@ export class ITProject {
192
186
  console.log(`node build ended with ${result.errors.length} errors`);
193
187
  console.log(result)
194
188
  result.errors.length !== 0 && process.exit(-1);
195
- // HERE: somehow restart the server from here, e.g., by sending a signal that you trap and react to inside the server.
196
189
  })
197
190
  }
198
191
  },
199
192
  ],
200
193
  };
201
194
  const esbuildConfigWeb: BuildOptions = {
202
- // packages: "external",
203
195
  target: "esnext",
204
196
  format: "esm",
205
197
  splitting: true,
@@ -210,13 +202,15 @@ export class ITProject {
210
202
  },
211
203
 
212
204
  external: [
205
+ "tests.test.js",
206
+ "features.test.js",
213
207
  // "url",
208
+ // "react",
214
209
  "electron",
215
210
  "path",
216
211
  "fs",
217
- // "react",
218
212
  "stream",
219
- "tests.test.js", "features.test.js"],
213
+ ],
220
214
  platform: "browser",
221
215
 
222
216
  outbase: config.outbase,
@@ -237,8 +231,7 @@ export class ITProject {
237
231
  '.jpg': 'binary',
238
232
  },
239
233
  plugins: [
240
- ...(config.plugins || []),
241
-
234
+ ...(config.webPlugins || []),
242
235
  {
243
236
  name: 'rebuild-notify',
244
237
  setup(build) {
@@ -246,7 +239,6 @@ export class ITProject {
246
239
  console.log(`web build ended with ${result.errors.length} errors`);
247
240
  console.log(result)
248
241
  result.errors.length !== 0 && process.exit(-1);
249
- // HERE: somehow restart the server from here, e.g., by sending a signal that you trap and react to inside the server.
250
242
  })
251
243
  }
252
244
  },
@@ -298,24 +290,33 @@ export class ITProject {
298
290
  `)
299
291
 
300
292
  Promise.all([
301
- esbuild.context(esbuildConfigNode).then(async (nodeContext) => {
302
- await nodeContext.watch();
303
- }),
304
- esbuild.context(esbuildConfigWeb).then(async (esbuildWeb) => {
305
- await esbuildWeb.watch();
306
- })
293
+ esbuild.context(esbuildConfigNode)
294
+ .then(async (nodeContext) => {
295
+ await nodeContext.watch();
296
+ }),
297
+
298
+ esbuild.context(esbuildConfigWeb)
299
+ .then(async (esbuildWeb) => {
300
+ await esbuildWeb.watch();
301
+ })
302
+
307
303
  ]).then(() => {
304
+
308
305
  if (config.devMode === false) {
309
306
  console.log("Your tests were built but not run because devMode was false. Exiting gracefully");
310
307
  process.exit(0);
308
+
311
309
  } else {
310
+
312
311
  pm2.connect(async (err) => {
312
+
313
313
  if (err) {
314
314
  console.error(err);
315
315
  process.exit(-1);
316
316
  } else {
317
317
  console.log(`pm2 is connected`);
318
318
  }
319
+
319
320
  // run a websocket as an alternative to node IPC
320
321
  webSocketServer = new WebSocketServer({
321
322
  port: 8080,
@@ -324,36 +325,19 @@ export class ITProject {
324
325
 
325
326
  webSocketServer.on('open', () => {
326
327
  console.log('open');
327
- // process.exit()
328
328
  });
329
329
 
330
330
  webSocketServer.on('close', (data) => {
331
331
  console.log('webSocketServer close: %s', data);
332
- // process.exit()
333
332
  });
334
333
 
335
334
  webSocketServer.on('listening', () => {
336
335
  console.log("webSocketServer listening", webSocketServer.address());
337
- // process.exit()
338
336
  });
339
337
 
340
338
  webSocketServer.on('connection', (webSocket: WebSocket) => {
341
- console.log('webSocketServer connection');
342
-
343
339
  webSocket.on('message', (webSocketData) => {
344
- // console.log('webSocket message: %s', webSocketData);
345
340
  const payload = JSON.parse(webSocketData.valueOf().toString() as any);
346
-
347
- // console.log('webSocket payload', JSON.stringify(payload.data.testResourceConfiguration.name, null, 2));
348
- // as {
349
- // type: string,
350
- // data: ITTestResourceRequirement & {
351
- // testResourceConfiguration: {
352
- // name: string;
353
- // }
354
- // }
355
- // };
356
-
357
341
  const messageType = payload.type;
358
342
 
359
343
  if (messageType === "testeranto:hola") {
@@ -400,7 +384,6 @@ export class ITProject {
400
384
 
401
385
  pm2.launchBus((err, pm2_bus) => {
402
386
  pm2_bus.on("testeranto:hola", (packet: { data: { requirement: ITTestResourceRequirement } }) => {
403
- console.log("hola IPC", packet);
404
387
  this.requestResource(
405
388
  packet.data.requirement,
406
389
  'ipc'
@@ -537,14 +520,12 @@ export class ITProject {
537
520
  }
538
521
 
539
522
  private shutdown() {
540
-
541
523
  let i = 0;
542
524
  new Promise((res, reh) => {
543
525
  console.log("final results: ");
544
526
  const procsTable: any[] = [];
545
527
  pm2.list((err, procs) => {
546
528
  procs.forEach((proc, ndx) => {
547
-
548
529
  const exitCode = this.exitCodes[proc.name as string]
549
530
  if (exitCode !== 0) {
550
531
  i++;
@@ -562,11 +543,8 @@ export class ITProject {
562
543
  })
563
544
  })
564
545
  }).then((failures: number) => {
565
- console.log("Stopping PM2");
566
546
  pm2.stop("all", (e) => console.error(e));
567
- // pm2.killDaemon((e) => console.error(e));
568
547
  pm2.disconnect();
569
-
570
548
  console.log(`gracefully exiting with ${failures} failures`)
571
549
  process.exit(failures);
572
550
  })
package/src/Types.ts CHANGED
@@ -2,7 +2,8 @@ export type IBaseConfig = {
2
2
  clearScreen: boolean;
3
3
  devMode: boolean;
4
4
  features: string;
5
- plugins: any[];
5
+ webPlugins: any[];
6
+ nodePlugins: any[];
6
7
  minify: boolean;
7
8
  outbase: string;
8
9
  outdir: string;