11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
51cb0ef41Sopenharmony_ciconst { isMainThread, Worker } = require('worker_threads');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst inspector = require('inspector');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciif (!isMainThread) {
101cb0ef41Sopenharmony_ci  // Verify the inspector api on the worker thread.
111cb0ef41Sopenharmony_ci  assert.strictEqual(inspector.url(), undefined);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  inspector.open(0, undefined, false);
141cb0ef41Sopenharmony_ci  const wsUrl = inspector.url();
151cb0ef41Sopenharmony_ci  assert(wsUrl.startsWith('ws://'));
161cb0ef41Sopenharmony_ci  inspector.close();
171cb0ef41Sopenharmony_ci  assert.strictEqual(inspector.url(), undefined);
181cb0ef41Sopenharmony_ci  return;
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// Open inspector on the main thread first.
221cb0ef41Sopenharmony_ciinspector.open(0, undefined, false);
231cb0ef41Sopenharmony_ciconst wsUrl = inspector.url();
241cb0ef41Sopenharmony_ciassert(wsUrl.startsWith('ws://'));
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciconst worker = new Worker(__filename);
271cb0ef41Sopenharmony_ciworker.on('exit', common.mustCall((code) => {
281cb0ef41Sopenharmony_ci  assert.strictEqual(code, 0);
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  // Verify inspector on the main thread is still active.
311cb0ef41Sopenharmony_ci  assert.strictEqual(inspector.url(), wsUrl);
321cb0ef41Sopenharmony_ci  inspector.close();
331cb0ef41Sopenharmony_ci  assert.strictEqual(inspector.url(), undefined);
341cb0ef41Sopenharmony_ci}));
35