|
| 1 | +const path = require('path'); |
| 2 | +const spawn = require('child_process').spawn; |
| 3 | + |
| 4 | +const TIMEOUT = 1000; // ms |
| 5 | + |
| 6 | +describe('port, config, appId, serverURL, masterKey, appName, graphQLServerURL options should not be ignored.', () => { |
| 7 | + it('Should start with port 4041.', async () => { |
| 8 | + const result = await startParseDashboardAndGetOutput(['--port', '4041']); |
| 9 | + |
| 10 | + expect(result).toContain('The dashboard is now available at http://0.0.0.0:4041/'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('Should return an error message if config and appId options are provided together.', async () => { |
| 14 | + const result = await startParseDashboardAndGetOutput(['--config', 'helloworld', '--appId', 'helloworld']); |
| 15 | + |
| 16 | + expect(result).toContain('You must provide either a config file or other CLI options (appName, appId, masterKey, serverURL, and graphQLServerURL); not both.'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('Should return an error message if config and serverURL options are provided together.', async () => { |
| 20 | + const result = await startParseDashboardAndGetOutput(['--config', 'helloworld', '--serverURL', 'helloworld']); |
| 21 | + |
| 22 | + expect(result).toContain('You must provide either a config file or other CLI options (appName, appId, masterKey, serverURL, and graphQLServerURL); not both.'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('Should return an error message if config and masterKey options are provided together.', async () => { |
| 26 | + const result = await startParseDashboardAndGetOutput(['--config', 'helloworld', '--masterKey', 'helloworld']); |
| 27 | + |
| 28 | + expect(result).toContain('You must provide either a config file or other CLI options (appName, appId, masterKey, serverURL, and graphQLServerURL); not both.'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('Should return an error message if config and appName options are provided together.', async () => { |
| 32 | + const result = await startParseDashboardAndGetOutput(['--config', 'helloworld', '--appName', 'helloworld']); |
| 33 | + |
| 34 | + expect(result).toContain('You must provide either a config file or other CLI options (appName, appId, masterKey, serverURL, and graphQLServerURL); not both.'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('Should return an error message if config and graphQLServerURL options are provided together.', async () => { |
| 38 | + const result = await startParseDashboardAndGetOutput(['--config', 'helloworld', '--graphQLServerURL', 'helloworld']); |
| 39 | + |
| 40 | + expect(result).toContain('You must provide either a config file or other CLI options (appName, appId, masterKey, serverURL, and graphQLServerURL); not both.'); |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
| 44 | +function startParseDashboardAndGetOutput(args) { |
| 45 | + return new Promise((resolve) => { |
| 46 | + const indexFilePath = path.resolve('./Parse-Dashboard/index.js'); |
| 47 | + const child = spawn('node', [indexFilePath, ...args], { cwd: '.', timeout: TIMEOUT, killSignal: 'SIGINT' }); |
| 48 | + |
| 49 | + let output = ''; |
| 50 | + child.on('error', () => { resolve(output); }); |
| 51 | + child.on('close', () => { resolve(output); }); |
| 52 | + |
| 53 | + if (child.stdout) { |
| 54 | + child.stdout.on('data', data => { |
| 55 | + output += `STDOUT: ${data}\n`; |
| 56 | + }); |
| 57 | + } |
| 58 | + |
| 59 | + if (child.stderr) { |
| 60 | + child.stderr.on('data', data => { |
| 61 | + output += `STDERROR: ${data}\n`; |
| 62 | + }); |
| 63 | + } |
| 64 | + }); |
| 65 | +} |
0 commit comments