testeranto 0.43.1 → 0.45.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.
@@ -13,13 +13,15 @@ exports.default = async (input, testSpecification, testImplementation, testInter
13
13
  function (b) {
14
14
  return b;
15
15
  }, NodeWriter_js_1.NodeWriter);
16
- const t = mrt[0];
16
+ const t = mrt.testJobs[0];
17
17
  const testResourceArg = process.argv[2] || `{}`;
18
18
  try {
19
19
  const partialTestResource = JSON.parse(testResourceArg);
20
20
  if (testResourceRequirement.ports == 0) {
21
- const failed = await t.receiveTestResourceConfig(partialTestResource);
22
- // process.exit(failed ? 1 : 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
+ });
23
25
  }
24
26
  else {
25
27
  console.log("test configuration is incomplete", partialTestResource);
@@ -38,7 +40,7 @@ exports.default = async (input, testSpecification, testImplementation, testInter
38
40
  const resourcesFromPm2 = packet.data.testResourceConfiguration;
39
41
  const secondTestResource = Object.assign(Object.assign({ fs: "." }, JSON.parse(JSON.stringify(partialTestResource))), JSON.parse(JSON.stringify(resourcesFromPm2)));
40
42
  console.log("secondTestResource", secondTestResource);
41
- const failed = await t.receiveTestResourceConfig(secondTestResource);
43
+ const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource);
42
44
  /* @ts-ignore:next-line */
43
45
  process.send({
44
46
  type: "testeranto:adios",
@@ -46,13 +48,15 @@ exports.default = async (input, testSpecification, testImplementation, testInter
46
48
  testResourceConfiguration: t.test.testResourceConfiguration,
47
49
  results: t.toObj(),
48
50
  },
49
- }, (err) => {
51
+ }, async (err) => {
50
52
  if (!err) {
51
- // process.exit(failed ? 1 : 0);
53
+ Promise.all([...artifacts, logPromise]).then(async () => {
54
+ process.exit(await failed ? 1 : 0);
55
+ });
52
56
  }
53
57
  else {
54
58
  console.error(err);
55
- // process.exit(1);
59
+ process.exit(1);
56
60
  }
57
61
  });
58
62
  });
