@jsenv/test 3.5.1 → 3.5.3

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.
@@ -5464,7 +5464,7 @@ const pingServer = async (url) => {
5464
5464
 
5465
5465
  const startServerUsingCommand = async (
5466
5466
  webServer,
5467
- { signal, allocatedMs, logger, teardownCallbackSet },
5467
+ { signal, allocatedMs, logger, teardownCallbackSet, shell = true },
5468
5468
  ) => {
5469
5469
  const spawnedProcess = spawn(webServer.command, [], {
5470
5470
  // On non-windows platforms, `detached: true` makes child process a leader of a new
@@ -5472,7 +5472,7 @@ const startServerUsingCommand = async (
5472
5472
  // @see https://nodejs.org/api/child_process.html#child_process_options_detached
5473
5473
  detached: process.platform !== "win32",
5474
5474
  stdio: ["pipe", "pipe", "pipe"],
5475
- shell: true,
5475
+ shell,
5476
5476
  cwd: webServer.cwd,
5477
5477
  });
5478
5478
  if (!spawnedProcess.pid) {
@@ -5499,13 +5499,28 @@ const startServerUsingCommand = async (
5499
5499
  // stderr.on("line", (data) => {
5500
5500
  // logger.debug(`[pid=${spawnedProcess.pid}][err] ${data}`);
5501
5501
  // });
5502
+ let isAbort = false;
5503
+ let isTeardown = false;
5502
5504
  let processClosed = false;
5505
+ let stderr = "";
5506
+ spawnedProcess.stderr.on("data", (data) => {
5507
+ stderr += String(data);
5508
+ });
5503
5509
  const closedPromise = new Promise((resolve) => {
5504
5510
  spawnedProcess.once("exit", (exitCode, signal) => {
5505
- logger.debug(
5506
- `[pid=${spawnedProcess.pid}] <process did exit: exitCode=${exitCode}, signal=${signal}>`,
5507
- );
5508
5511
  processClosed = true;
5512
+ if (isAbort || isTeardown) {
5513
+ logger.debug(
5514
+ `web server process exit exitCode=${exitCode}, exitSignal=${signal}, pid=${spawnedProcess.pid}`,
5515
+ );
5516
+ } else {
5517
+ logger.error(
5518
+ `web server process premature exit exitCode=${exitCode}, exitSignal=${signal}, pid=${spawnedProcess.pid}
5519
+ --- stderr ---
5520
+ ${stderr}
5521
+ --------------`,
5522
+ );
5523
+ }
5509
5524
  resolve();
5510
5525
  });
5511
5526
  });
@@ -5550,8 +5565,14 @@ const startServerUsingCommand = async (
5550
5565
  const startOperation = Abort.startOperation();
5551
5566
  startOperation.addAbortSignal(signal);
5552
5567
  const timeoutAbortSource = startOperation.timeout(allocatedMs);
5553
- startOperation.addAbortCallback(killProcess);
5554
- teardownCallbackSet.add(killProcess);
5568
+ startOperation.addAbortCallback(async () => {
5569
+ isAbort = true;
5570
+ await killProcess();
5571
+ });
5572
+ teardownCallbackSet.add(async () => {
5573
+ isTeardown = true;
5574
+ await killProcess();
5575
+ });
5555
5576
 
5556
5577
  const startedPromise = (async () => {
5557
5578
  const logScale = [100, 250, 500];
@@ -5598,7 +5619,8 @@ const startServerUsingModuleUrl = async (webServer, params) => {
5598
5619
  return startServerUsingCommand(
5599
5620
  {
5600
5621
  ...webServer,
5601
- command: `node ${fileURLToPath(webServer.moduleUrl)}`,
5622
+ command: `node ${fileURLToPath(webServer.moduleUrl)} --jsenv-test`,
5623
+ shell: false,
5602
5624
  },
5603
5625
  params,
5604
5626
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/test",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,7 +4,7 @@ import { pingServer } from "../../helpers/ping_server.js";
4
4
 
5
5
  export const startServerUsingCommand = async (
6
6
  webServer,
7
- { signal, allocatedMs, logger, teardownCallbackSet },
7
+ { signal, allocatedMs, logger, teardownCallbackSet, shell = true },
8
8
  ) => {
9
9
  const spawnedProcess = spawn(webServer.command, [], {
10
10
  // On non-windows platforms, `detached: true` makes child process a leader of a new
@@ -12,7 +12,7 @@ export const startServerUsingCommand = async (
12
12
  // @see https://nodejs.org/api/child_process.html#child_process_options_detached
13
13
  detached: process.platform !== "win32",
14
14
  stdio: ["pipe", "pipe", "pipe"],
15
- shell: true,
15
+ shell,
16
16
  cwd: webServer.cwd,
17
17
  });
18
18
  if (!spawnedProcess.pid) {
@@ -39,13 +39,28 @@ export const startServerUsingCommand = async (
39
39
  // stderr.on("line", (data) => {
40
40
  // logger.debug(`[pid=${spawnedProcess.pid}][err] ${data}`);
41
41
  // });
42
+ let isAbort = false;
43
+ let isTeardown = false;
42
44
  let processClosed = false;
45
+ let stderr = "";
46
+ spawnedProcess.stderr.on("data", (data) => {
47
+ stderr += String(data);
48
+ });
43
49
  const closedPromise = new Promise((resolve) => {
44
50
  spawnedProcess.once("exit", (exitCode, signal) => {
45
- logger.debug(
46
- `[pid=${spawnedProcess.pid}] <process did exit: exitCode=${exitCode}, signal=${signal}>`,
47
- );
48
51
  processClosed = true;
52
+ if (isAbort || isTeardown) {
53
+ logger.debug(
54
+ `web server process exit exitCode=${exitCode}, exitSignal=${signal}, pid=${spawnedProcess.pid}`,
55
+ );
56
+ } else {
57
+ logger.error(
58
+ `web server process premature exit exitCode=${exitCode}, exitSignal=${signal}, pid=${spawnedProcess.pid}
59
+ --- stderr ---
60
+ ${stderr}
61
+ --------------`,
62
+ );
63
+ }
49
64
  resolve();
50
65
  });
51
66
  });
@@ -90,8 +105,14 @@ export const startServerUsingCommand = async (
90
105
  const startOperation = Abort.startOperation();
91
106
  startOperation.addAbortSignal(signal);
92
107
  const timeoutAbortSource = startOperation.timeout(allocatedMs);
93
- startOperation.addAbortCallback(killProcess);
94
- teardownCallbackSet.add(killProcess);
108
+ startOperation.addAbortCallback(async () => {
109
+ isAbort = true;
110
+ await killProcess();
111
+ });
112
+ teardownCallbackSet.add(async () => {
113
+ isTeardown = true;
114
+ await killProcess();
115
+ });
95
116
 
96
117
  const startedPromise = (async () => {
97
118
  const logScale = [100, 250, 500];
@@ -10,7 +10,8 @@ export const startServerUsingModuleUrl = async (webServer, params) => {
10
10
  return startServerUsingCommand(
11
11
  {
12
12
  ...webServer,
13
- command: `node ${fileURLToPath(webServer.moduleUrl)}`,
13
+ command: `node ${fileURLToPath(webServer.moduleUrl)} --jsenv-test`,
14
+ shell: false,
14
15
  },
15
16
  params,
16
17
  );
@@ -1,5 +1,4 @@
1
1
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
2
-
3
2
  import { basicFetch } from "../helpers/basic_fetch.js";
4
3
  import { pingServer } from "../helpers/ping_server.js";
5
4
  import { startServerUsingCommand } from "./web_server/start_using_command.js";