@naturalcycles/dev-lib 19.12.0 → 19.12.2

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.
@@ -1,5 +1,7 @@
1
1
  export class CollectReporter {
2
- constructor(cfg = {}) { this.cfg = cfg }
2
+ constructor(cfg = {}) {
3
+ this.cfg = cfg
4
+ }
3
5
 
4
6
  onTestModuleEnd(testModule) {
5
7
  const { threshold = 0 } = this.cfg
@@ -1,3 +1,4 @@
1
+ import { red } from '@naturalcycles/nodejs-lib/colors';
1
2
  import createMitm from 'mitm';
2
3
  const LOCAL_HOSTS = ['localhost', '127.0.0.1'];
3
4
  const detectLeaks = process.argv.some(a => a.includes('detectLeaks'));
@@ -6,17 +7,18 @@ let mitm;
6
7
  * Based on: https://github.com/palmerj3/jest-offline/blob/master/index.js
7
8
  */
8
9
  export function testOffline() {
10
+ if (mitm)
11
+ return; // already applied
9
12
  if (detectLeaks) {
10
13
  console.log('NOT applying testOffline() when --detectLeaks is on');
11
14
  return;
12
15
  }
13
- console.log('test offline mode');
14
- mitm ||= createMitm();
16
+ mitm = createMitm();
15
17
  mitm.on('connect', (socket, opts) => {
16
18
  const { host } = opts;
17
19
  if (!LOCAL_HOSTS.includes(host)) {
18
- process.stderr.write(`Network request forbidden by testOffline(): ${host}\n`);
19
- throw new Error(`Network request forbidden by testOffline(): ${host}`);
20
+ process.stderr.write(red(`Network request forbidden by testOffline: ${host}\n`));
21
+ throw new Error(`Network request forbidden by testOffline: ${host}`);
20
22
  }
21
23
  socket.bypass();
22
24
  });
@@ -26,4 +28,5 @@ export function testOffline() {
26
28
  */
27
29
  export function testOnline() {
28
30
  mitm?.disable();
31
+ mitm = undefined;
29
32
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
3
  "type": "module",
4
- "version": "19.12.0",
4
+ "version": "19.12.2",
5
5
  "dependencies": {
6
6
  "@biomejs/biome": "^2",
7
7
  "@commitlint/cli": "^19",