@@ -17,35 +17,40 @@ exports.NodeWriter = {
17
17
  mkdirSync: async (fp) => {
18
18
  await fs_1.default.mkdirSync(fp, { recursive: true });
19
19
  },
20
- testArtiFactoryfileWriter: (tLog) => (fPath, value) => {
21
- tLog("testArtiFactory =>", fPath);
22
- const cleanPath = path_1.default.resolve(fPath);
23
- fPaths.push(cleanPath.replace(process.cwd(), ``));
24
- const targetDir = cleanPath.split("/").slice(0, -1).join("/");
25
- fs_1.default.mkdir(targetDir, { recursive: true }, async (error) => {
26
- if (error) {
27
- console.error(`❗️testArtiFactory failed`, targetDir, error);
28
- }
29
- fs_1.default.writeFileSync(path_1.default.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
30
- encoding: "utf-8",
31
- });
32
- if (Buffer.isBuffer(value)) {
33
- fs_1.default.writeFileSync(fPath, value, "binary");
34
- }
35
- else if (`string` === typeof value) {
36
- fs_1.default.writeFileSync(fPath, value.toString(), {
20
+ testArtiFactoryfileWriter: (tLog, callback) => (fPath, value) => {
21
+ callback(new Promise((res, rej) => {
22
+ tLog("testArtiFactory =>", fPath);
23
+ const cleanPath = path_1.default.resolve(fPath);
24
+ fPaths.push(cleanPath.replace(process.cwd(), ``));
25
+ const targetDir = cleanPath.split("/").slice(0, -1).join("/");
26
+ fs_1.default.mkdir(targetDir, { recursive: true }, async (error) => {
27
+ if (error) {
28
+ console.error(`❗️testArtiFactory failed`, targetDir, error);
29
+ }
30
+ fs_1.default.writeFileSync(path_1.default.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
37
31
  encoding: "utf-8",
38
32
  });
39
- }
40
- else {
41
- /* @ts-ignore:next-line */
42
- const pipeStream = value;
43
- const myFile = fs_1.default.createWriteStream(fPath);
44
- pipeStream.pipe(myFile);
45
- pipeStream.on("close", () => {
46
- myFile.close();
47
- });
48
- }
49
- });
33
+ if (Buffer.isBuffer(value)) {
34
+ fs_1.default.writeFileSync(fPath, value, "binary");
35
+ res();
36
+ }
37
+ else if (`string` === typeof value) {
38
+ fs_1.default.writeFileSync(fPath, value.toString(), {
39
+ encoding: "utf-8",
40
+ });
41
+ res();
42
+ }
43
+ else {
44
+ /* @ts-ignore:next-line */
45
+ const pipeStream = value;
46
+ const myFile = fs_1.default.createWriteStream(fPath);
47
+ pipeStream.pipe(myFile);
48
+ pipeStream.on("close", () => {
49
+ myFile.close();
50
+ res();
51
+ });
52
+ }
53
+ });
54
+ }));
50
55
  }
51
56
  };
@@ -82,7 +82,7 @@ class ITProject {
82
82
  if (!this.devMode && this.mode === "up") {
83
83
  this.initiateShutdown("resource request queue is empty");
84
84
  }
85
- if (this.mode === "down" && procsTable.every((p) => p.pid === 0)) {
85
+ if (this.mode === "down" && procsTable.every((p) => p.pid === 0 || p.pid === undefined)) {
86
86
  this.shutdown();
87
87
  }
88
88
  }
@@ -139,31 +139,6 @@ class ITProject {
139
139
  this.tests = tests.default;
140
140
  Promise.resolve().then(() => __importStar(require(featurePath))).then((features) => {
141
141
  this.features = features.default;
142
- const [nodeEntryPoints, webEntryPoints] = getRunnables(this.tests);
143
- const esbuildConfigNode = {
144
- packages: "external",
145
- external: ["tests.test.js", "features.test.js"],
146
- platform: "node",
147
- outbase: config.outbase,
148
- outdir: config.outdir,
149
- jsx: `transform`,
150
- entryPoints: [...nodeEntryPoints],
151
- bundle: true,
152
- minify: config.minify === true,
153
- write: true,
154
- plugins: [
155
- ...(config.loaders || []),
156
- {
157
- name: 'rebuild-notify',
158
- setup(build) {
159
- build.onEnd(result => {
160
- console.log(`node build ended with ${result.errors.length} errors`);
161
- // HERE: somehow restart the server from here, e.g., by sending a signal that you trap and react to inside the server.
162
- });
163
- }
164
- },
165
- ],
166
- };
167
142
  Promise.resolve(Promise.all([
168
143
  ...this.getSecondaryEndpointsPoints("web")
169
144
  ]
@@ -173,7 +148,7 @@ class ITProject {
173
148
  const sourceFileName = sourceFileSplit[sourceFileSplit.length - 1];
174
149
  const sourceFileNameMinusJs = sourceFileName.split(".").slice(0, -1).join(".");
175
150
  const htmlFilePath = path_1.default.normalize(`${process.cwd()}/${config.outdir}/${sourceDir.join("/")}/${sourceFileNameMinusJs}.html`);
176
- const jsfilePath = `./${sourceFileNameMinusJs}.js`;
151
+ const jsfilePath = `./${sourceFileNameMinusJs}.mjs`;
177
152
  return fs_1.default.promises.mkdir(path_1.default.dirname(htmlFilePath), { recursive: true }).then(x => fs_1.default.writeFileSync(htmlFilePath, `
178
153
  <!DOCTYPE html>
179
154
  <html lang="en">
@@ -193,13 +168,57 @@ class ITProject {
193
168
  </html>
194
169
  `));
195
170
  })));
171
+ const [nodeEntryPoints, webEntryPoints] = getRunnables(this.tests);
172
+ const esbuildConfigNode = {
173
+ define: {
174
+ "process.env.FLUENTFFMPEG_COV": "0"
175
+ },
176
+ absWorkingDir: process.cwd(),
177
+ banner: {
178
+ js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
179
+ },
180
+ target: "esnext",
181
+ // packages: "external",
182
+ format: "esm",
183
+ splitting: true,
184
+ outExtension: { '.js': '.mjs' },
185
+ platform: "node",
186
+ external: ["tests.test.js", "features.test.js"],
187
+ outbase: config.outbase,
188
+ outdir: config.outdir,
189
+ jsx: 'transform',
190
+ entryPoints: [...nodeEntryPoints],
191
+ bundle: true,
192
+ minify: config.minify === true,
193
+ write: true,
194
+ loader: {
195
+ '.js': 'jsx',
196
+ '.png': 'binary',
197
+ '.jpg': 'binary',
198
+ },
199
+ plugins: [
200
+ ...(config.plugins || []),
201
+ {
202
+ name: 'rebuild-notify',
203
+ setup(build) {
204
+ build.onEnd(result => {
205
+ console.log(`node build ended with ${result.errors.length} errors`);
206
+ // HERE: somehow restart the server from here, e.g., by sending a signal that you trap and react to inside the server.
207
+ });
208
+ }
209
+ },
210
+ ],
211
+ };
196
212
  const esbuildConfigWeb = {
213
+ // packages: "external",
214
+ format: "esm",
215
+ splitting: true,
216
+ outExtension: { '.js': '.mjs' },
197
217
  external: ["stream", "tests.test.js", "features.test.js"],
198
218
  platform: "browser",
199
- format: "esm",
200
219
  outbase: config.outbase,
201
220
  outdir: config.outdir,
202
- jsx: `transform`,
221
+ jsx: 'transform',
203
222
  entryPoints: [
204
223
  ...webEntryPoints,
205
224
  testPath,
@@ -208,9 +227,13 @@ class ITProject {
208
227
  bundle: true,
209
228
  minify: config.minify === true,
210
229
  write: true,
211
- splitting: true,
230
+ loader: {
231
+ '.js': 'jsx',
232
+ '.png': 'binary',
233
+ '.jpg': 'binary',
234
+ },
212
235
  plugins: [
213
- ...(config.loaders || []),
236
+ ...(config.plugins || []),
214
237
  {
215
238
  name: 'rebuild-notify',
216
239
  setup(build) {
@@ -220,21 +243,6 @@ class ITProject {
220
243
  });
221
244
  }
222
245
  },
223
- // {
224
- // name: "testeranto-redirect",
225
- // setup(build) {
226
- // build.onResolve({ filter: /^.*\/testeranto\/$/ }, (args) => {
227
- // return {
228
- // path: path.join(
229
- // process.cwd(),
230
- // `..`,
231
- // "node_modules",
232
- // `testeranto`
233
- // ),
234
- // };
235
- // });
236
- // },
237
- // },
238
246
  ],
239
247
  };
240
248
  esbuild_1.default.build({
@@ -332,15 +340,13 @@ class ITProject {
332
340
  }
333
341
  });
334
342
  });
335
- const makePath = (fPath) => {
336
- const ext = path_1.default.extname(fPath);
337
- const x = "./" + config.outdir + "/" + fPath.replace(ext, "") + ".js";
338
- return path_1.default.resolve(x);
343
+ const makePath = (fPath, rt) => {
344
+ return path_1.default.resolve("./" + config.outdir + "/" + fPath.replace(path_1.default.extname(fPath), "") + ".mjs");
339
345
  };
340
346
  const bootInterval = setInterval(async () => {
341
347
  const filesToLookup = this.tests
342
348
  .map(([p, rt]) => {
343
- const filepath = makePath(p);
349
+ const filepath = makePath(p, rt);
344
350
  return {
345
351
  filepath,
346
352
  exists: (0, fs_promises_exists_1.default)(filepath),
@@ -368,7 +374,7 @@ class ITProject {
368
374
  this
369
375
  .tests
370
376
  .reduce((m, [inputFilePath, runtime]) => {
371
- const script = makePath(inputFilePath);
377
+ const script = makePath(inputFilePath, runtime);
372
378
  const partialTestResourceByCommandLineArg = `${script} '${JSON.stringify({
373
379
  name: inputFilePath,
374
380
  ports: [],
@@ -380,7 +386,7 @@ class ITProject {
380
386
  const fname = fileAsList[fileAsList.length - 1];
381
387
  const fnameOnly = fname.split(".").slice(0, -1).join(".");
382
388
  const htmlFile = [config.outdir, ...fileListHead, `${fnameOnly}.html`].join("/");
383
- const jsFile = htmlFile.split(".html")[0] + ".js";
389
+ const jsFile = htmlFile.split(".html")[0] + ".mjs";
384
390
  console.log("watching", jsFile);
385
391
  pm2_1.default.start({
386
392
  script: `yarn electron node_modules/testeranto/dist/common/electron.js ${htmlFile} '${JSON.stringify({
@@ -14,13 +14,19 @@ exports.default = async (input, testSpecification, testImplementation, testInter
14
14
  function (b) {
15
15
  return b;
16
16
  }, window.NodeWriter);
17
- const t = mrt[0];
17
+ const tl2 = mrt;
18
+ const t = tl2.testJobs[0];
18
19
  const testResourceArg = decodeURIComponent(new URLSearchParams(location.search).get('requesting') || '');
19
20
  try {
20
21
  const partialTestResource = JSON.parse(testResourceArg);
21
22
  if (partialTestResource.fs && partialTestResource.ports) {
22
- const failed = await t.receiveTestResourceConfig(partialTestResource);
23
- window.exit(failed);
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
+ });
24
30
  }
25
31
  else {
26
32
  console.log("test configuration is incomplete", partialTestResource);
@@ -42,7 +48,11 @@ exports.default = async (input, testSpecification, testImplementation, testInter
42
48
  const resourcesFromPm2 = msg.data.testResourceConfiguration;
43
49
  const secondTestResource = Object.assign(Object.assign({ fs: "." }, JSON.parse(JSON.stringify(partialTestResource))), JSON.parse(JSON.stringify(resourcesFromPm2)));
44
50
  console.log("secondTestResource", secondTestResource);
45
- const failed = await t.receiveTestResourceConfig(partialTestResource);
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
+ });
46
56
  webSocket.send(JSON.stringify({
47
57
  type: "testeranto:adios",
48
58
  data: {
@@ -59,6 +69,6 @@ exports.default = async (input, testSpecification, testImplementation, testInter
59
69
  }
60
70
  catch (e) {
61
71
  console.error(e);
62
- process.exit(-1);
72
+ // process.exit(-1);
63
73
  }
64
74
  };
@@ -245,6 +245,7 @@ class TesterantoLevelZero {
245
245
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////
246
246
  class TesterantoLevelOne {
247
247
  constructor(testImplementation, testSpecification, input, suiteKlasser, givenKlasser, whenKlasser, thenKlasser, checkKlasser, testResourceRequirement, logWriter) {
248
+ this.artifacts = [];
248
249
  const classySuites = Object.entries(testImplementation.Suites).reduce((a, [key], index) => {
249
250
  a[key] = (somestring, givens, checks) => {
250
251
  return new suiteKlasser.prototype.constructor(somestring, index, givens, checks);
@@ -282,10 +283,12 @@ class TesterantoLevelOne {
282
283
  /* @ts-ignore:next-line */
283
284
  classyTesteranto.Suites(), classyTesteranto.Given(), classyTesteranto.When(), classyTesteranto.Then(), classyTesteranto.Check(), logWriter);
284
285
  const suiteRunner = (suite) => async (testResourceConfiguration, tLog) => {
285
- return await suite.run(input, testResourceConfiguration, (fPath, value) => logWriter.testArtiFactoryfileWriter(tLog)(testResourceConfiguration.fs + "/" + fPath, value), tLog);
286
+ return await suite.run(input, testResourceConfiguration, (fPath, value) => logWriter.testArtiFactoryfileWriter(tLog, (p) => {
287
+ artifacts.push(p);
288
+ })(testResourceConfiguration.fs + "/" + fPath, value), tLog);
286
289
  };
287
- /* @ts-ignore:next-line */
288
- const toReturn = suites.map((suite) => {
290
+ const artifacts = this.artifacts;
291
+ this.testJobs = suites.map((suite) => {
289
292
  const runner = suiteRunner(suite);
290
293
  return {
291
294
  test: suite,
@@ -306,21 +309,23 @@ class TesterantoLevelOne {
306
309
  const suiteDone = await runner(testResourceConfiguration, tLog);
307
310
  const resultsFilePath = (`${testResourceConfiguration.fs}/results.json`);
308
311
  logWriter.writeFileSync(resultsFilePath, JSON.stringify(suiteDone.toObj(), null, 2));
309
- // logWriter.writeFileSync(
310
- // `${testResourceConfiguration.fs}/results2.json`,
311
- // JSON.stringify(suiteDone.givens, null, 2)
312
- // );
313
- access.close();
312
+ const logPromise = new Promise((res, rej) => {
313
+ access.on("finish", () => { res(true); });
314
+ });
315
+ access.end();
314
316
  const numberOfFailures = Object.keys(suiteDone.givens).filter((k) => {
315
317
  // console.log(`suiteDone.givens[k].error`, suiteDone.givens[k].error);
316
318
  return suiteDone.givens[k].error;
317
319
  }).length;
318
320
  console.log(`exiting gracefully with ${numberOfFailures} failures.`);
319
- return numberOfFailures !== 0;
321
+ return {
322
+ failed: numberOfFailures,
323
+ artifacts,
324
+ logPromise
325
+ };
320
326
  },
321
327
  };
322
328
  });
323
- return toReturn;
324
329
  }
325
330
  }
326
331
  ////////////////////////////////////////////////////////////////////////////////////////////////
@@ -31,10 +31,10 @@ function createWindow() {
31
31
  });
32
32
  console.log("loading", u);
33
33
  win.loadURL(u);
34
- win.webContents.openDevTools();
34
+ // win.webContents.openDevTools()
35
35
  }
36
36
  electron_1.app.on("ready", createWindow);
37
37
  electron_1.ipcMain.handle('quit-app', (x, failed) => {
38
38
  console.log("quit-app", failed);
39
- electron_1.app.exit(failed ? 1 : 0);
39
+ electron_1.app.exit(failed);
40
40
  });