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