Skip to content

Commit

Permalink
feat: update Node.js version requirement for serialization
Browse files Browse the repository at this point in the history
>= v12.16.0 < v13.0.0, or >= v13.2.0
  • Loading branch information
waitingsong committed Feb 14, 2020
1 parent 097dd0a commit 4179e83
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
7 changes: 5 additions & 2 deletions lib/master.js
Expand Up @@ -38,7 +38,7 @@ class Master extends EventEmitter {
* - {Object} [https] https options, { key, cert, ca }, full path
* - {Array|String} [require] will inject into worker/agent process
* - {String} [pidFile] will save master pid to this file
* - {json|advanced} [serialization] Advanced serialization for IPC since Node.js v12.16.0,
* - {json|advanced} [serialization] Advanced serialization for IPC need Node.js >= v12.16.0 or >= v13.2.0,
* see: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V12.md#advanced-serialization-for-ipc
*/
constructor(options) {
Expand Down Expand Up @@ -251,7 +251,10 @@ class Master extends EventEmitter {
if (this.options.isDebug) opt.execArgv = process.execArgv.concat([ `--${semver.gte(process.version, '8.0.0') ? 'inspect' : 'debug'}-port=${debugPort}` ]);

/* istanbul ignore next */
if (semver.gte(process.version, '12.16.0')) {

if ((semver.gte(process.version, '12.16.0') && semver.lt(process.version, '13.0.0'))
|| semver.gte(process.version, '13.2.0'
) {
/* istanbul ignore next */
if (this.options.serialization) {
opt.serialization = this.options.serialization;
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/options.js
Expand Up @@ -65,7 +65,9 @@ module.exports = function(options) {
const isDebug = process.execArgv.some(argv => argv.includes('--debug') || argv.includes('--inspect'));
if (isDebug) options.isDebug = isDebug;

if (semver.gte(process.version, '12.16.0')) {
if ((semver.gte(process.version, '12.16.0') && semver.lt(process.version, '13.0.0'))
|| semver.gte(process.version, '13.2.0'
) {
/* istanbul ignore else */
if (typeof options.serialization !== 'undefined'
&& options.serialization !== 'json'
Expand All @@ -75,7 +77,7 @@ module.exports = function(options) {
} else {
/* istanbul ignore else */
if (options.serialization) {
throw new Error('[egg-cluster] options.serialization requires Node.js >= v12.16.0');
throw new Error('[egg-cluster] options.serialization requires Node.js >= v12.16.0 or >= v13.2.0');
}
}

Expand Down
27 changes: 17 additions & 10 deletions test/options.test.js
Expand Up @@ -205,26 +205,33 @@ describe('test/options.test.js', () => {
});

describe('should options.serialization', () => {
it('should with "json" value when Node.js >= v12.16.0', () => {
if (semver.gte(process.version, '12.16.0')) {
let isSupportSerialization = false
if ((semver.gte(process.version, '12.16.0') && semver.lt(process.version, '13.0.0'))
|| semver.gte(process.version, '13.2.0'
) {
isSupportSerialization = true
}

it('should with "json" value when Node.js supports serialization', () => {
if (isSupportSerialization) {
const options = parseOptions({
serialization: 'json',
});
assert(options.serialization === 'json');
}
});

it('should with "advanced" value when Node.js >= v12.16.0', () => {
if (semver.gte(process.version, '12.16.0')) {
it('should with "advanced" value when Node.js supports serialization', () => {
if (isSupportSerialization) {
const options = parseOptions({
serialization: 'advanced',
});
assert(options.serialization === 'advanced');
}
});

it('should error with invalid value when Node.js >= v12.16.0', () => {
if (semver.gte(process.version, '12.16.0')) {
it('should error with invalid value when Node.js supports serialization', () => {
if (isSupportSerialization) {
try {
parseOptions({
serialization: 'fake',
Expand All @@ -236,8 +243,8 @@ describe('test/options.test.js', () => {
}
});

it('should error with empty value when Node.js >= v12.16.0', () => {
if (semver.gte(process.version, '12.16.0')) {
it('should error with empty value when Node.js supports serialization', () => {
if (isSupportSerialization) {
try {
parseOptions({
serialization: '',
Expand All @@ -249,8 +256,8 @@ describe('test/options.test.js', () => {
}
});

it('should error with value when Node.js < v12.16.0', () => {
if (!semver.gte(process.version, '12.16.0')) {
it('should error with value when Node.js not supports serialization', () => {
if (!isSupportSerialization) {
try {
parseOptions({
serialization: 'json',
Expand Down

0 comments on commit 4179e83

Please sign in to comment.