BVB Source Codes

parse-server Show CLI.spec.js Source code

Return Download parse-server: download CLI.spec.js Source code - Download parse-server Source code - Type:.js
  1. 'use strict';
  2. import commander from '../src/cli/utils/commander';
  3. import definitions from '../src/cli/definitions/parse-server';
  4. import liveQueryDefinitions from '../src/cli/definitions/parse-live-query-server';
  5.  
  6. var testDefinitions = {
  7.   'arg0': 'PROGRAM_ARG_0',
  8.   'arg1': {
  9.     env: 'PROGRAM_ARG_1',
  10.     required: true
  11.   },
  12.   'arg2': {
  13.     env: 'PROGRAM_ARG_2',
  14.     action: function(value) {
  15.       var intValue = parseInt(value);
  16.       if (!Number.isInteger(intValue)) {
  17.         throw 'arg2 is invalid';
  18.       }
  19.       return intValue;
  20.     }
  21.   },
  22.   'arg3': {},
  23.   'arg4': {
  24.     default: 'arg4Value'
  25.   }
  26. };
  27.  
  28. describe('commander additions', () => {
  29.   afterEach((done) => {
  30.     commander.options = [];
  31.     delete commander.arg0;
  32.     delete commander.arg1;
  33.     delete commander.arg2;
  34.     delete commander.arg3;
  35.     delete commander.arg4;
  36.     done();
  37.   });
  38.  
  39.   it('should load properly definitions from args', (done) => {
  40.     commander.loadDefinitions(testDefinitions);
  41.     commander.parse(['node','./CLI.spec.js','--arg0', 'arg0Value', '--arg1', 'arg1Value', '--arg2', '2', '--arg3', 'some']);
  42.     expect(commander.arg0).toEqual('arg0Value');
  43.     expect(commander.arg1).toEqual('arg1Value');
  44.     expect(commander.arg2).toEqual(2);
  45.     expect(commander.arg3).toEqual('some');
  46.     expect(commander.arg4).toEqual('arg4Value');
  47.     done();
  48.   });
  49.  
  50.   it('should load properly definitions from env', (done) => {
  51.     commander.loadDefinitions(testDefinitions);
  52.     commander.parse([], {
  53.       'PROGRAM_ARG_0': 'arg0ENVValue',
  54.       'PROGRAM_ARG_1': 'arg1ENVValue',
  55.       'PROGRAM_ARG_2': '3',
  56.     });
  57.     expect(commander.arg0).toEqual('arg0ENVValue');
  58.     expect(commander.arg1).toEqual('arg1ENVValue');
  59.     expect(commander.arg2).toEqual(3);
  60.     expect(commander.arg4).toEqual('arg4Value');
  61.     done();
  62.   });
  63.  
  64.   it('should load properly use args over env', (done) => {
  65.     commander.loadDefinitions(testDefinitions);
  66.     commander.parse(['node','./CLI.spec.js','--arg0', 'arg0Value', '--arg4', ''], {
  67.       'PROGRAM_ARG_0': 'arg0ENVValue',
  68.       'PROGRAM_ARG_1': 'arg1ENVValue',
  69.       'PROGRAM_ARG_2': '4',
  70.       'PROGRAM_ARG_4': 'arg4ENVValue'
  71.     });
  72.     expect(commander.arg0).toEqual('arg0Value');
  73.     expect(commander.arg1).toEqual('arg1ENVValue');
  74.     expect(commander.arg2).toEqual(4);
  75.     expect(commander.arg4).toEqual('');
  76.     done();
  77.   });
  78.  
  79.   it('should fail in action as port is invalid', (done) => {
  80.     commander.loadDefinitions(testDefinitions);
  81.     expect(()=> {
  82.       commander.parse(['node','./CLI.spec.js','--arg0', 'arg0Value'], {
  83.         'PROGRAM_ARG_0': 'arg0ENVValue',
  84.         'PROGRAM_ARG_1': 'arg1ENVValue',
  85.         'PROGRAM_ARG_2': 'hello',
  86.       });
  87.     }).toThrow('arg2 is invalid');
  88.     done();
  89.   });
  90.  
  91.   it('should not override config.json', (done) => {
  92.     commander.loadDefinitions(testDefinitions);
  93.     commander.parse(['node','./CLI.spec.js','--arg0', 'arg0Value', './spec/configs/CLIConfig.json'], {
  94.       'PROGRAM_ARG_0': 'arg0ENVValue',
  95.       'PROGRAM_ARG_1': 'arg1ENVValue',
  96.     });
  97.     const options = commander.getOptions();
  98.     expect(options.arg2).toBe(8888);
  99.     expect(options.arg3).toBe('hello'); //config value
  100.     expect(options.arg4).toBe('/1');
  101.     done();
  102.   });
  103.  
  104.   it('should fail with invalid values in JSON', (done) => {
  105.     commander.loadDefinitions(testDefinitions);
  106.     expect(() => {
  107.       commander.parse(['node','./CLI.spec.js','--arg0', 'arg0Value', './spec/configs/CLIConfigFail.json'], {
  108.         'PROGRAM_ARG_0': 'arg0ENVValue',
  109.         'PROGRAM_ARG_1': 'arg1ENVValue',
  110.       });
  111.     }).toThrow('arg2 is invalid');
  112.     done();
  113.   });
  114.  
  115.   it('should fail when too many apps are set', (done) => {
  116.     commander.loadDefinitions(testDefinitions);
  117.     expect(() => {
  118.       commander.parse(['node','./CLI.spec.js','./spec/configs/CLIConfigFailTooManyApps.json']);
  119.     }).toThrow('Multiple apps are not supported');
  120.     done();
  121.   });
  122.  
  123.   it('should load config from apps', (done) => {
  124.     commander.loadDefinitions(testDefinitions);
  125.     commander.parse(['node', './CLI.spec.js', './spec/configs/CLIConfigApps.json']);
  126.     const options = commander.getOptions();
  127.     expect(options.arg1).toBe('my_app');
  128.     expect(options.arg2).toBe(8888);
  129.     expect(options.arg3).toBe('hello'); //config value
  130.     expect(options.arg4).toBe('/1');
  131.     done();
  132.   });
  133.  
  134.   it('should fail when passing an invalid arguement', (done) => {
  135.     commander.loadDefinitions(testDefinitions);
  136.     expect(() => {
  137.       commander.parse(['node', './CLI.spec.js', './spec/configs/CLIConfigUnknownArg.json']);
  138.     }).toThrow('error: unknown option myArg');
  139.     done();
  140.   });
  141. });
  142.  
  143. describe('definitions', () => {
  144.   it('should have valid types', () => {
  145.     for (const key in definitions) {
  146.       const definition = definitions[key];
  147.       expect(typeof definition).toBe('object');
  148.       if (typeof definition.env !== 'undefined') {
  149.         expect(typeof definition.env).toBe('string');
  150.       }
  151.       expect(typeof definition.help).toBe('string');
  152.       if (typeof definition.required !== 'undefined') {
  153.         expect(typeof definition.required).toBe('boolean');
  154.       }
  155.       if (typeof definition.action !== 'undefined') {
  156.         expect(typeof definition.action).toBe('function');
  157.       }
  158.     }
  159.   });
  160. });
  161.  
  162. describe('LiveQuery definitions', () => {
  163.   it('should have valid types', () => {
  164.     for (const key in liveQueryDefinitions) {
  165.       const definition = liveQueryDefinitions[key];
  166.       expect(typeof definition).toBe('object');
  167.       if (typeof definition.env !== 'undefined') {
  168.         expect(typeof definition.env).toBe('string');
  169.       }
  170.       expect(typeof definition.help).toBe('string');
  171.       if (typeof definition.required !== 'undefined') {
  172.         expect(typeof definition.required).toBe('boolean');
  173.       }
  174.       if (typeof definition.action !== 'undefined') {
  175.         expect(typeof definition.action).toBe('function');
  176.       }
  177.     }
  178.   });
  179. });
  180.  
downloadCLI.spec.js Source code - Download parse-server Source code
Related Source Codes/Software:
react-boilerplate - 2017-06-07
webtorrent - Streaming torrent client for the web ... 2017-06-06
machine-learning-for-software-engineers - A complete daily plan for studying to become a mac... 2017-06-06
upterm - A terminal emulator for the 21st century. 2017-06-06
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
storybook - 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top