Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ const baseOpen = async options => {
if (!options.wait) {
// PowerShell will keep the parent process alive unless stdio is ignored.
childProcessOptions.stdio = 'ignore';
childProcessOptions.detached = true;
childProcessOptions.windowsHide = true;
}
} else {
if (app) {
Expand Down
42 changes: 42 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,48 @@ test('subprocess is spawned before promise resolves', async t => {
t.true(childProcess.pid !== undefined && childProcess.pid !== null);
});

test.serial('detaches PowerShell launches when not waiting on Windows', async t => {
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform');
const originalSpawn = childProcess.spawn;

t.teardown(() => {
Object.defineProperty(process, 'platform', originalPlatform);
childProcess.spawn = originalSpawn;
});

Object.defineProperty(process, 'platform', {value: 'win32'});

let childProcessOptions;
let unrefCalled = false;

childProcess.spawn = (...arguments_) => {
childProcessOptions = arguments_[2];

// eslint-disable-next-line unicorn/prefer-event-target
const fakeChild = new EventEmitter();
fakeChild.unref = () => {
unrefCalled = true;
};

setImmediate(() => {
fakeChild.emit('spawn');
});

return fakeChild;
};

const {default: windowsOpen} = await import(`./index.js?windows-detach=${Date.now()}`);
await windowsOpen('C:/coverage/index.html');

t.like(childProcessOptions, {
windowsVerbatimArguments: true,
stdio: 'ignore',
detached: true,
windowsHide: true,
});
t.true(unrefCalled);
});

test.serial('app launches resolve before close without fallback', async t => {
const originalSpawn = childProcess.spawn;
t.teardown(() => {
Expand Down