Sha256: b70425ca86f94ce7ae9ed7c483bbc131a21b1b32cb3f7981229ff0f8bd4e998f

Contents?: true

Size: 1.7 KB

Versions: 26

Compression:

Stored size: 1.7 KB

Contents

import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';

const __require = createRequire(import.meta.url);
let inspector;
let session;
function setupInspect(ctx) {
  const config = ctx.config;
  const isEnabled = config.inspector.enabled;
  if (isEnabled) {
    inspector = __require("node:inspector");
    const isOpen = inspector.url() !== void 0;
    if (!isOpen) {
      inspector.open(
        config.inspector.port,
        config.inspector.host,
        config.inspector.waitForDebugger
      );
      if (config.inspectBrk) {
        const firstTestFile = ctx.files[0];
        if (firstTestFile) {
          session = new inspector.Session();
          session.connect();
          session.post("Debugger.enable");
          session.post("Debugger.setBreakpointByUrl", {
            lineNumber: 0,
            url: pathToFileURL(firstTestFile)
          });
        }
      }
    }
  }
  const keepOpen = shouldKeepOpen(config);
  return function cleanup() {
    if (isEnabled && !keepOpen && inspector) {
      inspector.close();
      session?.disconnect();
    }
  };
}
function closeInspector(config) {
  const keepOpen = shouldKeepOpen(config);
  if (inspector && !keepOpen) {
    inspector.close();
    session?.disconnect();
  }
}
function shouldKeepOpen(config) {
  const isIsolatedSingleThread = config.pool === "threads" && config.poolOptions?.threads?.isolate === false && config.poolOptions?.threads?.singleThread;
  const isIsolatedSingleFork = config.pool === "forks" && config.poolOptions?.forks?.isolate === false && config.poolOptions?.forks?.singleFork;
  return config.watch && (isIsolatedSingleFork || isIsolatedSingleThread);
}

export { closeInspector as c, setupInspect as s };

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/vitest/dist/chunks/inspector.70d6emsh.js