Skip to content
Open
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: 1 addition & 1 deletion resources/buildConfigDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand Down
12 changes: 10 additions & 2 deletions spec/CLI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand All @@ -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', () => {
Expand All @@ -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');
}
}
Expand Down
9 changes: 5 additions & 4 deletions spec/buildConfigDefinitions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Options/Definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading