Skip to content

Commit

Permalink
Add test to ensure port, config, appId, serverURL, masterKey, appName…
Browse files Browse the repository at this point in the history
…, graphQLServerURL options are not ignored.
  • Loading branch information
bugra9 committed May 7, 2022
1 parent fea00fb commit 5f369e4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Parse-Dashboard/tests/.eslintrc.json
@@ -0,0 +1,8 @@
{
"plugins": [
"jest"
],
"env": {
"jest/globals": true
}
}
65 changes: 65 additions & 0 deletions Parse-Dashboard/tests/index.test.js
@@ -0,0 +1,65 @@
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, killSignal: 'SIGINT' });

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`;
});
}
});
}
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -143,7 +143,8 @@
"main": "Parse-Dashboard/app.js",
"jest": {
"roots": [
"src/lib"
"src/lib",
"Parse-Dashboard"
],
"transform": {
".*": "<rootDir>/testing/preprocessor.js"
Expand Down

0 comments on commit 5f369e4

Please sign in to comment.