Skip to content

Commit 5f369e4

Browse files
committed
Add test to ensure port, config, appId, serverURL, masterKey, appName, graphQLServerURL options are not ignored.
1 parent fea00fb commit 5f369e4

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

Parse-Dashboard/tests/.eslintrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": [
3+
"jest"
4+
],
5+
"env": {
6+
"jest/globals": true
7+
}
8+
}

Parse-Dashboard/tests/index.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
"main": "Parse-Dashboard/app.js",
144144
"jest": {
145145
"roots": [
146-
"src/lib"
146+
"src/lib",
147+
"Parse-Dashboard"
147148
],
148149
"transform": {
149150
".*": "<rootDir>/testing/preprocessor.js"

0 commit comments

Comments
 (0)