mirror of
https://github.com/parse-community/parse-server
synced 2026-08-09 13:03:18 +00:00
fix: NumberOrBoolean config option (cluster) value not coerced from env/CLI (#10531)
This commit is contained in:
@@ -177,7 +177,7 @@ function mapperFor(elt, t) {
|
||||
return wrap(t.identifier('moduleOrObjectParser'));
|
||||
}
|
||||
if (type == 'NumberOrBoolean') {
|
||||
return wrap(t.identifier('numberOrBooleanParser'));
|
||||
return t.callExpression(wrap(t.identifier('numberOrBoolParser')), [t.stringLiteral(elt.name)]);
|
||||
}
|
||||
if (type == 'NumberOrString') {
|
||||
return t.callExpression(wrap(t.identifier('numberOrStringParser')), [t.stringLiteral(elt.name)]);
|
||||
|
||||
+10
-2
@@ -178,7 +178,7 @@ describe('definitions', () => {
|
||||
if (typeof definition.required !== 'undefined') {
|
||||
expect(typeof definition.required).toBe('boolean');
|
||||
}
|
||||
if (typeof definition.action !== 'undefined') {
|
||||
if ('action' in definition) {
|
||||
expect(typeof definition.action).toBe('function');
|
||||
}
|
||||
}
|
||||
@@ -189,6 +189,14 @@ describe('definitions', () => {
|
||||
definitions.facebookAppIds.action();
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should coerce the NumberOrBoolean cluster option value', () => {
|
||||
const action = definitions.cluster.action;
|
||||
expect(typeof action).toBe('function');
|
||||
expect(action('2')).toBe(2);
|
||||
expect(action('true')).toBe(true);
|
||||
expect(action('false')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('LiveQuery definitions', () => {
|
||||
@@ -203,7 +211,7 @@ describe('LiveQuery definitions', () => {
|
||||
if (typeof definition.required !== 'undefined') {
|
||||
expect(typeof definition.required).toBe('boolean');
|
||||
}
|
||||
if (typeof definition.action !== 'undefined') {
|
||||
if ('action' in definition) {
|
||||
expect(typeof definition.action).toBe('function');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +81,10 @@ describe('buildConfigDefinitions', () => {
|
||||
expect(result.property.name).toBe('moduleOrObjectParser');
|
||||
});
|
||||
|
||||
it('should return numberOrBooleanParser for NumberOrBoolean GenericTypeAnnotation', () => {
|
||||
it('should return numberOrBoolParser call expression for NumberOrBoolean GenericTypeAnnotation', () => {
|
||||
const mockElement = {
|
||||
type: 'GenericTypeAnnotation',
|
||||
name: 'cluster',
|
||||
typeAnnotation: {
|
||||
id: {
|
||||
name: 'NumberOrBoolean',
|
||||
@@ -93,9 +94,9 @@ describe('buildConfigDefinitions', () => {
|
||||
|
||||
const result = mapperFor(mockElement, t);
|
||||
|
||||
expect(t.isMemberExpression(result)).toBe(true);
|
||||
expect(result.object.name).toBe('parsers');
|
||||
expect(result.property.name).toBe('numberOrBooleanParser');
|
||||
expect(t.isCallExpression(result)).toBe(true);
|
||||
expect(result.callee.property.name).toBe('numberOrBoolParser');
|
||||
expect(result.arguments[0].value).toBe('cluster');
|
||||
});
|
||||
|
||||
it('should return numberOrStringParser call expression for NumberOrString GenericTypeAnnotation', () => {
|
||||
|
||||
@@ -139,7 +139,7 @@ module.exports.ParseServerOptions = {
|
||||
cluster: {
|
||||
env: 'PARSE_SERVER_CLUSTER',
|
||||
help: 'Run with cluster, optionally set the number of processes default to os.cpus().length',
|
||||
action: parsers.numberOrBooleanParser,
|
||||
action: parsers.numberOrBoolParser('cluster'),
|
||||
},
|
||||
collectionPrefix: {
|
||||
env: 'PARSE_SERVER_COLLECTION_PREFIX',
|
||||
|
||||
Reference in New Issue
Block a user