reference.js
This file
Path
test/ipc/reference.js
129 lines · 4.7 KiB · JavaScript
Last changed by
Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6
History of this fileTake it
Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 1–8why, one step back1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {PARALLEL_COUNT} from '../helpers/parallel.js';67setFixtureDirectory();8Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6
line 9why, one step back9const testReference = async (t, fixtureName) => {Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 10–13why, one step back10 const {timedOut} = await t.throwsAsync(execa(fixtureName, {ipc: true, timeout: 1e3}));11 t.true(timedOut);12};13Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6
lines 14–23why, one step back14test('exports.getOneMessage() keeps the subprocess alive', testReference, 'ipc-get-ref.js');15test('exports.getEachMessage() keeps the subprocess alive', testReference, 'ipc-iterate-ref.js');1617const testUnreference = async (t, fixtureName) => {18 const {ipcOutput} = await execa(fixtureName, {ipc: true});19 t.deepEqual(ipcOutput, []);20};2122test('exports.getOneMessage() does not keep the subprocess alive, reference false', testUnreference, 'ipc-get-unref.js');23test('exports.getEachMessage() does not keep the subprocess alive, reference false', testUnreference, 'ipc-iterate-unref.js');Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 24–37why, one step back2425test('exports.sendMessage() keeps the subprocess alive', async t => {26 const {ipcOutput} = await execa('ipc-send-repeat.js', [`${PARALLEL_COUNT}`], {ipc: true});27 const expectedOutput = Array.from({length: PARALLEL_COUNT}, (_, index) => index);28 t.deepEqual(ipcOutput, expectedOutput);29});3031test('process.send() keeps the subprocess alive', async t => {32 const {ipcOutput, stdout} = await execa('ipc-process-send.js', {ipc: true});33 t.deepEqual(ipcOutput, [foobarString]);34 t.is(stdout, '.');35});3637test('process.send() keeps the subprocess alive, after getOneMessage()', async t => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 38why, one step back38 const {ipcOutput, stdout} = await execa('ipc-process-send-get.js', {ipcInput: 0});Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 39–110why, one step back39 t.deepEqual(ipcOutput, [foobarString]);40 t.is(stdout, '.');41});4243test('process.send() keeps the subprocess alive, after sendMessage()', async t => {44 const {ipcOutput, stdout} = await execa('ipc-process-send-send.js', {ipc: true});45 t.deepEqual(ipcOutput, ['.', foobarString]);46 t.is(stdout, '.');47});4849test('process.once("message") keeps the subprocess alive', async t => {50 const subprocess = execa('ipc-once-message.js', {ipc: true});51 t.is(await subprocess.getOneMessage(), '.');52 await subprocess.sendMessage(foobarString);5354 const {ipcOutput, stdout} = await subprocess;55 t.deepEqual(ipcOutput, ['.']);56 t.is(stdout, foobarString);57});5859test('process.once("message") keeps the subprocess alive, after sendMessage()', async t => {60 const subprocess = execa('ipc-once-message-send.js', {ipc: true});61 t.is(await subprocess.getOneMessage(), '.');62 await subprocess.sendMessage(foobarString);6364 const {ipcOutput, stdout} = await subprocess;65 t.deepEqual(ipcOutput, ['.']);66 t.is(stdout, foobarString);67});6869test('process.once("message") keeps the subprocess alive, after getOneMessage()', async t => {70 const subprocess = execa('ipc-once-message-get.js', {ipc: true});71 await subprocess.sendMessage('.');72 t.is(await subprocess.getOneMessage(), '.');73 await subprocess.sendMessage(foobarString);7475 const {ipcOutput, stdout} = await subprocess;76 t.deepEqual(ipcOutput, ['.']);77 t.is(stdout, foobarString);78});7980test('process.once("disconnect") keeps the subprocess alive', async t => {81 const subprocess = execa('ipc-once-disconnect.js', {ipc: true});82 t.is(await subprocess.getOneMessage(), '.');83 subprocess.disconnect();8485 const {ipcOutput, stdout} = await subprocess;86 t.deepEqual(ipcOutput, ['.']);87 t.is(stdout, '.');88});8990test('process.once("disconnect") keeps the subprocess alive, after sendMessage()', async t => {91 const subprocess = execa('ipc-once-disconnect-send.js', {ipc: true});92 t.is(await subprocess.getOneMessage(), '.');93 t.is(await subprocess.getOneMessage(), '.');94 subprocess.disconnect();9596 const {ipcOutput, stdout} = await subprocess;97 t.deepEqual(ipcOutput, ['.', '.']);98 t.is(stdout, '.');99});100101test('process.once("disconnect") does not keep the subprocess alive, after getOneMessage()', async t => {102 const subprocess = execa('ipc-once-disconnect-get.js', {ipc: true});103 await subprocess.sendMessage('.');104 t.is(await subprocess.getOneMessage(), '.');105 subprocess.disconnect();106107 const {ipcOutput, stdout} = await subprocess;108 t.deepEqual(ipcOutput, ['.']);109 t.is(stdout, '.');110});Refactor reference counting with IPC (#1089)ehmickybefore adoption18e607c
lines 111–129why, one step back111112test('Can call subprocess.disconnect() right away', async t => {113 const subprocess = execa('ipc-send.js', {ipc: true});114 subprocess.disconnect();115 t.is(subprocess.channel, null);116117 await t.throwsAsync(subprocess.getOneMessage(), {118 message: /subprocess.getOneMessage\(\) could not complete/,119 });120 await t.throwsAsync(subprocess, {121 message: /Error: sendMessage\(\) cannot be used/,122 });123});124125test('Can call process.disconnect() right away', async t => {126 const {stdout, stderr} = await t.throwsAsync(execa('ipc-disconnect-get.js', {ipc: true}));127 t.is(stdout, 'null');128 t.true(stderr.includes('Error: getOneMessage() cannot be used'));129});