@jsenv/test 3.5.6 → 3.5.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.
@@ -4317,6 +4317,11 @@ const reporterList = ({
4317
4317
  {
4318
4318
  reporter: "list",
4319
4319
  beforeAll: async (testPlanResult) => {
4320
+ const applyColorOnFileRelativeUrl = createApplyColorOnFileRelativeUrl(
4321
+ testPlanResult.rootDirectoryUrl,
4322
+ );
4323
+ logOptions.applyColorOnFileRelativeUrl = applyColorOnFileRelativeUrl;
4324
+
4320
4325
  let spyReturnValue = await spy();
4321
4326
  let write = spyReturnValue.write;
4322
4327
  let end = spyReturnValue.end;
@@ -4472,6 +4477,58 @@ const reporterList = ({
4472
4477
  return reporters;
4473
4478
  };
4474
4479
 
4480
+ const createApplyColorOnFileRelativeUrl = (rootDirectoryUrl) => {
4481
+ const packageExistsMap = new Map();
4482
+ const directoryHasPackageJsonFile = (directoryUrl) => {
4483
+ if (packageExistsMap.has(directoryUrl)) {
4484
+ return packageExistsMap.get(directoryUrl);
4485
+ }
4486
+ const packageJsonFileUrl = new URL("./package.json", directoryUrl);
4487
+ if (existsSync(packageJsonFileUrl)) {
4488
+ packageExistsMap.set(directoryUrl, true);
4489
+ return true;
4490
+ }
4491
+ packageExistsMap.set(directoryUrl, false);
4492
+ return false;
4493
+ };
4494
+ const applyColorOnFileRelativeUrl = (fileRelativeUrl, color) => {
4495
+ let parts = fileRelativeUrl.split("/");
4496
+ const filename = parts.pop();
4497
+ let i = 0;
4498
+ while (i < parts.length) {
4499
+ const directoryRelativeUrl = parts.slice(0, i + 1).join("/");
4500
+ const directoryUrl = new URL(`${directoryRelativeUrl}/`, rootDirectoryUrl)
4501
+ .href;
4502
+ if (directoryHasPackageJsonFile(directoryUrl)) {
4503
+ if (i === 0) {
4504
+ return ANSI.color(fileRelativeUrl, color);
4505
+ }
4506
+ // all the things before in grey
4507
+ // all the things after in the color
4508
+ const before = parts.slice(0, i).join("/");
4509
+ const packageDirectory = parts[i];
4510
+ const packageDirectoryStylized = ANSI.color(
4511
+ ANSI.effect(packageDirectory, ANSI.UNDERLINE),
4512
+ color,
4513
+ );
4514
+ let pathColored = ANSI.color(`${before}/`, color);
4515
+ if (i === parts.length - 1) {
4516
+ pathColored += packageDirectoryStylized;
4517
+ pathColored += ANSI.color(`/${filename}`, color);
4518
+ return pathColored;
4519
+ }
4520
+ const after = parts.slice(i + 1).join("/");
4521
+ pathColored += packageDirectoryStylized;
4522
+ pathColored += ANSI.color(`/${after}/${filename}`, color);
4523
+ return pathColored;
4524
+ }
4525
+ i++;
4526
+ }
4527
+ return ANSI.color(fileRelativeUrl, color);
4528
+ };
4529
+ return applyColorOnFileRelativeUrl;
4530
+ };
4531
+
4475
4532
  const renderIntro = (testPlanResult, logOptions) => {
4476
4533
  const directory = logOptions.mockFluctuatingValues
4477
4534
  ? "/mock/"
@@ -4615,15 +4672,17 @@ const renderExecutionLabel = (execution, logOptions) => {
4615
4672
 
4616
4673
  // description
4617
4674
  {
4618
- const description =
4619
- descriptionFormatters[execution.result.status](execution);
4675
+ const description = descriptionFormatters[execution.result.status](
4676
+ execution,
4677
+ logOptions,
4678
+ );
4620
4679
  label += description;
4621
4680
  }
4622
4681
  // runtimeInfo
4623
4682
  {
4624
4683
  const infos = [];
4625
4684
  if (logOptions.group) {
4626
- infos.push(ANSI.color(execution.group, ANSI.GREY));
4685
+ infos.push(execution.group);
4627
4686
  }
4628
4687
  const { timings, memoryUsage } = execution.result;
4629
4688
  if (timings) {
@@ -4669,8 +4728,8 @@ const renderExecutionLabel = (execution, logOptions) => {
4669
4728
  return label;
4670
4729
  };
4671
4730
  const descriptionFormatters = {
4672
- executing: ({ fileRelativeUrl }) => {
4673
- return ANSI.color(`${fileRelativeUrl}`, COLOR_EXECUTING);
4731
+ executing: ({ fileRelativeUrl }, { applyColorOnFileRelativeUrl }) => {
4732
+ return applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_EXECUTING);
4674
4733
  },
4675
4734
  skippedGroup: ({ from, to, skipReason }) => {
4676
4735
  let description = `${UNICODE.CIRCLE_DOTTED_RAW} ${from + 1}:${to + 1} skipped`;
@@ -4679,57 +4738,97 @@ const descriptionFormatters = {
4679
4738
  }
4680
4739
  return ANSI.color(description, COLOR_SKIPPED);
4681
4740
  },
4682
- skipped: ({ index, countersInOrder, fileRelativeUrl, skipReason }) => {
4741
+ skipped: (
4742
+ { index, countersInOrder, fileRelativeUrl, skipReason },
4743
+ { applyColorOnFileRelativeUrl },
4744
+ ) => {
4683
4745
  const total = countersInOrder.planified;
4684
4746
  const number = fillLeft(index + 1, total, "0");
4685
- let description = `${UNICODE.CIRCLE_DOTTED_RAW} ${number}/${total} skipped ${fileRelativeUrl}`;
4747
+ let skipped = ANSI.color(
4748
+ `${UNICODE.CIRCLE_DOTTED_RAW} ${number}`,
4749
+ COLOR_SKIPPED,
4750
+ );
4751
+ skipped += ANSI.color(`/${total}`, COLOR_SKIPPED);
4752
+ skipped += " ";
4753
+ skipped += ANSI.color("skipped", COLOR_SKIPPED);
4754
+ skipped += " ";
4755
+ skipped += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_SKIPPED);
4686
4756
  if (skipReason) {
4687
- description += ` (${skipReason})`;
4757
+ skipped += " ";
4758
+ skipped += ANSI.color(`(${skipReason})`, COLOR_SKIPPED);
4688
4759
  }
4689
- return ANSI.color(description, COLOR_SKIPPED);
4760
+ return skipped;
4690
4761
  },
4691
- aborted: ({ index, countersInOrder, fileRelativeUrl }) => {
4762
+ aborted: (
4763
+ { index, countersInOrder, fileRelativeUrl },
4764
+ { applyColorOnFileRelativeUrl },
4765
+ ) => {
4692
4766
  const total = countersInOrder.planified;
4693
4767
  const number = fillLeft(index + 1, total, "0");
4694
- return ANSI.color(
4695
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl}`,
4696
- COLOR_ABORTED,
4697
- );
4768
+ let aborted = ANSI.color(`${UNICODE.FAILURE_RAW} ${number}`, COLOR_ABORTED);
4769
+ aborted += ANSI.color(`/${total}`, COLOR_ABORTED);
4770
+ aborted += " ";
4771
+ aborted += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_ABORTED);
4772
+ return aborted;
4698
4773
  },
4699
- cancelled: ({ index, countersInOrder, fileRelativeUrl }) => {
4774
+ cancelled: (
4775
+ { index, countersInOrder, fileRelativeUrl },
4776
+ { applyColorOnFileRelativeUrl },
4777
+ ) => {
4700
4778
  const total = countersInOrder.planified;
4701
4779
  const number = fillLeft(index + 1, total, "0");
4702
- return ANSI.color(
4703
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl}`,
4780
+ let cancelled = ANSI.color(
4781
+ `${UNICODE.FAILURE_RAW} ${number}`,
4704
4782
  COLOR_CANCELLED,
4705
4783
  );
4784
+ cancelled += ANSI.color(`/${total}`, COLOR_CANCELLED);
4785
+ cancelled += " ";
4786
+ cancelled += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_CANCELLED);
4787
+ return cancelled;
4706
4788
  },
4707
- timedout: ({ index, countersInOrder, fileRelativeUrl, params }) => {
4789
+ timedout: (
4790
+ { index, countersInOrder, fileRelativeUrl, params },
4791
+ { applyColorOnFileRelativeUrl },
4792
+ ) => {
4708
4793
  const total = countersInOrder.planified;
4709
4794
  const number = fillLeft(index + 1, total, "0");
4710
-
4711
- return ANSI.color(
4712
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl} timeout after ${params.allocatedMs}ms`,
4795
+ let timedout = ANSI.color(
4796
+ `${UNICODE.FAILURE_RAW} ${number}`,
4713
4797
  COLOR_TIMEOUT,
4714
4798
  );
4799
+ timedout += ANSI.color(`/${total}`, COLOR_TIMEOUT);
4800
+ timedout += " ";
4801
+ timedout += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_TIMEOUT);
4802
+ timedout += " ";
4803
+ timedout += ANSI.color(
4804
+ `timeout after ${params.allocatedMs}ms`,
4805
+ COLOR_TIMEOUT,
4806
+ );
4807
+ return timedout;
4715
4808
  },
4716
- failed: ({ index, countersInOrder, fileRelativeUrl }) => {
4809
+ failed: (
4810
+ { index, countersInOrder, fileRelativeUrl },
4811
+ { applyColorOnFileRelativeUrl },
4812
+ ) => {
4717
4813
  const total = countersInOrder.planified;
4718
4814
  const number = fillLeft(index + 1, total, "0");
4719
-
4720
- return ANSI.color(
4721
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl}`,
4722
- COLOR_FAILED,
4723
- );
4815
+ let failed = ANSI.color(`${UNICODE.FAILURE_RAW} ${number}`, COLOR_FAILED);
4816
+ failed += ANSI.color(`/${total}`, COLOR_FAILED);
4817
+ failed += " ";
4818
+ failed += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_FAILED);
4819
+ return failed;
4724
4820
  },
4725
- completed: ({ index, countersInOrder, fileRelativeUrl }) => {
4821
+ completed: (
4822
+ { index, countersInOrder, fileRelativeUrl },
4823
+ { applyColorOnFileRelativeUrl },
4824
+ ) => {
4726
4825
  const total = countersInOrder.planified;
4727
4826
  const number = fillLeft(index + 1, total, "0");
4728
-
4729
- return ANSI.color(
4730
- `${UNICODE.OK_RAW} ${number}/${total} ${fileRelativeUrl}`,
4731
- COLOR_COMPLETED,
4732
- );
4827
+ let completed = ANSI.color(`${UNICODE.OK_RAW} ${number}`, COLOR_COMPLETED);
4828
+ completed += ANSI.color(`/${total}`, COLOR_COMPLETED);
4829
+ completed += " ";
4830
+ completed += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_COMPLETED);
4831
+ return completed;
4733
4832
  },
4734
4833
  };
4735
4834
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/test",
3
- "version": "3.5.6",
3
+ "version": "3.5.8",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,7 +39,7 @@
39
39
  "@jsenv/abort": "4.3.0",
40
40
  "@jsenv/ast": "6.2.17",
41
41
  "@jsenv/exception": "1.1.3",
42
- "@jsenv/filesystem": "4.10.5",
42
+ "@jsenv/filesystem": "4.10.6",
43
43
  "@jsenv/github-check-run": "0.2.1",
44
44
  "@jsenv/node-esm-resolution": "1.0.6",
45
45
  "@jsenv/humanize": "1.2.8",
@@ -7,9 +7,9 @@ import {
7
7
  UNICODE,
8
8
  } from "@jsenv/humanize";
9
9
  import { urlToFileSystemPath } from "@jsenv/urls";
10
+ import { existsSync } from "node:fs";
10
11
  import { memoryUsage as processMemoryUsage } from "node:process";
11
12
  import stripAnsi from "strip-ansi";
12
-
13
13
  import { formatErrorForTerminal } from "../format_error_for_terminal.js";
14
14
 
15
15
  /*
@@ -74,6 +74,11 @@ export const reporterList = ({
74
74
  {
75
75
  reporter: "list",
76
76
  beforeAll: async (testPlanResult) => {
77
+ const applyColorOnFileRelativeUrl = createApplyColorOnFileRelativeUrl(
78
+ testPlanResult.rootDirectoryUrl,
79
+ );
80
+ logOptions.applyColorOnFileRelativeUrl = applyColorOnFileRelativeUrl;
81
+
77
82
  let spyReturnValue = await spy();
78
83
  let write = spyReturnValue.write;
79
84
  let end = spyReturnValue.end;
@@ -229,6 +234,58 @@ export const reporterList = ({
229
234
  return reporters;
230
235
  };
231
236
 
237
+ const createApplyColorOnFileRelativeUrl = (rootDirectoryUrl) => {
238
+ const packageExistsMap = new Map();
239
+ const directoryHasPackageJsonFile = (directoryUrl) => {
240
+ if (packageExistsMap.has(directoryUrl)) {
241
+ return packageExistsMap.get(directoryUrl);
242
+ }
243
+ const packageJsonFileUrl = new URL("./package.json", directoryUrl);
244
+ if (existsSync(packageJsonFileUrl)) {
245
+ packageExistsMap.set(directoryUrl, true);
246
+ return true;
247
+ }
248
+ packageExistsMap.set(directoryUrl, false);
249
+ return false;
250
+ };
251
+ const applyColorOnFileRelativeUrl = (fileRelativeUrl, color) => {
252
+ let parts = fileRelativeUrl.split("/");
253
+ const filename = parts.pop();
254
+ let i = 0;
255
+ while (i < parts.length) {
256
+ const directoryRelativeUrl = parts.slice(0, i + 1).join("/");
257
+ const directoryUrl = new URL(`${directoryRelativeUrl}/`, rootDirectoryUrl)
258
+ .href;
259
+ if (directoryHasPackageJsonFile(directoryUrl)) {
260
+ if (i === 0) {
261
+ return ANSI.color(fileRelativeUrl, color);
262
+ }
263
+ // all the things before in grey
264
+ // all the things after in the color
265
+ const before = parts.slice(0, i).join("/");
266
+ const packageDirectory = parts[i];
267
+ const packageDirectoryStylized = ANSI.color(
268
+ ANSI.effect(packageDirectory, ANSI.UNDERLINE),
269
+ color,
270
+ );
271
+ let pathColored = ANSI.color(`${before}/`, color);
272
+ if (i === parts.length - 1) {
273
+ pathColored += packageDirectoryStylized;
274
+ pathColored += ANSI.color(`/${filename}`, color);
275
+ return pathColored;
276
+ }
277
+ const after = parts.slice(i + 1).join("/");
278
+ pathColored += packageDirectoryStylized;
279
+ pathColored += ANSI.color(`/${after}/${filename}`, color);
280
+ return pathColored;
281
+ }
282
+ i++;
283
+ }
284
+ return ANSI.color(fileRelativeUrl, color);
285
+ };
286
+ return applyColorOnFileRelativeUrl;
287
+ };
288
+
232
289
  const renderIntro = (testPlanResult, logOptions) => {
233
290
  const directory = logOptions.mockFluctuatingValues
234
291
  ? "/mock/"
@@ -372,15 +429,17 @@ const renderExecutionLabel = (execution, logOptions) => {
372
429
 
373
430
  // description
374
431
  {
375
- const description =
376
- descriptionFormatters[execution.result.status](execution);
432
+ const description = descriptionFormatters[execution.result.status](
433
+ execution,
434
+ logOptions,
435
+ );
377
436
  label += description;
378
437
  }
379
438
  // runtimeInfo
380
439
  {
381
440
  const infos = [];
382
441
  if (logOptions.group) {
383
- infos.push(ANSI.color(execution.group, ANSI.GREY));
442
+ infos.push(execution.group);
384
443
  }
385
444
  const { timings, memoryUsage } = execution.result;
386
445
  if (timings) {
@@ -426,8 +485,8 @@ const renderExecutionLabel = (execution, logOptions) => {
426
485
  return label;
427
486
  };
428
487
  const descriptionFormatters = {
429
- executing: ({ fileRelativeUrl }) => {
430
- return ANSI.color(`${fileRelativeUrl}`, COLOR_EXECUTING);
488
+ executing: ({ fileRelativeUrl }, { applyColorOnFileRelativeUrl }) => {
489
+ return applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_EXECUTING);
431
490
  },
432
491
  skippedGroup: ({ from, to, skipReason }) => {
433
492
  let description = `${UNICODE.CIRCLE_DOTTED_RAW} ${from + 1}:${to + 1} skipped`;
@@ -436,57 +495,97 @@ const descriptionFormatters = {
436
495
  }
437
496
  return ANSI.color(description, COLOR_SKIPPED);
438
497
  },
439
- skipped: ({ index, countersInOrder, fileRelativeUrl, skipReason }) => {
498
+ skipped: (
499
+ { index, countersInOrder, fileRelativeUrl, skipReason },
500
+ { applyColorOnFileRelativeUrl },
501
+ ) => {
440
502
  const total = countersInOrder.planified;
441
503
  const number = fillLeft(index + 1, total, "0");
442
- let description = `${UNICODE.CIRCLE_DOTTED_RAW} ${number}/${total} skipped ${fileRelativeUrl}`;
504
+ let skipped = ANSI.color(
505
+ `${UNICODE.CIRCLE_DOTTED_RAW} ${number}`,
506
+ COLOR_SKIPPED,
507
+ );
508
+ skipped += ANSI.color(`/${total}`, COLOR_SKIPPED);
509
+ skipped += " ";
510
+ skipped += ANSI.color("skipped", COLOR_SKIPPED);
511
+ skipped += " ";
512
+ skipped += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_SKIPPED);
443
513
  if (skipReason) {
444
- description += ` (${skipReason})`;
514
+ skipped += " ";
515
+ skipped += ANSI.color(`(${skipReason})`, COLOR_SKIPPED);
445
516
  }
446
- return ANSI.color(description, COLOR_SKIPPED);
517
+ return skipped;
447
518
  },
448
- aborted: ({ index, countersInOrder, fileRelativeUrl }) => {
519
+ aborted: (
520
+ { index, countersInOrder, fileRelativeUrl },
521
+ { applyColorOnFileRelativeUrl },
522
+ ) => {
449
523
  const total = countersInOrder.planified;
450
524
  const number = fillLeft(index + 1, total, "0");
451
- return ANSI.color(
452
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl}`,
453
- COLOR_ABORTED,
454
- );
525
+ let aborted = ANSI.color(`${UNICODE.FAILURE_RAW} ${number}`, COLOR_ABORTED);
526
+ aborted += ANSI.color(`/${total}`, COLOR_ABORTED);
527
+ aborted += " ";
528
+ aborted += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_ABORTED);
529
+ return aborted;
455
530
  },
456
- cancelled: ({ index, countersInOrder, fileRelativeUrl }) => {
531
+ cancelled: (
532
+ { index, countersInOrder, fileRelativeUrl },
533
+ { applyColorOnFileRelativeUrl },
534
+ ) => {
457
535
  const total = countersInOrder.planified;
458
536
  const number = fillLeft(index + 1, total, "0");
459
- return ANSI.color(
460
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl}`,
537
+ let cancelled = ANSI.color(
538
+ `${UNICODE.FAILURE_RAW} ${number}`,
461
539
  COLOR_CANCELLED,
462
540
  );
541
+ cancelled += ANSI.color(`/${total}`, COLOR_CANCELLED);
542
+ cancelled += " ";
543
+ cancelled += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_CANCELLED);
544
+ return cancelled;
463
545
  },
464
- timedout: ({ index, countersInOrder, fileRelativeUrl, params }) => {
546
+ timedout: (
547
+ { index, countersInOrder, fileRelativeUrl, params },
548
+ { applyColorOnFileRelativeUrl },
549
+ ) => {
465
550
  const total = countersInOrder.planified;
466
551
  const number = fillLeft(index + 1, total, "0");
467
-
468
- return ANSI.color(
469
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl} timeout after ${params.allocatedMs}ms`,
552
+ let timedout = ANSI.color(
553
+ `${UNICODE.FAILURE_RAW} ${number}`,
470
554
  COLOR_TIMEOUT,
471
555
  );
556
+ timedout += ANSI.color(`/${total}`, COLOR_TIMEOUT);
557
+ timedout += " ";
558
+ timedout += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_TIMEOUT);
559
+ timedout += " ";
560
+ timedout += ANSI.color(
561
+ `timeout after ${params.allocatedMs}ms`,
562
+ COLOR_TIMEOUT,
563
+ );
564
+ return timedout;
472
565
  },
473
- failed: ({ index, countersInOrder, fileRelativeUrl }) => {
566
+ failed: (
567
+ { index, countersInOrder, fileRelativeUrl },
568
+ { applyColorOnFileRelativeUrl },
569
+ ) => {
474
570
  const total = countersInOrder.planified;
475
571
  const number = fillLeft(index + 1, total, "0");
476
-
477
- return ANSI.color(
478
- `${UNICODE.FAILURE_RAW} ${number}/${total} ${fileRelativeUrl}`,
479
- COLOR_FAILED,
480
- );
572
+ let failed = ANSI.color(`${UNICODE.FAILURE_RAW} ${number}`, COLOR_FAILED);
573
+ failed += ANSI.color(`/${total}`, COLOR_FAILED);
574
+ failed += " ";
575
+ failed += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_FAILED);
576
+ return failed;
481
577
  },
482
- completed: ({ index, countersInOrder, fileRelativeUrl }) => {
578
+ completed: (
579
+ { index, countersInOrder, fileRelativeUrl },
580
+ { applyColorOnFileRelativeUrl },
581
+ ) => {
483
582
  const total = countersInOrder.planified;
484
583
  const number = fillLeft(index + 1, total, "0");
485
-
486
- return ANSI.color(
487
- `${UNICODE.OK_RAW} ${number}/${total} ${fileRelativeUrl}`,
488
- COLOR_COMPLETED,
489
- );
584
+ let completed = ANSI.color(`${UNICODE.OK_RAW} ${number}`, COLOR_COMPLETED);
585
+ completed += ANSI.color(`/${total}`, COLOR_COMPLETED);
586
+ completed += " ";
587
+ completed += applyColorOnFileRelativeUrl(fileRelativeUrl, COLOR_COMPLETED);
588
+ return completed;
490
589
  },
491
590
  };
492
591