Skip to content

Commit

Permalink
more tests (including timeout stuff)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Oct 15, 2020
1 parent 12939fb commit 062c799
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/server/__tests__/unitTests/fileToLines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ describe('reads lines from file', () => {
expect(lines.length).toBe(1);
expect(lines[0]).toEqual(lineToKeep);
});
test('handles bash bang stuff', async () => {
const file = `#!/bin/bash
testline`;
await fs.writeFile(filename, file);

const lines = await fileToLines(filename);
expect(lines.length).toBe(1);
expect(lines[0]).toEqual(lineToKeep);
});
test('writes file, then reads back, omitting comments', async () => {
const file = `#testline
testline`;
Expand Down
20 changes: 16 additions & 4 deletions src/server/__tests__/unitTests/flagTypeFromCommandHelp.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { getCommandsWithFileFlagsMap, getBaseCommand, usageAsArray, getTypeFromUsageArray, commandRewriter } from '../../lib/flagTypeFromCommandHelp';
import {
getCommandsWithFileFlagsMap,
getBaseCommand,
usageAsArray,
getTypeFromUsageArray,
commandRewriter
} from '../../lib/flagTypeFromCommandHelp';

const usage = `<%= command.id %> -i <id> -n <string> [-d <string>] [-v <string>] [-m] [-r <url>] [-p <url>] [-k <string>] [-w <number>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`;
const cmd = 'sfdx force:org:create -f config/project-scratch-def.json -s -a vol -d 1';
const cmd2 = 'sfdx force:org:create -s -a vol -d 1';
const cmd3 = 'sfdx force:org:create --definitionfile config/project-scratch-def.json -s -a vol -d 1';
const cmd3 =
'sfdx force:org:create --definitionfile config/project-scratch-def.json -s -a vol -d 1';

describe('flag type parsing', () => {
jest.setTimeout(10000);
// test('handles create -a', async () => {
// const output = await getFlagsFromCommandHelp(cmd);
// expect(output.find(item => item.flag === '-f')).toHaveProperty('type', 'filepath');
Expand All @@ -22,12 +30,16 @@ describe('flag type parsing', () => {

test('rewrites commands', async () => {
const results = await commandRewriter('somePath', cmd);
expect(results).toBe('sfdx force:org:create -f somePath/config/project-scratch-def.json -s -a vol -d 1');
expect(results).toBe(
'sfdx force:org:create -f somePath/config/project-scratch-def.json -s -a vol -d 1'
);
});

test('rewrites commands with full flag name', async () => {
const results = await commandRewriter('somePath', cmd3);
expect(results).toBe('sfdx force:org:create --definitionfile somePath/config/project-scratch-def.json -s -a vol -d 1');
expect(results).toBe(
'sfdx force:org:create --definitionfile somePath/config/project-scratch-def.json -s -a vol -d 1'
);
});

test('does not rewrite commands that do not need it', async () => {
Expand Down
41 changes: 33 additions & 8 deletions src/server/__tests__/unitTests/lineParse.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import fs from 'fs-extra';

// import { testRepos } from '../helpers/testRepos';
import { lineParse, securityAssertions, jsonify, byooFilter, getMaxDays, multiOrgCorrections } from '../../lib/lineParse';
import {
lineParse,
securityAssertions,
jsonify,
byooFilter,
getMaxDays,
multiOrgCorrections
} from '../../lib/lineParse';
// import { getCloneCommands } from '../../lib/namedUtilities';
// import { sfdxTimeout } from '../helpers/testingUtils';
// import { execProm } from '../../lib/execProm';
Expand Down Expand Up @@ -67,20 +74,25 @@ const file2Length = 7;
// createdTimestamp: new Date()
// };
describe('multiOrgCorrections', () => {
jest.setTimeout(10000);
it('works with single password command', async () => {
const lines = await filesToLines([
'./src/server/__tests__/helpers/initFiles/inputFile1',
'./src/server/__tests__/helpers/initFiles/inputFile2'
]);
expect(multiOrgCorrections(lines).filter((line) => line.includes('user:password')).length).toBe(1);
expect(
multiOrgCorrections(lines).filter((line) => line.includes('user:password')).length
).toBe(1);
});
it('works with no password command', async () => {
const lines = await filesToLines([
'./src/server/__tests__/helpers/initFiles/inputFile1',
'./src/server/__tests__/helpers/initFiles/inputFile2'
]);
expect(
multiOrgCorrections(lines.filter((line) => !line.includes('user:password'))).filter((line) => line.includes('user:password')).length
multiOrgCorrections(
lines.filter((line) => !line.includes('user:password'))
).filter((line) => line.includes('user:password')).length
).toBe(0);
});
it('works with multiple password command', async () => {
Expand All @@ -89,7 +101,9 @@ describe('multiOrgCorrections', () => {
'./src/server/__tests__/helpers/initFiles/inputFile2'
]);
lines.push('sfdx force:user:password:generate');
expect(multiOrgCorrections(lines).filter((line) => line.includes('user:password')).length).toBe(1);
expect(
multiOrgCorrections(lines).filter((line) => line.includes('user:password')).length
).toBe(1);
});
});

Expand All @@ -115,7 +129,9 @@ describe('maxDays', () => {
'./src/server/__tests__/helpers/initFiles/inputFile1',
'./src/server/__tests__/helpers/initFiles/inputFile2'
]);
expect(getMaxDays(lines.map((line) => line.replace(' -d 1', '').replace(' -d 2', '')))).toBe(7);
expect(
getMaxDays(lines.map((line) => line.replace(' -d 1', '').replace(' -d 2', '')))
).toBe(7);
});
});

Expand All @@ -134,7 +150,10 @@ describe('end-to-end tests', () => {

test('single repo byoo', async () => {
await fs.copy('./src/server/__tests__/helpers/initFiles/inputFile1', testOrgInitLoc);
await fs.copy('./src/server/__tests__/helpers/initFiles/sfdx-project.json', `${testFileLoc}/sfdx-project.json`);
await fs.copy(
'./src/server/__tests__/helpers/initFiles/sfdx-project.json',
`${testFileLoc}/sfdx-project.json`
);
const results = await lineParse({
...testDepReqWL,
byoo: {
Expand All @@ -149,8 +168,14 @@ describe('end-to-end tests', () => {
});

test('multi repo', async () => {
await fs.copy('./src/server/__tests__/helpers/initFiles/inputFile1', `${testFileLoc}/inputFile1/orgInit.sh`);
await fs.copy('./src/server/__tests__/helpers/initFiles/inputFile2', `${testFileLoc}/inputFile2/orgInit.sh`);
await fs.copy(
'./src/server/__tests__/helpers/initFiles/inputFile1',
`${testFileLoc}/inputFile1/orgInit.sh`
);
await fs.copy(
'./src/server/__tests__/helpers/initFiles/inputFile2',
`${testFileLoc}/inputFile2/orgInit.sh`
);
const results = await lineParse(testDepReqWLMulti);
// remvoes 1 line (the org:create on the 2nd file)
expect(results).toHaveLength(file1Length + file2Length - 1);
Expand Down

0 comments on commit 062c799

Please sign in to comment.