summaryrefslogtreecommitdiff
path: root/tests/node_compat
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-09-12 12:24:58 -0700
committerGitHub <noreply@github.com>2024-09-12 19:24:58 +0000
commit18b89d948dcb849c4dc577478794c3d5fb23b597 (patch)
tree9945567e4b53dc50d2a61a3149b51edf97c05839 /tests/node_compat
parent3f15e300625723df10c564c4e29ec276288a931b (diff)
fix(ext/node): Implement detached option in `child_process` (#25218)
Fixes https://github.com/denoland/deno/issues/25193.
Diffstat (limited to 'tests/node_compat')
-rw-r--r--tests/node_compat/config.jsonc4
-rw-r--r--tests/node_compat/test/fixtures/child-process-persistent.js8
-rw-r--r--tests/node_compat/test/fixtures/parent-process-nonpersistent.js21
-rw-r--r--tests/node_compat/test/parallel/test-child-process-detached.js52
4 files changed, 85 insertions, 0 deletions
diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc
index 8c8d503d5..01db5557d 100644
--- a/tests/node_compat/config.jsonc
+++ b/tests/node_compat/config.jsonc
@@ -8,6 +8,7 @@
"elipses.txt",
"empty.txt",
"exit.js",
+ "parent-process-nonpersistent.js",
"print-chars.js",
"x.txt"
],
@@ -25,6 +26,7 @@
"test-buffer-from.js",
"test-buffer-includes.js",
"test-buffer-indexof.js",
+ "test-child-process-detached.js",
"test-child-process-exec-abortcontroller-promisified.js",
"test-child-process-exec-encoding.js",
"test-child-process-exec-kill-throws.js",
@@ -135,6 +137,7 @@
"fixtures": [
"a.js",
"child_process_should_emit_error.js",
+ "child-process-persistent.js",
"child-process-spawn-node.js",
"echo.js",
"elipses.txt",
@@ -766,6 +769,7 @@
},
"windowsIgnore": {
"parallel": [
+ "test-child-process-detached.js",
"test-child-process-exec-abortcontroller-promisified.js",
"test-console-log-throw-primitive.js",
"test-console-no-swallow-stack-overflow.js",
diff --git a/tests/node_compat/test/fixtures/child-process-persistent.js b/tests/node_compat/test/fixtures/child-process-persistent.js
new file mode 100644
index 000000000..520c4bebc
--- /dev/null
+++ b/tests/node_compat/test/fixtures/child-process-persistent.js
@@ -0,0 +1,8 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+setInterval(function() {}, 9999);
diff --git a/tests/node_compat/test/fixtures/parent-process-nonpersistent.js b/tests/node_compat/test/fixtures/parent-process-nonpersistent.js
new file mode 100644
index 000000000..537478aac
--- /dev/null
+++ b/tests/node_compat/test/fixtures/parent-process-nonpersistent.js
@@ -0,0 +1,21 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+// Modified to add `runner.ts` to inject `require` into subprocess
+
+const spawn = require('child_process').spawn,
+ path = require('path'),
+ childPath = path.join(__dirname, 'child-process-persistent.js');
+
+var child = spawn(process.execPath, [ childPath ], {
+ detached: true,
+ stdio: 'ignore'
+});
+
+console.log(child.pid);
+
+child.unref();
diff --git a/tests/node_compat/test/parallel/test-child-process-detached.js b/tests/node_compat/test/parallel/test-child-process-detached.js
new file mode 100644
index 000000000..65ec20753
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-child-process-detached.js
@@ -0,0 +1,52 @@
+// deno-fmt-ignore-file
+// deno-lint-ignore-file
+
+// Copyright Joyent and Node contributors. All rights reserved. MIT license.
+// Taken from Node 18.12.1
+// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
+
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// Modified to add `runner.ts` to inject `require` into subprocess
+
+'use strict';
+require('../common');
+const assert = require('assert');
+const fixtures = require('../common/fixtures');
+
+const spawn = require('child_process').spawn;
+const childPath = fixtures.path('parent-process-nonpersistent.js');
+let persistentPid = -1;
+
+const child = spawn(process.execPath, [ "runner.ts", childPath ]);
+
+child.stdout.on('data', function(data) {
+ persistentPid = parseInt(data, 10);
+});
+
+process.on('exit', function() {
+ assert.notStrictEqual(persistentPid, -1);
+ assert.throws(function() {
+ process.kill(child.pid);
+ }, /^Error: kill ESRCH$/);
+ process.kill(persistentPid);
+});