@jsenv/test 3.6.7 → 3.6.9
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/dist/jsenv_test.js +602 -778
- package/dist/jsenv_test_node_modules.js +295 -0
- package/package.json +10 -10
- package/src/execution/execute_test_plan.js +21 -82
- package/src/execution/reporters/reporter_list.js +3 -73
- package/src/helpers/call_orderer.js +0 -39
- package/src/helpers/cpu_usage.js +0 -221
- package/src/helpers/cpu_usage.test_manual.js +0 -17
package/dist/jsenv_test.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { readGitHubWorkflowEnv, startGithubCheckRun } from "@jsenv/github-check-run";
|
|
2
|
-
import process$1, { cpuUsage, memoryUsage } from "node:process";
|
|
3
|
-
import os, { cpus, totalmem, release, availableParallelism, freemem } from "node:os";
|
|
4
|
-
import tty from "node:tty";
|
|
5
|
-
import stringWidth from "string-width";
|
|
6
2
|
import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
7
3
|
import { readdir, chmod, stat, lstat, chmodSync, statSync, lstatSync, promises, readFile as readFile$1, readdirSync, openSync, closeSync, unlinkSync, rmdirSync, mkdirSync, readFileSync, writeFileSync as writeFileSync$1, unlink, rmdir, existsSync } from "node:fs";
|
|
8
4
|
import { takeCoverage } from "node:v8";
|
|
@@ -10,16 +6,21 @@ import stripAnsi from "strip-ansi";
|
|
|
10
6
|
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
11
7
|
import { createRequire } from "node:module";
|
|
12
8
|
import { applyBabelPlugins } from "@jsenv/ast";
|
|
9
|
+
import { cpuUsage, memoryUsage } from "node:process";
|
|
10
|
+
import { createSupportsColor, isUnicodeSupported, clearTerminal, eraseLines } from "./jsenv_test_node_modules.js";
|
|
11
|
+
import { measureTextWidth } from "@jsenv/terminal-text-size";
|
|
13
12
|
import { createException } from "@jsenv/exception";
|
|
14
13
|
import crypto from "node:crypto";
|
|
15
14
|
import { dirname } from "node:path";
|
|
16
15
|
import { createServer } from "node:net";
|
|
17
16
|
import { spawn, spawnSync, fork } from "node:child_process";
|
|
17
|
+
import { availableParallelism, cpus, totalmem, release, freemem } from "node:os";
|
|
18
18
|
import { SOURCEMAP, generateSourcemapDataUrl } from "@jsenv/sourcemap";
|
|
19
19
|
import { injectSupervisorIntoHTML, supervisorFileUrl } from "@jsenv/plugin-supervisor";
|
|
20
20
|
import { findFreePort } from "@jsenv/server";
|
|
21
21
|
import { Worker } from "node:worker_threads";
|
|
22
22
|
import he from "he";
|
|
23
|
+
import "node:tty";
|
|
23
24
|
|
|
24
25
|
const createCallbackListNotifiedOnce = () => {
|
|
25
26
|
let callbacks = [];
|
|
@@ -530,329 +531,86 @@ const SIGINT_CALLBACK = {
|
|
|
530
531
|
},
|
|
531
532
|
};
|
|
532
533
|
|
|
533
|
-
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
|
|
534
|
-
/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
|
|
535
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
|
|
536
|
-
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
537
|
-
const position = argv.indexOf(prefix + flag);
|
|
538
|
-
const terminatorPosition = argv.indexOf('--');
|
|
539
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
const {env} = process$1;
|
|
543
|
-
|
|
544
|
-
let flagForceColor;
|
|
545
|
-
if (
|
|
546
|
-
hasFlag('no-color')
|
|
547
|
-
|| hasFlag('no-colors')
|
|
548
|
-
|| hasFlag('color=false')
|
|
549
|
-
|| hasFlag('color=never')
|
|
550
|
-
) {
|
|
551
|
-
flagForceColor = 0;
|
|
552
|
-
} else if (
|
|
553
|
-
hasFlag('color')
|
|
554
|
-
|| hasFlag('colors')
|
|
555
|
-
|| hasFlag('color=true')
|
|
556
|
-
|| hasFlag('color=always')
|
|
557
|
-
) {
|
|
558
|
-
flagForceColor = 1;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
function envForceColor() {
|
|
562
|
-
if (!('FORCE_COLOR' in env)) {
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
if (env.FORCE_COLOR === 'true') {
|
|
567
|
-
return 1;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
if (env.FORCE_COLOR === 'false') {
|
|
571
|
-
return 0;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
if (env.FORCE_COLOR.length === 0) {
|
|
575
|
-
return 1;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
579
|
-
|
|
580
|
-
if (![0, 1, 2, 3].includes(level)) {
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
return level;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function translateLevel(level) {
|
|
588
|
-
if (level === 0) {
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return {
|
|
593
|
-
level,
|
|
594
|
-
hasBasic: true,
|
|
595
|
-
has256: level >= 2,
|
|
596
|
-
has16m: level >= 3,
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
601
|
-
const noFlagForceColor = envForceColor();
|
|
602
|
-
if (noFlagForceColor !== undefined) {
|
|
603
|
-
flagForceColor = noFlagForceColor;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
607
|
-
|
|
608
|
-
if (forceColor === 0) {
|
|
609
|
-
return 0;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
if (sniffFlags) {
|
|
613
|
-
if (hasFlag('color=16m')
|
|
614
|
-
|| hasFlag('color=full')
|
|
615
|
-
|| hasFlag('color=truecolor')) {
|
|
616
|
-
return 3;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
if (hasFlag('color=256')) {
|
|
620
|
-
return 2;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// Check for Azure DevOps pipelines.
|
|
625
|
-
// Has to be above the `!streamIsTTY` check.
|
|
626
|
-
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
|
|
627
|
-
return 1;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
631
|
-
return 0;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
const min = forceColor || 0;
|
|
635
|
-
|
|
636
|
-
if (env.TERM === 'dumb') {
|
|
637
|
-
return min;
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
if (process$1.platform === 'win32') {
|
|
641
|
-
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
642
|
-
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
643
|
-
const osRelease = os.release().split('.');
|
|
644
|
-
if (
|
|
645
|
-
Number(osRelease[0]) >= 10
|
|
646
|
-
&& Number(osRelease[2]) >= 10_586
|
|
647
|
-
) {
|
|
648
|
-
return Number(osRelease[2]) >= 14_931 ? 3 : 2;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
return 1;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
if ('CI' in env) {
|
|
655
|
-
if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
|
|
656
|
-
return 3;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
660
|
-
return 1;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
return min;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
if ('TEAMCITY_VERSION' in env) {
|
|
667
|
-
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
if (env.COLORTERM === 'truecolor') {
|
|
671
|
-
return 3;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
if (env.TERM === 'xterm-kitty') {
|
|
675
|
-
return 3;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
if ('TERM_PROGRAM' in env) {
|
|
679
|
-
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
680
|
-
|
|
681
|
-
switch (env.TERM_PROGRAM) {
|
|
682
|
-
case 'iTerm.app': {
|
|
683
|
-
return version >= 3 ? 3 : 2;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
case 'Apple_Terminal': {
|
|
687
|
-
return 2;
|
|
688
|
-
}
|
|
689
|
-
// No default
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
if (/-256(color)?$/i.test(env.TERM)) {
|
|
694
|
-
return 2;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
698
|
-
return 1;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
if ('COLORTERM' in env) {
|
|
702
|
-
return 1;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
return min;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
function createSupportsColor(stream, options = {}) {
|
|
709
|
-
const level = _supportsColor(stream, {
|
|
710
|
-
streamIsTTY: stream && stream.isTTY,
|
|
711
|
-
...options,
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
return translateLevel(level);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
({
|
|
718
|
-
stdout: createSupportsColor({isTTY: tty.isatty(1)}),
|
|
719
|
-
stderr: createSupportsColor({isTTY: tty.isatty(2)}),
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
function isUnicodeSupported() {
|
|
723
|
-
const {env} = process$1;
|
|
724
|
-
const {TERM, TERM_PROGRAM} = env;
|
|
725
|
-
|
|
726
|
-
if (process$1.platform !== 'win32') {
|
|
727
|
-
return TERM !== 'linux'; // Linux console (kernel)
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
return Boolean(env.WT_SESSION) // Windows Terminal
|
|
731
|
-
|| Boolean(env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|
|
732
|
-
|| env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|
|
733
|
-
|| TERM_PROGRAM === 'Terminus-Sublime'
|
|
734
|
-
|| TERM_PROGRAM === 'vscode'
|
|
735
|
-
|| TERM === 'xterm-256color'
|
|
736
|
-
|| TERM === 'alacritty'
|
|
737
|
-
|| TERM === 'rxvt-unicode'
|
|
738
|
-
|| TERM === 'rxvt-unicode-256color'
|
|
739
|
-
|| env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
/* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
|
|
743
|
-
|
|
744
|
-
const isBrowser = globalThis.window?.document !== undefined;
|
|
745
|
-
|
|
746
|
-
globalThis.process?.versions?.node !== undefined;
|
|
747
|
-
|
|
748
|
-
globalThis.process?.versions?.bun !== undefined;
|
|
749
|
-
|
|
750
|
-
globalThis.Deno?.version?.deno !== undefined;
|
|
751
|
-
|
|
752
|
-
globalThis.process?.versions?.electron !== undefined;
|
|
753
|
-
|
|
754
|
-
globalThis.navigator?.userAgent?.includes('jsdom') === true;
|
|
755
|
-
|
|
756
|
-
typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
|
|
757
|
-
|
|
758
|
-
typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
|
|
759
|
-
|
|
760
|
-
typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
|
|
761
|
-
|
|
762
|
-
typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
|
|
763
|
-
|
|
764
|
-
// Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
|
|
765
|
-
const platform = globalThis.navigator?.userAgentData?.platform;
|
|
766
|
-
|
|
767
|
-
platform === 'macOS'
|
|
768
|
-
|| globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
|
|
769
|
-
|| globalThis.navigator?.userAgent?.includes(' Mac ') === true
|
|
770
|
-
|| globalThis.process?.platform === 'darwin';
|
|
771
|
-
|
|
772
|
-
platform === 'Windows'
|
|
773
|
-
|| globalThis.navigator?.platform === 'Win32'
|
|
774
|
-
|| globalThis.process?.platform === 'win32';
|
|
775
|
-
|
|
776
|
-
platform === 'Linux'
|
|
777
|
-
|| globalThis.navigator?.platform?.startsWith('Linux') === true
|
|
778
|
-
|| globalThis.navigator?.userAgent?.includes(' Linux ') === true
|
|
779
|
-
|| globalThis.process?.platform === 'linux';
|
|
780
|
-
|
|
781
|
-
platform === 'Android'
|
|
782
|
-
|| globalThis.navigator?.platform === 'Android'
|
|
783
|
-
|| globalThis.navigator?.userAgent?.includes(' Android ') === true
|
|
784
|
-
|| globalThis.process?.platform === 'android';
|
|
785
|
-
|
|
786
|
-
const ESC = '\u001B[';
|
|
787
|
-
|
|
788
|
-
!isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
789
|
-
const isWindows$3 = !isBrowser && process$1.platform === 'win32';
|
|
790
|
-
|
|
791
|
-
isBrowser ? () => {
|
|
792
|
-
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
|
|
793
|
-
} : process$1.cwd;
|
|
794
|
-
|
|
795
|
-
const cursorUp = (count = 1) => ESC + count + 'A';
|
|
796
|
-
|
|
797
|
-
const cursorLeft = ESC + 'G';
|
|
798
|
-
|
|
799
|
-
const eraseLines = count => {
|
|
800
|
-
let clear = '';
|
|
801
|
-
|
|
802
|
-
for (let i = 0; i < count; i++) {
|
|
803
|
-
clear += eraseLine + (i < count - 1 ? cursorUp() : '');
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
if (count) {
|
|
807
|
-
clear += cursorLeft;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
return clear;
|
|
811
|
-
};
|
|
812
|
-
const eraseLine = ESC + '2K';
|
|
813
|
-
const eraseScreen = ESC + '2J';
|
|
814
|
-
|
|
815
|
-
const clearTerminal = isWindows$3
|
|
816
|
-
? `${eraseScreen}${ESC}0f`
|
|
817
|
-
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
818
|
-
// 2. Erases the whole screen including scrollback buffer
|
|
819
|
-
// 3. Moves cursor to the top-left position
|
|
820
|
-
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
821
|
-
: `${eraseScreen}${ESC}3J${ESC}H`;
|
|
822
|
-
|
|
823
534
|
const createDetailedMessage = (message, details = {}) => {
|
|
824
|
-
let
|
|
535
|
+
let text = `${message}`;
|
|
536
|
+
const namedSectionsText = renderNamedSections(details);
|
|
537
|
+
if (namedSectionsText) {
|
|
538
|
+
text += `
|
|
539
|
+
${namedSectionsText}`;
|
|
540
|
+
}
|
|
541
|
+
return text;
|
|
542
|
+
};
|
|
825
543
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
544
|
+
const renderNamedSections = (namedSections) => {
|
|
545
|
+
let text = "";
|
|
546
|
+
let keys = Object.keys(namedSections);
|
|
547
|
+
for (const key of keys) {
|
|
548
|
+
const isLastKey = key === keys[keys.length - 1];
|
|
549
|
+
const value = namedSections[key];
|
|
550
|
+
text += `--- ${key} ---
|
|
830
551
|
${
|
|
831
552
|
Array.isArray(value)
|
|
832
553
|
? value.join(`
|
|
833
554
|
`)
|
|
834
555
|
: value
|
|
835
556
|
}`;
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
557
|
+
if (!isLastKey) {
|
|
558
|
+
text += "\n";
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return text;
|
|
839
562
|
};
|
|
840
563
|
|
|
841
564
|
// https://github.com/Marak/colors.js/blob/master/lib/styles.js
|
|
842
565
|
// https://stackoverflow.com/a/75985833/2634179
|
|
843
566
|
const RESET = "\x1b[0m";
|
|
844
567
|
|
|
568
|
+
const RED = "red";
|
|
569
|
+
const GREEN = "green";
|
|
570
|
+
const YELLOW = "yellow";
|
|
571
|
+
const BLUE = "blue";
|
|
572
|
+
const MAGENTA = "magenta";
|
|
573
|
+
const CYAN = "cyan";
|
|
574
|
+
const GREY = "grey";
|
|
575
|
+
const WHITE = "white";
|
|
576
|
+
const BLACK = "black";
|
|
577
|
+
|
|
578
|
+
const TEXT_COLOR_ANSI_CODES = {
|
|
579
|
+
[RED]: "\x1b[31m",
|
|
580
|
+
[GREEN]: "\x1b[32m",
|
|
581
|
+
[YELLOW]: "\x1b[33m",
|
|
582
|
+
[BLUE]: "\x1b[34m",
|
|
583
|
+
[MAGENTA]: "\x1b[35m",
|
|
584
|
+
[CYAN]: "\x1b[36m",
|
|
585
|
+
[GREY]: "\x1b[90m",
|
|
586
|
+
[WHITE]: "\x1b[37m",
|
|
587
|
+
[BLACK]: "\x1b[30m",
|
|
588
|
+
};
|
|
589
|
+
const BACKGROUND_COLOR_ANSI_CODES = {
|
|
590
|
+
[RED]: "\x1b[41m",
|
|
591
|
+
[GREEN]: "\x1b[42m",
|
|
592
|
+
[YELLOW]: "\x1b[43m",
|
|
593
|
+
[BLUE]: "\x1b[44m",
|
|
594
|
+
[MAGENTA]: "\x1b[45m",
|
|
595
|
+
[CYAN]: "\x1b[46m",
|
|
596
|
+
[GREY]: "\x1b[100m",
|
|
597
|
+
[WHITE]: "\x1b[47m",
|
|
598
|
+
[BLACK]: "\x1b[40m",
|
|
599
|
+
};
|
|
600
|
+
|
|
845
601
|
const createAnsi = ({ supported }) => {
|
|
846
602
|
const ANSI = {
|
|
847
603
|
supported,
|
|
848
604
|
|
|
849
|
-
RED
|
|
850
|
-
GREEN
|
|
851
|
-
YELLOW
|
|
852
|
-
BLUE
|
|
853
|
-
MAGENTA
|
|
854
|
-
CYAN
|
|
855
|
-
GREY
|
|
605
|
+
RED,
|
|
606
|
+
GREEN,
|
|
607
|
+
YELLOW,
|
|
608
|
+
BLUE,
|
|
609
|
+
MAGENTA,
|
|
610
|
+
CYAN,
|
|
611
|
+
GREY,
|
|
612
|
+
WHITE,
|
|
613
|
+
BLACK,
|
|
856
614
|
color: (text, color) => {
|
|
857
615
|
if (!ANSI.supported) {
|
|
858
616
|
return text;
|
|
@@ -864,7 +622,29 @@ const createAnsi = ({ supported }) => {
|
|
|
864
622
|
// cannot set color of blank chars
|
|
865
623
|
return text;
|
|
866
624
|
}
|
|
867
|
-
|
|
625
|
+
const ansiEscapeCodeForTextColor = TEXT_COLOR_ANSI_CODES[color];
|
|
626
|
+
if (!ansiEscapeCodeForTextColor) {
|
|
627
|
+
return text;
|
|
628
|
+
}
|
|
629
|
+
return `${ansiEscapeCodeForTextColor}${text}${RESET}`;
|
|
630
|
+
},
|
|
631
|
+
backgroundColor: (text, color) => {
|
|
632
|
+
if (!ANSI.supported) {
|
|
633
|
+
return text;
|
|
634
|
+
}
|
|
635
|
+
if (!color) {
|
|
636
|
+
return text;
|
|
637
|
+
}
|
|
638
|
+
if (typeof text === "string" && text.trim() === "") {
|
|
639
|
+
// cannot set background color of blank chars
|
|
640
|
+
return text;
|
|
641
|
+
}
|
|
642
|
+
const ansiEscapeCodeForBackgroundColor =
|
|
643
|
+
BACKGROUND_COLOR_ANSI_CODES[color];
|
|
644
|
+
if (!ansiEscapeCodeForBackgroundColor) {
|
|
645
|
+
return text;
|
|
646
|
+
}
|
|
647
|
+
return `${ansiEscapeCodeForBackgroundColor}${text}${RESET}`;
|
|
868
648
|
},
|
|
869
649
|
|
|
870
650
|
BOLD: "\x1b[1m",
|
|
@@ -881,7 +661,8 @@ const createAnsi = ({ supported }) => {
|
|
|
881
661
|
if (text === "") {
|
|
882
662
|
return text;
|
|
883
663
|
}
|
|
884
|
-
|
|
664
|
+
const ansiEscapeCodeForEffect = effect;
|
|
665
|
+
return `${ansiEscapeCodeForEffect}${text}${RESET}`;
|
|
885
666
|
},
|
|
886
667
|
};
|
|
887
668
|
|
|
@@ -1012,6 +793,23 @@ const setDecimalsPrecision = (
|
|
|
1012
793
|
const asFloat = asInteger / coef;
|
|
1013
794
|
return number < 0 ? -asFloat : asFloat;
|
|
1014
795
|
};
|
|
796
|
+
|
|
797
|
+
// https://www.codingem.com/javascript-how-to-limit-decimal-places/
|
|
798
|
+
// export const roundNumber = (number, maxDecimals) => {
|
|
799
|
+
// const decimalsExp = Math.pow(10, maxDecimals)
|
|
800
|
+
// const numberRoundInt = Math.round(decimalsExp * (number + Number.EPSILON))
|
|
801
|
+
// const numberRoundFloat = numberRoundInt / decimalsExp
|
|
802
|
+
// return numberRoundFloat
|
|
803
|
+
// }
|
|
804
|
+
|
|
805
|
+
// export const setPrecision = (number, precision) => {
|
|
806
|
+
// if (Math.floor(number) === number) return number
|
|
807
|
+
// const [int, decimals] = number.toString().split(".")
|
|
808
|
+
// if (precision <= 0) return int
|
|
809
|
+
// const numberTruncated = `${int}.${decimals.slice(0, precision)}`
|
|
810
|
+
// return numberTruncated
|
|
811
|
+
// }
|
|
812
|
+
|
|
1015
813
|
const unitShort = {
|
|
1016
814
|
year: "y",
|
|
1017
815
|
month: "m",
|
|
@@ -1334,6 +1132,119 @@ const fillLeft$1 = (value, biggestValue, char = " ") => {
|
|
|
1334
1132
|
return padded;
|
|
1335
1133
|
};
|
|
1336
1134
|
|
|
1135
|
+
const createCallOrderer = () => {
|
|
1136
|
+
const queue = [];
|
|
1137
|
+
const callWhenPreviousExecutionAreDone = (executionIndex, callback) => {
|
|
1138
|
+
if (queue[executionIndex]) {
|
|
1139
|
+
throw new Error(`${executionIndex} already used`);
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
let allBeforeAreDone = true;
|
|
1143
|
+
if (executionIndex > 0) {
|
|
1144
|
+
let beforeIndex = executionIndex - 1;
|
|
1145
|
+
do {
|
|
1146
|
+
const value = queue[beforeIndex];
|
|
1147
|
+
if (!value) {
|
|
1148
|
+
allBeforeAreDone = false;
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
} while (beforeIndex--);
|
|
1152
|
+
}
|
|
1153
|
+
if (!allBeforeAreDone) {
|
|
1154
|
+
queue[executionIndex] = callback;
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
queue[executionIndex] = true;
|
|
1158
|
+
callback();
|
|
1159
|
+
let afterIndex = executionIndex + 1;
|
|
1160
|
+
while (afterIndex < queue.length) {
|
|
1161
|
+
const value = queue[afterIndex];
|
|
1162
|
+
if (value === undefined) {
|
|
1163
|
+
break;
|
|
1164
|
+
}
|
|
1165
|
+
if (typeof value === "function") {
|
|
1166
|
+
queue[afterIndex] = true;
|
|
1167
|
+
value();
|
|
1168
|
+
}
|
|
1169
|
+
afterIndex++;
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
return callWhenPreviousExecutionAreDone;
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
const renderBigSection = (params) => {
|
|
1176
|
+
return renderSection({
|
|
1177
|
+
width: 45,
|
|
1178
|
+
...params,
|
|
1179
|
+
});
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
const renderSection = ({
|
|
1183
|
+
title,
|
|
1184
|
+
content,
|
|
1185
|
+
dashColor = ANSI.GREY,
|
|
1186
|
+
width = 38,
|
|
1187
|
+
bottomSeparator = true,
|
|
1188
|
+
}) => {
|
|
1189
|
+
let section = "";
|
|
1190
|
+
|
|
1191
|
+
if (title) {
|
|
1192
|
+
const titleWidth = stripAnsi(title).length;
|
|
1193
|
+
const minWidthRequired = `--- … ---`.length;
|
|
1194
|
+
const needsTruncate = titleWidth + minWidthRequired >= width;
|
|
1195
|
+
if (needsTruncate) {
|
|
1196
|
+
const titleTruncated = title.slice(0, width - minWidthRequired);
|
|
1197
|
+
const leftDashes = ANSI.color("---", dashColor);
|
|
1198
|
+
const rightDashes = ANSI.color("---", dashColor);
|
|
1199
|
+
section += `${leftDashes} ${titleTruncated}… ${rightDashes}`;
|
|
1200
|
+
} else {
|
|
1201
|
+
const remainingWidth = width - titleWidth - 2; // 2 for spaces around the title
|
|
1202
|
+
const dashLeftCount = Math.floor(remainingWidth / 2);
|
|
1203
|
+
const dashRightCount = remainingWidth - dashLeftCount;
|
|
1204
|
+
const leftDashes = ANSI.color("-".repeat(dashLeftCount), dashColor);
|
|
1205
|
+
const rightDashes = ANSI.color("-".repeat(dashRightCount), dashColor);
|
|
1206
|
+
section += `${leftDashes} ${title} ${rightDashes}`;
|
|
1207
|
+
}
|
|
1208
|
+
section += "\n";
|
|
1209
|
+
} else {
|
|
1210
|
+
const topDashes = ANSI.color(`-`.repeat(width), dashColor);
|
|
1211
|
+
section += topDashes;
|
|
1212
|
+
section += "\n";
|
|
1213
|
+
}
|
|
1214
|
+
section += `${content}`;
|
|
1215
|
+
if (bottomSeparator) {
|
|
1216
|
+
section += "\n";
|
|
1217
|
+
const bottomDashes = ANSI.color(`-`.repeat(width), dashColor);
|
|
1218
|
+
section += bottomDashes;
|
|
1219
|
+
}
|
|
1220
|
+
return section;
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
const renderDetails = (data) => {
|
|
1224
|
+
const details = [];
|
|
1225
|
+
for (const key of Object.keys(data)) {
|
|
1226
|
+
const value = data[key];
|
|
1227
|
+
let valueString = "";
|
|
1228
|
+
valueString += ANSI.color(`${key}:`, ANSI.GREY);
|
|
1229
|
+
const useNonGreyAnsiColor =
|
|
1230
|
+
typeof value === "string" && value.includes("\x1b");
|
|
1231
|
+
valueString += " ";
|
|
1232
|
+
valueString += useNonGreyAnsiColor
|
|
1233
|
+
? value
|
|
1234
|
+
: ANSI.color(String(value), ANSI.GREY);
|
|
1235
|
+
details.push(valueString);
|
|
1236
|
+
}
|
|
1237
|
+
if (details.length === 0) {
|
|
1238
|
+
return "";
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
let string = "";
|
|
1242
|
+
string += ` ${ANSI.color("(", ANSI.GREY)}`;
|
|
1243
|
+
string += details.join(ANSI.color(", ", ANSI.GREY));
|
|
1244
|
+
string += ANSI.color(")", ANSI.GREY);
|
|
1245
|
+
return string;
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1337
1248
|
const LOG_LEVEL_OFF = "off";
|
|
1338
1249
|
|
|
1339
1250
|
const LOG_LEVEL_DEBUG = "debug";
|
|
@@ -1457,7 +1368,7 @@ const createDynamicLog = ({
|
|
|
1457
1368
|
const logLines = lastOutput.split(/\r\n|\r|\n/);
|
|
1458
1369
|
let visualLineCount = 0;
|
|
1459
1370
|
for (const logLine of logLines) {
|
|
1460
|
-
const width =
|
|
1371
|
+
const width = measureTextWidth(logLine);
|
|
1461
1372
|
if (width === 0) {
|
|
1462
1373
|
visualLineCount++;
|
|
1463
1374
|
} else {
|
|
@@ -1522,7 +1433,8 @@ const createDynamicLog = ({
|
|
|
1522
1433
|
update("");
|
|
1523
1434
|
|
|
1524
1435
|
writing = true;
|
|
1525
|
-
callback();
|
|
1436
|
+
callback(update);
|
|
1437
|
+
lastOutput = "";
|
|
1526
1438
|
writing = false;
|
|
1527
1439
|
|
|
1528
1440
|
update(ouputAfterCallback);
|
|
@@ -3821,62 +3733,321 @@ const ensureEmptyDirectory = async (source) => {
|
|
|
3821
3733
|
);
|
|
3822
3734
|
};
|
|
3823
3735
|
|
|
3824
|
-
const
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
const
|
|
3829
|
-
|
|
3830
|
-
const fileCoverage = fileByFileCoverage[key];
|
|
3831
|
-
const { path } = fileCoverage;
|
|
3832
|
-
const url = isFileSystemPath(path)
|
|
3833
|
-
? fileSystemPathToUrl(path)
|
|
3834
|
-
: new URL(path, rootDirectoryUrl).href;
|
|
3835
|
-
const relativeUrl = urlToRelativeUrl(url, rootDirectoryUrl);
|
|
3836
|
-
fileByFileNormalized[`./${relativeUrl}`] = {
|
|
3837
|
-
...fileCoverage,
|
|
3838
|
-
path: `./${relativeUrl}`,
|
|
3839
|
-
};
|
|
3840
|
-
});
|
|
3841
|
-
return fileByFileNormalized;
|
|
3736
|
+
const countAvailableCpus = () => {
|
|
3737
|
+
if (typeof availableParallelism === "function") {
|
|
3738
|
+
return availableParallelism();
|
|
3739
|
+
}
|
|
3740
|
+
const cpuArray = cpus();
|
|
3741
|
+
return cpuArray.length || 1;
|
|
3842
3742
|
};
|
|
3843
3743
|
|
|
3844
|
-
const
|
|
3845
|
-
|
|
3846
|
-
const composeTwoFileByFileIstanbulCoverages = (
|
|
3847
|
-
firstFileByFileIstanbulCoverage,
|
|
3848
|
-
secondFileByFileIstanbulCoverage,
|
|
3849
|
-
) => {
|
|
3850
|
-
const fileByFileIstanbulCoverage = {};
|
|
3851
|
-
Object.keys(firstFileByFileIstanbulCoverage).forEach((key) => {
|
|
3852
|
-
fileByFileIstanbulCoverage[key] = firstFileByFileIstanbulCoverage[key];
|
|
3853
|
-
});
|
|
3854
|
-
Object.keys(secondFileByFileIstanbulCoverage).forEach((key) => {
|
|
3855
|
-
const firstCoverage = firstFileByFileIstanbulCoverage[key];
|
|
3856
|
-
const secondCoverage = secondFileByFileIstanbulCoverage[key];
|
|
3857
|
-
fileByFileIstanbulCoverage[key] = firstCoverage
|
|
3858
|
-
? merge(firstCoverage, secondCoverage)
|
|
3859
|
-
: secondCoverage;
|
|
3860
|
-
});
|
|
3861
|
-
|
|
3862
|
-
return fileByFileIstanbulCoverage;
|
|
3863
|
-
};
|
|
3744
|
+
const getAvailableMemory = () => totalmem();
|
|
3864
3745
|
|
|
3865
|
-
const
|
|
3866
|
-
const { createFileCoverage } = importWithRequire("istanbul-lib-coverage");
|
|
3867
|
-
const istanbulFileCoverageObject = createFileCoverage(firstIstanbulCoverage);
|
|
3868
|
-
istanbulFileCoverageObject.merge(secondIstanbulCoverage);
|
|
3869
|
-
const istanbulCoverage = istanbulFileCoverageObject.toJSON();
|
|
3870
|
-
return istanbulCoverage;
|
|
3871
|
-
};
|
|
3746
|
+
const getOsVersion = () => release();
|
|
3872
3747
|
|
|
3873
|
-
|
|
3748
|
+
const startMeasuringTotalCpuUsage = () => {
|
|
3749
|
+
let previousCpuArray = cpus();
|
|
3750
|
+
let previousMs = Date.now();
|
|
3751
|
+
let previousCpuUsage = cpuUsage();
|
|
3874
3752
|
|
|
3875
|
-
const
|
|
3876
|
-
|
|
3877
|
-
|
|
3753
|
+
const overall = {
|
|
3754
|
+
inactive: 100,
|
|
3755
|
+
active: 0,
|
|
3756
|
+
system: 0,
|
|
3757
|
+
user: 0,
|
|
3758
|
+
};
|
|
3759
|
+
const thisProcess = {
|
|
3760
|
+
active: 0,
|
|
3761
|
+
system: 0,
|
|
3762
|
+
user: 0,
|
|
3763
|
+
};
|
|
3764
|
+
const details = previousCpuArray.map(() => {
|
|
3765
|
+
return {
|
|
3766
|
+
inactive: 100,
|
|
3767
|
+
active: 0,
|
|
3768
|
+
system: 0,
|
|
3769
|
+
user: 0,
|
|
3770
|
+
};
|
|
3771
|
+
});
|
|
3878
3772
|
|
|
3879
|
-
|
|
3773
|
+
const samples = [];
|
|
3774
|
+
const interval = setInterval(() => {
|
|
3775
|
+
let cpuArray = cpus();
|
|
3776
|
+
const ms = Date.now();
|
|
3777
|
+
const ellapsedMs = ms - previousMs;
|
|
3778
|
+
const cpuUsageSampleArray = [];
|
|
3779
|
+
let overallSystemMs = 0;
|
|
3780
|
+
let overallUserMs = 0;
|
|
3781
|
+
let overallInactiveMs = 0;
|
|
3782
|
+
let overallActiveMs = 0;
|
|
3783
|
+
let overallMsEllapsed = 0;
|
|
3784
|
+
let index = 0;
|
|
3785
|
+
for (const cpu of cpuArray) {
|
|
3786
|
+
const previousCpuTimes = previousCpuArray[index].times;
|
|
3787
|
+
const cpuTimes = cpu.times;
|
|
3788
|
+
const systemMs = cpuTimes.sys - previousCpuTimes.sys;
|
|
3789
|
+
const userMs = cpuTimes.user - previousCpuTimes.user;
|
|
3790
|
+
const activeMs = systemMs + userMs;
|
|
3791
|
+
const inactiveMs = ellapsedMs - activeMs;
|
|
3792
|
+
const cpuUsageSample = {
|
|
3793
|
+
inactive: inactiveMs / ellapsedMs,
|
|
3794
|
+
active: activeMs / ellapsedMs,
|
|
3795
|
+
system: systemMs / ellapsedMs,
|
|
3796
|
+
user: userMs / ellapsedMs,
|
|
3797
|
+
};
|
|
3798
|
+
cpuUsageSampleArray.push(cpuUsageSample);
|
|
3799
|
+
|
|
3800
|
+
overallSystemMs += systemMs;
|
|
3801
|
+
overallUserMs += userMs;
|
|
3802
|
+
overallInactiveMs += inactiveMs;
|
|
3803
|
+
overallActiveMs += activeMs;
|
|
3804
|
+
overallMsEllapsed += ellapsedMs;
|
|
3805
|
+
index++;
|
|
3806
|
+
}
|
|
3807
|
+
const overallUsageSample = {
|
|
3808
|
+
inactive: overallInactiveMs / overallMsEllapsed,
|
|
3809
|
+
active: overallActiveMs / overallMsEllapsed,
|
|
3810
|
+
system: overallSystemMs / overallMsEllapsed,
|
|
3811
|
+
user: overallUserMs / overallMsEllapsed,
|
|
3812
|
+
};
|
|
3813
|
+
previousCpuArray = cpuArray;
|
|
3814
|
+
previousMs = ms;
|
|
3815
|
+
|
|
3816
|
+
const processCpuUsage = cpuUsage();
|
|
3817
|
+
const thisProcessSystemMs = Math.round(
|
|
3818
|
+
(processCpuUsage.system - previousCpuUsage.system) / 1000,
|
|
3819
|
+
);
|
|
3820
|
+
const thisProcessUserMs = Math.round(
|
|
3821
|
+
(processCpuUsage.user - previousCpuUsage.user) / 1000,
|
|
3822
|
+
);
|
|
3823
|
+
previousCpuUsage = processCpuUsage;
|
|
3824
|
+
|
|
3825
|
+
const thisProcessActiveMs = thisProcessSystemMs + thisProcessUserMs;
|
|
3826
|
+
const thisProcessInactiveMs = overallMsEllapsed - thisProcessActiveMs;
|
|
3827
|
+
const thisProcessSample = {
|
|
3828
|
+
inactive: thisProcessInactiveMs / overallMsEllapsed,
|
|
3829
|
+
active: thisProcessActiveMs / overallMsEllapsed,
|
|
3830
|
+
system: thisProcessSystemMs / overallMsEllapsed,
|
|
3831
|
+
user: thisProcessUserMs / overallMsEllapsed,
|
|
3832
|
+
};
|
|
3833
|
+
samples.push({
|
|
3834
|
+
cpuUsageSampleArray,
|
|
3835
|
+
overallUsageSample,
|
|
3836
|
+
thisProcessSample,
|
|
3837
|
+
});
|
|
3838
|
+
if (samples.length === 10) {
|
|
3839
|
+
{
|
|
3840
|
+
let index = 0;
|
|
3841
|
+
for (const detail of details) {
|
|
3842
|
+
let systemSum = 0;
|
|
3843
|
+
let userSum = 0;
|
|
3844
|
+
let inactiveSum = 0;
|
|
3845
|
+
let activeSum = 0;
|
|
3846
|
+
for (const sample of samples) {
|
|
3847
|
+
const { cpuUsageSampleArray } = sample;
|
|
3848
|
+
const cpuUsageSample = cpuUsageSampleArray[index];
|
|
3849
|
+
inactiveSum += cpuUsageSample.inactive;
|
|
3850
|
+
activeSum += cpuUsageSample.active;
|
|
3851
|
+
systemSum += cpuUsageSample.system;
|
|
3852
|
+
userSum += cpuUsageSample.user;
|
|
3853
|
+
}
|
|
3854
|
+
Object.assign(detail, {
|
|
3855
|
+
inactive: inactiveSum / samples.length,
|
|
3856
|
+
active: activeSum / samples.length,
|
|
3857
|
+
system: systemSum / samples.length,
|
|
3858
|
+
user: userSum / samples.length,
|
|
3859
|
+
});
|
|
3860
|
+
index++;
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
{
|
|
3864
|
+
let overallSystemSum = 0;
|
|
3865
|
+
let overallUserSum = 0;
|
|
3866
|
+
let overallInactiveSum = 0;
|
|
3867
|
+
let overallActiveSum = 0;
|
|
3868
|
+
for (const sample of samples) {
|
|
3869
|
+
const { overallUsageSample } = sample;
|
|
3870
|
+
overallSystemSum += overallUsageSample.system;
|
|
3871
|
+
overallUserSum += overallUsageSample.user;
|
|
3872
|
+
overallInactiveSum += overallUsageSample.inactive;
|
|
3873
|
+
overallActiveSum += overallUsageSample.active;
|
|
3874
|
+
}
|
|
3875
|
+
Object.assign(overall, {
|
|
3876
|
+
inactive: overallInactiveSum / samples.length,
|
|
3877
|
+
active: overallActiveSum / samples.length,
|
|
3878
|
+
system: overallSystemSum / samples.length,
|
|
3879
|
+
user: overallUserSum / samples.length,
|
|
3880
|
+
});
|
|
3881
|
+
}
|
|
3882
|
+
{
|
|
3883
|
+
let thisProcessSystemSum = 0;
|
|
3884
|
+
let thisProcessUserSum = 0;
|
|
3885
|
+
let thisProcessInactiveSum = 0;
|
|
3886
|
+
let thisProcessActiveSum = 0;
|
|
3887
|
+
for (const sample of samples) {
|
|
3888
|
+
const { thisProcessSample } = sample;
|
|
3889
|
+
thisProcessSystemSum += thisProcessSample.system;
|
|
3890
|
+
thisProcessUserSum += thisProcessSample.user;
|
|
3891
|
+
thisProcessInactiveSum += thisProcessSample.inactive;
|
|
3892
|
+
thisProcessActiveSum += thisProcessSample.active;
|
|
3893
|
+
}
|
|
3894
|
+
Object.assign(thisProcess, {
|
|
3895
|
+
inactive: thisProcessInactiveSum / samples.length,
|
|
3896
|
+
active: thisProcessActiveSum / samples.length,
|
|
3897
|
+
system: thisProcessSystemSum / samples.length,
|
|
3898
|
+
user: thisProcessUserSum / samples.length,
|
|
3899
|
+
});
|
|
3900
|
+
}
|
|
3901
|
+
samples.length = 0;
|
|
3902
|
+
}
|
|
3903
|
+
}, 15);
|
|
3904
|
+
interval.unref();
|
|
3905
|
+
|
|
3906
|
+
return {
|
|
3907
|
+
overall,
|
|
3908
|
+
thisProcess,
|
|
3909
|
+
details,
|
|
3910
|
+
stop: () => {
|
|
3911
|
+
clearInterval(interval);
|
|
3912
|
+
},
|
|
3913
|
+
};
|
|
3914
|
+
};
|
|
3915
|
+
|
|
3916
|
+
const startMonitoringMetric = (measure) => {
|
|
3917
|
+
const metrics = [];
|
|
3918
|
+
const takeMeasure = () => {
|
|
3919
|
+
const value = measure();
|
|
3920
|
+
metrics.push(value);
|
|
3921
|
+
return value;
|
|
3922
|
+
};
|
|
3923
|
+
|
|
3924
|
+
const info = {
|
|
3925
|
+
start: takeMeasure(),
|
|
3926
|
+
min: null,
|
|
3927
|
+
max: null,
|
|
3928
|
+
median: null,
|
|
3929
|
+
end: null,
|
|
3930
|
+
};
|
|
3931
|
+
return {
|
|
3932
|
+
info,
|
|
3933
|
+
measure: takeMeasure,
|
|
3934
|
+
end: () => {
|
|
3935
|
+
info.end = takeMeasure();
|
|
3936
|
+
metrics.sort((a, b) => a - b);
|
|
3937
|
+
info.min = metrics[0];
|
|
3938
|
+
info.max = metrics[metrics.length - 1];
|
|
3939
|
+
info.median = medianFromSortedArray(metrics);
|
|
3940
|
+
metrics.length = 0;
|
|
3941
|
+
},
|
|
3942
|
+
};
|
|
3943
|
+
};
|
|
3944
|
+
|
|
3945
|
+
const medianFromSortedArray = (array) => {
|
|
3946
|
+
const length = array.length;
|
|
3947
|
+
const isOdd = length % 2 === 1;
|
|
3948
|
+
if (isOdd) {
|
|
3949
|
+
const medianNumberIndex = (length - 1) / 2;
|
|
3950
|
+
const medianNumber = array[medianNumberIndex];
|
|
3951
|
+
return medianNumber;
|
|
3952
|
+
}
|
|
3953
|
+
const rightMiddleNumberIndex = length / 2;
|
|
3954
|
+
const leftMiddleNumberIndex = rightMiddleNumberIndex - 1;
|
|
3955
|
+
const leftMiddleNumber = array[leftMiddleNumberIndex];
|
|
3956
|
+
const rightMiddleNumber = array[rightMiddleNumberIndex];
|
|
3957
|
+
const medianNumber = (leftMiddleNumber + rightMiddleNumber) / 2;
|
|
3958
|
+
return medianNumber;
|
|
3959
|
+
};
|
|
3960
|
+
|
|
3961
|
+
// https://gist.github.com/GaetanoPiazzolla/c40e1ebb9f709d091208e89baf9f4e00
|
|
3962
|
+
|
|
3963
|
+
|
|
3964
|
+
const startMonitoringCpuUsage = () => {
|
|
3965
|
+
const cpuUsage = startMeasuringTotalCpuUsage();
|
|
3966
|
+
const processCpuUsageMonitoring = startMonitoringMetric(() => {
|
|
3967
|
+
return cpuUsage.thisProcess.active;
|
|
3968
|
+
});
|
|
3969
|
+
const osCpuUsageMonitoring = startMonitoringMetric(() => {
|
|
3970
|
+
return cpuUsage.overall.active;
|
|
3971
|
+
});
|
|
3972
|
+
const result = [processCpuUsageMonitoring, osCpuUsageMonitoring];
|
|
3973
|
+
result.stop = cpuUsage.stop;
|
|
3974
|
+
return result;
|
|
3975
|
+
};
|
|
3976
|
+
|
|
3977
|
+
const startMonitoringMemoryUsage = () => {
|
|
3978
|
+
const processMemoryUsageMonitoring = startMonitoringMetric(() => {
|
|
3979
|
+
return memoryUsage().rss;
|
|
3980
|
+
});
|
|
3981
|
+
const osMemoryUsageMonitoring = startMonitoringMetric(() => {
|
|
3982
|
+
const total = totalmem();
|
|
3983
|
+
const free = freemem();
|
|
3984
|
+
return total - free;
|
|
3985
|
+
});
|
|
3986
|
+
const stop = () => {
|
|
3987
|
+
processMemoryUsageMonitoring.stop();
|
|
3988
|
+
osMemoryUsageMonitoring.stop();
|
|
3989
|
+
};
|
|
3990
|
+
const result = [processMemoryUsageMonitoring, osMemoryUsageMonitoring];
|
|
3991
|
+
result.stop = stop;
|
|
3992
|
+
return result;
|
|
3993
|
+
};
|
|
3994
|
+
|
|
3995
|
+
const normalizeFileByFileCoveragePaths = (
|
|
3996
|
+
fileByFileCoverage,
|
|
3997
|
+
rootDirectoryUrl,
|
|
3998
|
+
) => {
|
|
3999
|
+
const fileByFileNormalized = {};
|
|
4000
|
+
Object.keys(fileByFileCoverage).forEach((key) => {
|
|
4001
|
+
const fileCoverage = fileByFileCoverage[key];
|
|
4002
|
+
const { path } = fileCoverage;
|
|
4003
|
+
const url = isFileSystemPath(path)
|
|
4004
|
+
? fileSystemPathToUrl(path)
|
|
4005
|
+
: new URL(path, rootDirectoryUrl).href;
|
|
4006
|
+
const relativeUrl = urlToRelativeUrl(url, rootDirectoryUrl);
|
|
4007
|
+
fileByFileNormalized[`./${relativeUrl}`] = {
|
|
4008
|
+
...fileCoverage,
|
|
4009
|
+
path: `./${relativeUrl}`,
|
|
4010
|
+
};
|
|
4011
|
+
});
|
|
4012
|
+
return fileByFileNormalized;
|
|
4013
|
+
};
|
|
4014
|
+
|
|
4015
|
+
const importWithRequire = createRequire(import.meta.url);
|
|
4016
|
+
|
|
4017
|
+
const composeTwoFileByFileIstanbulCoverages = (
|
|
4018
|
+
firstFileByFileIstanbulCoverage,
|
|
4019
|
+
secondFileByFileIstanbulCoverage,
|
|
4020
|
+
) => {
|
|
4021
|
+
const fileByFileIstanbulCoverage = {};
|
|
4022
|
+
Object.keys(firstFileByFileIstanbulCoverage).forEach((key) => {
|
|
4023
|
+
fileByFileIstanbulCoverage[key] = firstFileByFileIstanbulCoverage[key];
|
|
4024
|
+
});
|
|
4025
|
+
Object.keys(secondFileByFileIstanbulCoverage).forEach((key) => {
|
|
4026
|
+
const firstCoverage = firstFileByFileIstanbulCoverage[key];
|
|
4027
|
+
const secondCoverage = secondFileByFileIstanbulCoverage[key];
|
|
4028
|
+
fileByFileIstanbulCoverage[key] = firstCoverage
|
|
4029
|
+
? merge(firstCoverage, secondCoverage)
|
|
4030
|
+
: secondCoverage;
|
|
4031
|
+
});
|
|
4032
|
+
|
|
4033
|
+
return fileByFileIstanbulCoverage;
|
|
4034
|
+
};
|
|
4035
|
+
|
|
4036
|
+
const merge = (firstIstanbulCoverage, secondIstanbulCoverage) => {
|
|
4037
|
+
const { createFileCoverage } = importWithRequire("istanbul-lib-coverage");
|
|
4038
|
+
const istanbulFileCoverageObject = createFileCoverage(firstIstanbulCoverage);
|
|
4039
|
+
istanbulFileCoverageObject.merge(secondIstanbulCoverage);
|
|
4040
|
+
const istanbulCoverage = istanbulFileCoverageObject.toJSON();
|
|
4041
|
+
return istanbulCoverage;
|
|
4042
|
+
};
|
|
4043
|
+
|
|
4044
|
+
// https://github.com/istanbuljs/babel-plugin-istanbul/blob/321740f7b25d803f881466ea819d870f7ed6a254/src/index.js
|
|
4045
|
+
|
|
4046
|
+
const babelPluginInstrument = (api, { useInlineSourceMaps = false }) => {
|
|
4047
|
+
const { programVisitor } = importWithRequire("istanbul-lib-instrument");
|
|
4048
|
+
const { types } = api;
|
|
4049
|
+
|
|
4050
|
+
return {
|
|
3880
4051
|
name: "transform-instrument",
|
|
3881
4052
|
visitor: {
|
|
3882
4053
|
Program: {
|
|
@@ -4389,285 +4560,74 @@ const generateCoverage = async (
|
|
|
4389
4560
|
rootDirectoryUrl,
|
|
4390
4561
|
),
|
|
4391
4562
|
);
|
|
4392
|
-
}
|
|
4393
|
-
|
|
4394
|
-
return fileByFileCoverage;
|
|
4395
|
-
};
|
|
4396
|
-
|
|
4397
|
-
const getCoverageFromTestPlanResults = async (
|
|
4398
|
-
executionResults,
|
|
4399
|
-
{ signal, onMissing },
|
|
4400
|
-
) => {
|
|
4401
|
-
const operation = Abort.startOperation();
|
|
4402
|
-
operation.addAbortSignal(signal);
|
|
4403
|
-
|
|
4404
|
-
try {
|
|
4405
|
-
let v8Coverage;
|
|
4406
|
-
let fileByFileIstanbulCoverage;
|
|
4407
|
-
|
|
4408
|
-
// collect v8 and istanbul coverage from executions
|
|
4409
|
-
for (const file of Object.keys(executionResults)) {
|
|
4410
|
-
const executionResultForFile = executionResults[file];
|
|
4411
|
-
for (const executionName of Object.keys(executionResultForFile)) {
|
|
4412
|
-
operation.throwIfAborted();
|
|
4413
|
-
|
|
4414
|
-
const executionResultForFileOnRuntime =
|
|
4415
|
-
executionResultForFile[executionName];
|
|
4416
|
-
const { coverageFileUrl } = executionResultForFileOnRuntime;
|
|
4417
|
-
let executionCoverage;
|
|
4418
|
-
try {
|
|
4419
|
-
executionCoverage = JSON.parse(
|
|
4420
|
-
String(readFileSync(new URL(coverageFileUrl))),
|
|
4421
|
-
);
|
|
4422
|
-
} catch (e) {
|
|
4423
|
-
if (e.code === "ENOENT" || e.name === "SyntaxError") {
|
|
4424
|
-
onMissing({
|
|
4425
|
-
executionName,
|
|
4426
|
-
file,
|
|
4427
|
-
executionResult: executionResultForFileOnRuntime,
|
|
4428
|
-
});
|
|
4429
|
-
continue;
|
|
4430
|
-
}
|
|
4431
|
-
throw e;
|
|
4432
|
-
}
|
|
4433
|
-
|
|
4434
|
-
if (isV8Coverage(executionCoverage)) {
|
|
4435
|
-
v8Coverage = v8Coverage
|
|
4436
|
-
? composeTwoV8Coverages(v8Coverage, executionCoverage)
|
|
4437
|
-
: executionCoverage;
|
|
4438
|
-
} else {
|
|
4439
|
-
fileByFileIstanbulCoverage = fileByFileIstanbulCoverage
|
|
4440
|
-
? composeTwoFileByFileIstanbulCoverages(
|
|
4441
|
-
fileByFileIstanbulCoverage,
|
|
4442
|
-
executionCoverage,
|
|
4443
|
-
)
|
|
4444
|
-
: executionCoverage;
|
|
4445
|
-
}
|
|
4446
|
-
}
|
|
4447
|
-
}
|
|
4448
|
-
|
|
4449
|
-
return {
|
|
4450
|
-
v8Coverage,
|
|
4451
|
-
fileByFileIstanbulCoverage,
|
|
4452
|
-
};
|
|
4453
|
-
} finally {
|
|
4454
|
-
await operation.end();
|
|
4455
|
-
}
|
|
4456
|
-
};
|
|
4457
|
-
|
|
4458
|
-
const isV8Coverage = (coverage) => Boolean(coverage.result);
|
|
4459
|
-
|
|
4460
|
-
const createCallOrderer = () => {
|
|
4461
|
-
const queue = [];
|
|
4462
|
-
const callWhenPreviousExecutionAreDone = (executionIndex, callback) => {
|
|
4463
|
-
if (queue[executionIndex]) {
|
|
4464
|
-
throw new Error(`${executionIndex} already used`);
|
|
4465
|
-
}
|
|
4466
|
-
|
|
4467
|
-
let allBeforeAreDone = true;
|
|
4468
|
-
if (executionIndex > 0) {
|
|
4469
|
-
let beforeIndex = executionIndex - 1;
|
|
4470
|
-
do {
|
|
4471
|
-
const value = queue[beforeIndex];
|
|
4472
|
-
if (!value) {
|
|
4473
|
-
allBeforeAreDone = false;
|
|
4474
|
-
break;
|
|
4475
|
-
}
|
|
4476
|
-
} while (beforeIndex--);
|
|
4477
|
-
}
|
|
4478
|
-
if (!allBeforeAreDone) {
|
|
4479
|
-
queue[executionIndex] = callback;
|
|
4480
|
-
return;
|
|
4481
|
-
}
|
|
4482
|
-
queue[executionIndex] = true;
|
|
4483
|
-
callback();
|
|
4484
|
-
let afterIndex = executionIndex + 1;
|
|
4485
|
-
while (afterIndex < queue.length) {
|
|
4486
|
-
const value = queue[afterIndex];
|
|
4487
|
-
if (value === undefined) {
|
|
4488
|
-
break;
|
|
4489
|
-
}
|
|
4490
|
-
if (typeof value === "function") {
|
|
4491
|
-
queue[afterIndex] = true;
|
|
4492
|
-
value();
|
|
4493
|
-
}
|
|
4494
|
-
afterIndex++;
|
|
4495
|
-
}
|
|
4496
|
-
};
|
|
4497
|
-
return callWhenPreviousExecutionAreDone;
|
|
4498
|
-
};
|
|
4499
|
-
|
|
4500
|
-
// https://gist.github.com/GaetanoPiazzolla/c40e1ebb9f709d091208e89baf9f4e00
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
const startMeasuringTotalCpuUsage = () => {
|
|
4504
|
-
let previousCpuArray = cpus();
|
|
4505
|
-
let previousMs = Date.now();
|
|
4506
|
-
let previousCpuUsage = cpuUsage();
|
|
4507
|
-
|
|
4508
|
-
const overall = {
|
|
4509
|
-
inactive: 100,
|
|
4510
|
-
active: 0,
|
|
4511
|
-
system: 0,
|
|
4512
|
-
user: 0,
|
|
4513
|
-
};
|
|
4514
|
-
const thisProcess = {
|
|
4515
|
-
active: 0,
|
|
4516
|
-
system: 0,
|
|
4517
|
-
user: 0,
|
|
4518
|
-
};
|
|
4519
|
-
const details = previousCpuArray.map(() => {
|
|
4520
|
-
return {
|
|
4521
|
-
inactive: 100,
|
|
4522
|
-
active: 0,
|
|
4523
|
-
system: 0,
|
|
4524
|
-
user: 0,
|
|
4525
|
-
};
|
|
4526
|
-
});
|
|
4527
|
-
|
|
4528
|
-
const samples = [];
|
|
4529
|
-
const interval = setInterval(() => {
|
|
4530
|
-
let cpuArray = cpus();
|
|
4531
|
-
const ms = Date.now();
|
|
4532
|
-
const ellapsedMs = ms - previousMs;
|
|
4533
|
-
const cpuUsageSampleArray = [];
|
|
4534
|
-
let overallSystemMs = 0;
|
|
4535
|
-
let overallUserMs = 0;
|
|
4536
|
-
let overallInactiveMs = 0;
|
|
4537
|
-
let overallActiveMs = 0;
|
|
4538
|
-
let overallMsEllapsed = 0;
|
|
4539
|
-
let index = 0;
|
|
4540
|
-
for (const cpu of cpuArray) {
|
|
4541
|
-
const previousCpuTimes = previousCpuArray[index].times;
|
|
4542
|
-
const cpuTimes = cpu.times;
|
|
4543
|
-
const systemMs = cpuTimes.sys - previousCpuTimes.sys;
|
|
4544
|
-
const userMs = cpuTimes.user - previousCpuTimes.user;
|
|
4545
|
-
const activeMs = systemMs + userMs;
|
|
4546
|
-
const inactiveMs = ellapsedMs - activeMs;
|
|
4547
|
-
const cpuUsageSample = {
|
|
4548
|
-
inactive: inactiveMs / ellapsedMs,
|
|
4549
|
-
active: activeMs / ellapsedMs,
|
|
4550
|
-
system: systemMs / ellapsedMs,
|
|
4551
|
-
user: userMs / ellapsedMs,
|
|
4552
|
-
};
|
|
4553
|
-
cpuUsageSampleArray.push(cpuUsageSample);
|
|
4554
|
-
|
|
4555
|
-
overallSystemMs += systemMs;
|
|
4556
|
-
overallUserMs += userMs;
|
|
4557
|
-
overallInactiveMs += inactiveMs;
|
|
4558
|
-
overallActiveMs += activeMs;
|
|
4559
|
-
overallMsEllapsed += ellapsedMs;
|
|
4560
|
-
index++;
|
|
4561
|
-
}
|
|
4562
|
-
const overallUsageSample = {
|
|
4563
|
-
inactive: overallInactiveMs / overallMsEllapsed,
|
|
4564
|
-
active: overallActiveMs / overallMsEllapsed,
|
|
4565
|
-
system: overallSystemMs / overallMsEllapsed,
|
|
4566
|
-
user: overallUserMs / overallMsEllapsed,
|
|
4567
|
-
};
|
|
4568
|
-
previousCpuArray = cpuArray;
|
|
4569
|
-
previousMs = ms;
|
|
4570
|
-
|
|
4571
|
-
const processCpuUsage = cpuUsage();
|
|
4572
|
-
const thisProcessSystemMs = Math.round(
|
|
4573
|
-
(processCpuUsage.system - previousCpuUsage.system) / 1000,
|
|
4574
|
-
);
|
|
4575
|
-
const thisProcessUserMs = Math.round(
|
|
4576
|
-
(processCpuUsage.user - previousCpuUsage.user) / 1000,
|
|
4577
|
-
);
|
|
4578
|
-
previousCpuUsage = processCpuUsage;
|
|
4579
|
-
|
|
4580
|
-
const thisProcessActiveMs = thisProcessSystemMs + thisProcessUserMs;
|
|
4581
|
-
const thisProcessInactiveMs = overallMsEllapsed - thisProcessActiveMs;
|
|
4582
|
-
const thisProcessSample = {
|
|
4583
|
-
inactive: thisProcessInactiveMs / overallMsEllapsed,
|
|
4584
|
-
active: thisProcessActiveMs / overallMsEllapsed,
|
|
4585
|
-
system: thisProcessSystemMs / overallMsEllapsed,
|
|
4586
|
-
user: thisProcessUserMs / overallMsEllapsed,
|
|
4587
|
-
};
|
|
4588
|
-
samples.push({
|
|
4589
|
-
cpuUsageSampleArray,
|
|
4590
|
-
overallUsageSample,
|
|
4591
|
-
thisProcessSample,
|
|
4592
|
-
});
|
|
4593
|
-
if (samples.length === 10) {
|
|
4594
|
-
{
|
|
4595
|
-
let index = 0;
|
|
4596
|
-
for (const detail of details) {
|
|
4597
|
-
let systemSum = 0;
|
|
4598
|
-
let userSum = 0;
|
|
4599
|
-
let inactiveSum = 0;
|
|
4600
|
-
let activeSum = 0;
|
|
4601
|
-
for (const sample of samples) {
|
|
4602
|
-
const { cpuUsageSampleArray } = sample;
|
|
4603
|
-
const cpuUsageSample = cpuUsageSampleArray[index];
|
|
4604
|
-
inactiveSum += cpuUsageSample.inactive;
|
|
4605
|
-
activeSum += cpuUsageSample.active;
|
|
4606
|
-
systemSum += cpuUsageSample.system;
|
|
4607
|
-
userSum += cpuUsageSample.user;
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4565
|
+
return fileByFileCoverage;
|
|
4566
|
+
};
|
|
4567
|
+
|
|
4568
|
+
const getCoverageFromTestPlanResults = async (
|
|
4569
|
+
executionResults,
|
|
4570
|
+
{ signal, onMissing },
|
|
4571
|
+
) => {
|
|
4572
|
+
const operation = Abort.startOperation();
|
|
4573
|
+
operation.addAbortSignal(signal);
|
|
4574
|
+
|
|
4575
|
+
try {
|
|
4576
|
+
let v8Coverage;
|
|
4577
|
+
let fileByFileIstanbulCoverage;
|
|
4578
|
+
|
|
4579
|
+
// collect v8 and istanbul coverage from executions
|
|
4580
|
+
for (const file of Object.keys(executionResults)) {
|
|
4581
|
+
const executionResultForFile = executionResults[file];
|
|
4582
|
+
for (const executionName of Object.keys(executionResultForFile)) {
|
|
4583
|
+
operation.throwIfAborted();
|
|
4584
|
+
|
|
4585
|
+
const executionResultForFileOnRuntime =
|
|
4586
|
+
executionResultForFile[executionName];
|
|
4587
|
+
const { coverageFileUrl } = executionResultForFileOnRuntime;
|
|
4588
|
+
let executionCoverage;
|
|
4589
|
+
try {
|
|
4590
|
+
executionCoverage = JSON.parse(
|
|
4591
|
+
String(readFileSync(new URL(coverageFileUrl))),
|
|
4592
|
+
);
|
|
4593
|
+
} catch (e) {
|
|
4594
|
+
if (e.code === "ENOENT" || e.name === "SyntaxError") {
|
|
4595
|
+
onMissing({
|
|
4596
|
+
executionName,
|
|
4597
|
+
file,
|
|
4598
|
+
executionResult: executionResultForFileOnRuntime,
|
|
4599
|
+
});
|
|
4600
|
+
continue;
|
|
4608
4601
|
}
|
|
4609
|
-
|
|
4610
|
-
inactive: inactiveSum / samples.length,
|
|
4611
|
-
active: activeSum / samples.length,
|
|
4612
|
-
system: systemSum / samples.length,
|
|
4613
|
-
user: userSum / samples.length,
|
|
4614
|
-
});
|
|
4615
|
-
index++;
|
|
4616
|
-
}
|
|
4617
|
-
}
|
|
4618
|
-
{
|
|
4619
|
-
let overallSystemSum = 0;
|
|
4620
|
-
let overallUserSum = 0;
|
|
4621
|
-
let overallInactiveSum = 0;
|
|
4622
|
-
let overallActiveSum = 0;
|
|
4623
|
-
for (const sample of samples) {
|
|
4624
|
-
const { overallUsageSample } = sample;
|
|
4625
|
-
overallSystemSum += overallUsageSample.system;
|
|
4626
|
-
overallUserSum += overallUsageSample.user;
|
|
4627
|
-
overallInactiveSum += overallUsageSample.inactive;
|
|
4628
|
-
overallActiveSum += overallUsageSample.active;
|
|
4602
|
+
throw e;
|
|
4629
4603
|
}
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
}
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
for (const sample of samples) {
|
|
4643
|
-
const { thisProcessSample } = sample;
|
|
4644
|
-
thisProcessSystemSum += thisProcessSample.system;
|
|
4645
|
-
thisProcessUserSum += thisProcessSample.user;
|
|
4646
|
-
thisProcessInactiveSum += thisProcessSample.inactive;
|
|
4647
|
-
thisProcessActiveSum += thisProcessSample.active;
|
|
4604
|
+
|
|
4605
|
+
if (isV8Coverage(executionCoverage)) {
|
|
4606
|
+
v8Coverage = v8Coverage
|
|
4607
|
+
? composeTwoV8Coverages(v8Coverage, executionCoverage)
|
|
4608
|
+
: executionCoverage;
|
|
4609
|
+
} else {
|
|
4610
|
+
fileByFileIstanbulCoverage = fileByFileIstanbulCoverage
|
|
4611
|
+
? composeTwoFileByFileIstanbulCoverages(
|
|
4612
|
+
fileByFileIstanbulCoverage,
|
|
4613
|
+
executionCoverage,
|
|
4614
|
+
)
|
|
4615
|
+
: executionCoverage;
|
|
4648
4616
|
}
|
|
4649
|
-
Object.assign(thisProcess, {
|
|
4650
|
-
inactive: thisProcessInactiveSum / samples.length,
|
|
4651
|
-
active: thisProcessActiveSum / samples.length,
|
|
4652
|
-
system: thisProcessSystemSum / samples.length,
|
|
4653
|
-
user: thisProcessUserSum / samples.length,
|
|
4654
|
-
});
|
|
4655
4617
|
}
|
|
4656
|
-
samples.length = 0;
|
|
4657
4618
|
}
|
|
4658
|
-
}, 15);
|
|
4659
|
-
interval.unref();
|
|
4660
4619
|
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
};
|
|
4620
|
+
return {
|
|
4621
|
+
v8Coverage,
|
|
4622
|
+
fileByFileIstanbulCoverage,
|
|
4623
|
+
};
|
|
4624
|
+
} finally {
|
|
4625
|
+
await operation.end();
|
|
4626
|
+
}
|
|
4669
4627
|
};
|
|
4670
4628
|
|
|
4629
|
+
const isV8Coverage = (coverage) => Boolean(coverage.result);
|
|
4630
|
+
|
|
4671
4631
|
const githubAnnotationFromError = (
|
|
4672
4632
|
error,
|
|
4673
4633
|
{ rootDirectoryUrl, execution },
|
|
@@ -5955,79 +5915,6 @@ const renderStatusRepartition = (counters, { showProgression } = {}) => {
|
|
|
5955
5915
|
return `${parts.join(", ")}`;
|
|
5956
5916
|
};
|
|
5957
5917
|
|
|
5958
|
-
const renderBigSection = (params) => {
|
|
5959
|
-
return renderSection({
|
|
5960
|
-
width: 45,
|
|
5961
|
-
...params,
|
|
5962
|
-
});
|
|
5963
|
-
};
|
|
5964
|
-
|
|
5965
|
-
const renderSection = ({
|
|
5966
|
-
title,
|
|
5967
|
-
content,
|
|
5968
|
-
dashColor = ANSI.GREY,
|
|
5969
|
-
width = 38,
|
|
5970
|
-
bottomSeparator = true,
|
|
5971
|
-
}) => {
|
|
5972
|
-
let section = "";
|
|
5973
|
-
|
|
5974
|
-
if (title) {
|
|
5975
|
-
const titleWidth = stripAnsi(title).length;
|
|
5976
|
-
const minWidthRequired = `--- … ---`.length;
|
|
5977
|
-
const needsTruncate = titleWidth + minWidthRequired >= width;
|
|
5978
|
-
if (needsTruncate) {
|
|
5979
|
-
const titleTruncated = title.slice(0, width - minWidthRequired);
|
|
5980
|
-
const leftDashes = ANSI.color("---", dashColor);
|
|
5981
|
-
const rightDashes = ANSI.color("---", dashColor);
|
|
5982
|
-
section += `${leftDashes} ${titleTruncated}… ${rightDashes}`;
|
|
5983
|
-
} else {
|
|
5984
|
-
const remainingWidth = width - titleWidth - 2; // 2 for spaces around the title
|
|
5985
|
-
const dashLeftCount = Math.floor(remainingWidth / 2);
|
|
5986
|
-
const dashRightCount = remainingWidth - dashLeftCount;
|
|
5987
|
-
const leftDashes = ANSI.color("-".repeat(dashLeftCount), dashColor);
|
|
5988
|
-
const rightDashes = ANSI.color("-".repeat(dashRightCount), dashColor);
|
|
5989
|
-
section += `${leftDashes} ${title} ${rightDashes}`;
|
|
5990
|
-
}
|
|
5991
|
-
section += "\n";
|
|
5992
|
-
} else {
|
|
5993
|
-
const topDashes = ANSI.color(`-`.repeat(width), dashColor);
|
|
5994
|
-
section += topDashes;
|
|
5995
|
-
section += "\n";
|
|
5996
|
-
}
|
|
5997
|
-
section += `${content}`;
|
|
5998
|
-
if (bottomSeparator) {
|
|
5999
|
-
section += "\n";
|
|
6000
|
-
const bottomDashes = ANSI.color(`-`.repeat(width), dashColor);
|
|
6001
|
-
section += bottomDashes;
|
|
6002
|
-
}
|
|
6003
|
-
return section;
|
|
6004
|
-
};
|
|
6005
|
-
|
|
6006
|
-
const renderDetails = (data) => {
|
|
6007
|
-
const details = [];
|
|
6008
|
-
for (const key of Object.keys(data)) {
|
|
6009
|
-
const value = data[key];
|
|
6010
|
-
let valueString = "";
|
|
6011
|
-
valueString += ANSI.color(`${key}:`, ANSI.GREY);
|
|
6012
|
-
const useNonGreyAnsiColor =
|
|
6013
|
-
typeof value === "string" && value.includes("\x1b");
|
|
6014
|
-
valueString += " ";
|
|
6015
|
-
valueString += useNonGreyAnsiColor
|
|
6016
|
-
? value
|
|
6017
|
-
: ANSI.color(String(value), ANSI.GREY);
|
|
6018
|
-
details.push(valueString);
|
|
6019
|
-
}
|
|
6020
|
-
if (details.length === 0) {
|
|
6021
|
-
return "";
|
|
6022
|
-
}
|
|
6023
|
-
|
|
6024
|
-
let string = "";
|
|
6025
|
-
string += ` ${ANSI.color("(", ANSI.GREY)}`;
|
|
6026
|
-
string += details.join(ANSI.color(", ", ANSI.GREY));
|
|
6027
|
-
string += ANSI.color(")", ANSI.GREY);
|
|
6028
|
-
return string;
|
|
6029
|
-
};
|
|
6030
|
-
|
|
6031
5918
|
/*
|
|
6032
5919
|
* Export a function capable to run a file on a runtime.
|
|
6033
5920
|
*
|
|
@@ -6731,22 +6618,12 @@ const executeTestPlan = async ({
|
|
|
6731
6618
|
});
|
|
6732
6619
|
}
|
|
6733
6620
|
|
|
6734
|
-
const
|
|
6735
|
-
operation.addEndCallback(
|
|
6736
|
-
const processCpuUsageMonitoring =
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
return cpuUsage.overall.active;
|
|
6741
|
-
});
|
|
6742
|
-
const processMemoryUsageMonitoring = startMonitoringMetric(() => {
|
|
6743
|
-
return memoryUsage().rss;
|
|
6744
|
-
});
|
|
6745
|
-
const osMemoryUsageMonitoring = startMonitoringMetric(() => {
|
|
6746
|
-
const total = totalmem();
|
|
6747
|
-
const free = freemem();
|
|
6748
|
-
return total - free;
|
|
6749
|
-
});
|
|
6621
|
+
const cpuMonitoring = startMonitoringCpuUsage();
|
|
6622
|
+
operation.addEndCallback(cpuMonitoring.stop);
|
|
6623
|
+
const [processCpuUsageMonitoring, osCpuUsageMonitoring] = cpuMonitoring;
|
|
6624
|
+
const memoryMonitoring = startMonitoringMemoryUsage();
|
|
6625
|
+
const [processMemoryUsageMonitoring, osMemoryUsageMonitoring] =
|
|
6626
|
+
memoryMonitoring;
|
|
6750
6627
|
|
|
6751
6628
|
const timingsOrigin = Date.now();
|
|
6752
6629
|
const takeTiming = () => {
|
|
@@ -6762,9 +6639,9 @@ const executeTestPlan = async ({
|
|
|
6762
6639
|
: process.platform === "linux"
|
|
6763
6640
|
? "linux"
|
|
6764
6641
|
: "other",
|
|
6765
|
-
version:
|
|
6642
|
+
version: getOsVersion(),
|
|
6766
6643
|
availableCpu: countAvailableCpus(),
|
|
6767
|
-
availableMemory:
|
|
6644
|
+
availableMemory: getAvailableMemory(),
|
|
6768
6645
|
},
|
|
6769
6646
|
runtime: {
|
|
6770
6647
|
name: "node",
|
|
@@ -7731,59 +7608,6 @@ To fix this warning:
|
|
|
7731
7608
|
return testPlanResult;
|
|
7732
7609
|
};
|
|
7733
7610
|
|
|
7734
|
-
const startMonitoringMetric = (measure) => {
|
|
7735
|
-
const metrics = [];
|
|
7736
|
-
const takeMeasure = () => {
|
|
7737
|
-
const value = measure();
|
|
7738
|
-
metrics.push(value);
|
|
7739
|
-
return value;
|
|
7740
|
-
};
|
|
7741
|
-
|
|
7742
|
-
const info = {
|
|
7743
|
-
start: takeMeasure(),
|
|
7744
|
-
min: null,
|
|
7745
|
-
max: null,
|
|
7746
|
-
median: null,
|
|
7747
|
-
end: null,
|
|
7748
|
-
};
|
|
7749
|
-
return {
|
|
7750
|
-
info,
|
|
7751
|
-
measure: takeMeasure,
|
|
7752
|
-
end: () => {
|
|
7753
|
-
info.end = takeMeasure();
|
|
7754
|
-
metrics.sort((a, b) => a - b);
|
|
7755
|
-
info.min = metrics[0];
|
|
7756
|
-
info.max = metrics[metrics.length - 1];
|
|
7757
|
-
info.median = medianFromSortedArray(metrics);
|
|
7758
|
-
metrics.length = 0;
|
|
7759
|
-
},
|
|
7760
|
-
};
|
|
7761
|
-
};
|
|
7762
|
-
|
|
7763
|
-
const medianFromSortedArray = (array) => {
|
|
7764
|
-
const length = array.length;
|
|
7765
|
-
const isOdd = length % 2 === 1;
|
|
7766
|
-
if (isOdd) {
|
|
7767
|
-
const medianNumberIndex = (length - 1) / 2;
|
|
7768
|
-
const medianNumber = array[medianNumberIndex];
|
|
7769
|
-
return medianNumber;
|
|
7770
|
-
}
|
|
7771
|
-
const rightMiddleNumberIndex = length / 2;
|
|
7772
|
-
const leftMiddleNumberIndex = rightMiddleNumberIndex - 1;
|
|
7773
|
-
const leftMiddleNumber = array[leftMiddleNumberIndex];
|
|
7774
|
-
const rightMiddleNumber = array[rightMiddleNumberIndex];
|
|
7775
|
-
const medianNumber = (leftMiddleNumber + rightMiddleNumber) / 2;
|
|
7776
|
-
return medianNumber;
|
|
7777
|
-
};
|
|
7778
|
-
|
|
7779
|
-
const countAvailableCpus = () => {
|
|
7780
|
-
if (typeof availableParallelism === "function") {
|
|
7781
|
-
return availableParallelism();
|
|
7782
|
-
}
|
|
7783
|
-
const cpuArray = cpus();
|
|
7784
|
-
return cpuArray.length || 1;
|
|
7785
|
-
};
|
|
7786
|
-
|
|
7787
7611
|
const mutateCountersBeforeExecutionStarts = (counters) => {
|
|
7788
7612
|
counters.executing++;
|
|
7789
7613
|
counters.waiting--;
|