@naturalcycles/dev-lib 13.24.0 → 13.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,8 +42,9 @@ async function runJest(opt = {}) {
42
42
  console.log((0, colors_1.dimGrey)(`node_modules/${(0, colors_1.white)('jest')} not found, skipping tests`));
43
43
  return;
44
44
  }
45
- const { CI, CIRCLECI, TZ = 'UTC', APP_ENV, JEST_NO_ALPHABETIC, JEST_SHARDS, NODE_OPTIONS = 'not defined', } = process.env;
45
+ const { CI, CIRCLECI, CPU_LIMIT, TZ = 'UTC', APP_ENV, JEST_NO_ALPHABETIC, JEST_SHARDS, NODE_OPTIONS = 'not defined', } = process.env;
46
46
  const { node } = process.versions;
47
+ const cpuLimit = Number(CPU_LIMIT) || undefined;
47
48
  const { integration, manual, leaks } = opt;
48
49
  const processArgs = process.argv.slice(2);
49
50
  let jestConfig;
@@ -75,13 +76,18 @@ async function runJest(opt = {}) {
75
76
  // Coverage only makes sense for unit tests, not for integration/manual
76
77
  args.push('--coverage');
77
78
  }
78
- if (CIRCLECI) {
79
- // We used to default to 2, but due to memory being an issue for Jest - now we default to 1,
80
- // as it's the most memory-efficient way
81
- // Since `workerIdleMemoryLimit` was introduced by default - we're changing default back to 2 workers
82
- // We now only do it for CircleCI (not for CI in general), as it reports cpus as 36
83
- // Github Actions don't do that and report correct number of cpus
84
- maxWorkers ||= '--maxWorkers=2';
79
+ if (!maxWorkers) {
80
+ if (cpuLimit && cpuLimit > 1) {
81
+ maxWorkers = `--maxWorkers=${cpuLimit - 1}`;
82
+ }
83
+ else if (CIRCLECI) {
84
+ // We used to default to 2, but due to memory being an issue for Jest - now we default to 1,
85
+ // as it's the most memory-efficient way
86
+ // Since `workerIdleMemoryLimit` was introduced by default - we're changing default back to 2 workers
87
+ // We now only do it for CircleCI (not for CI in general), as it reports cpus as 36
88
+ // Github Actions don't do that and report correct number of cpus
89
+ maxWorkers = '--maxWorkers=2';
90
+ }
85
91
  }
86
92
  }
87
93
  // Running all tests - will use `--silent` to suppress console-logs, will also set process.env.JEST_SILENT=1
@@ -107,9 +113,17 @@ async function runJest(opt = {}) {
107
113
  if (!JEST_NO_ALPHABETIC) {
108
114
  args.push(`--testSequencer=${paths_cnst_1.cfgDir}/jest.alphabetic.sequencer.js`);
109
115
  }
110
- const par = os.availableParallelism?.();
116
+ const availableParallelism = os.availableParallelism?.();
111
117
  const cpus = os.cpus().length;
112
- console.log(`${(0, colors_1.dimGrey)(`node ${node}, NODE_OPTIONS: ${NODE_OPTIONS}, cpus: ${cpus}, availableParallelism: ${par}`)}`);
118
+ console.log(`${(0, colors_1.dimGrey)(Object.entries({
119
+ node,
120
+ NODE_OPTIONS,
121
+ cpus,
122
+ availableParallelism,
123
+ cpuLimit,
124
+ })
125
+ .map(([k, v]) => `${k}: ${v}`)
126
+ .join(', '))}`);
113
127
  if (JEST_SHARDS) {
114
128
  const totalShards = Number(JEST_SHARDS);
115
129
  const shards = (0, js_lib_1._range)(1, totalShards + 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "13.24.0",
3
+ "version": "13.25.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "tsn-debug": "tsn testScript.ts",