diff options
Diffstat (limited to 'test/parallel/test-child-process-advanced-serialization.js')
-rw-r--r-- | test/parallel/test-child-process-advanced-serialization.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-advanced-serialization.js b/test/parallel/test-child-process-advanced-serialization.js new file mode 100644 index 0000000000..0424f14a06 --- /dev/null +++ b/test/parallel/test-child-process-advanced-serialization.js @@ -0,0 +1,46 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const child_process = require('child_process'); +const { once } = require('events'); + +if (process.argv[2] !== 'child') { + for (const value of [null, 42, Infinity, 'foo']) { + common.expectsError(() => { + child_process.spawn(process.execPath, [], { serialization: value }); + }, { + code: 'ERR_INVALID_OPT_VALUE', + message: `The value "${value}" is invalid ` + + 'for option "options.serialization"' + }); + } + + (async () => { + const cp = child_process.spawn(process.execPath, [__filename, 'child'], + { + stdio: ['ipc', 'inherit', 'inherit'], + serialization: 'advanced' + }); + + const circular = {}; + circular.circular = circular; + for await (const message of [ + { uint8: new Uint8Array(4) }, + { float64: new Float64Array([ Math.PI ]) }, + { buffer: Buffer.from('Hello!') }, + { map: new Map([{ a: 1 }, { b: 2 }]) }, + { bigInt: 1337n }, + circular, + new Error('Something went wrong'), + new RangeError('Something range-y went wrong'), + ]) { + cp.send(message); + const [ received ] = await once(cp, 'message'); + assert.deepStrictEqual(received, message); + } + + cp.disconnect(); + })().then(common.mustCall()); +} else { + process.on('message', (msg) => process.send(msg)); +} |