Skip to content

Commit 7eaf7a2

Browse files
committed
test(integration): Update test + framework code
Getting close enough on the core framework and unit test code to want to start working on the CirlceCI side of things. This commit forms a solid baseline to use while working on .circleci/config.yml Related to: #133
1 parent 0c5d2d0 commit 7eaf7a2

File tree

4 files changed

+138
-83
lines changed

4 files changed

+138
-83
lines changed

test/helpers/cmd.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {ChildProcess} from "child_process";
1919
const {existsSync} = require('fs');
2020
const {constants} = require('os');
2121
const {ChildProcess, spawn} = require('cross-spawn');
22+
const util = require('util'); // Provides access to the "inspect" function to help output objects via console.log.
2223

2324

2425
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -29,10 +30,11 @@ const {ChildProcess, spawn} = require('cross-spawn');
2930
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
3031
export interface CommandOutput {
3132
exitCode?: number;
32-
output?: string[];
33-
signal?: string;
34-
stderr?: string;
35-
stdout?: string;
33+
signal?: string;
34+
stderr?: string;
35+
stderrLines?: string[];
36+
stdout?: string;
37+
stdoutLines?: string[];
3638
}
3739

3840
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -150,14 +152,14 @@ export function createProcess(processPath:string, args:string[]=[], envVars:AnyJ
150152

151153
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
152154
/**
153-
* @function createProcess
155+
* @function executeWithInput
154156
* @param {string} processPath Path of the process to execute
155157
* @param {string[]} args Arguments to the command
156158
* @param {MockInput[]} [mockInputs] (Optional) Array of MockInput objects (user responses)
157159
* @param {ExecOptions} [opts] (optional) Environment variables
158160
* @returns {Promise<CommandOutput>} Returns a promise that resolves when all inputs are sent.
159161
* Rejects the promise if any error.
160-
* @description Creates a command and executes inputs (user responses) to the stdin
162+
* @description Executes a CLI Plugin command and is capable of sending mock stdin inputs.
161163
* @public
162164
*/
163165
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
@@ -176,10 +178,11 @@ export async function executeWithInput(processPath:string, args:string[]=[], moc
176178

177179
// Initialize an object to store output from this function.
178180
const commandOutput:CommandOutput = {
179-
exitCode: null,
180-
output: [],
181-
stderr: '',
182-
stdout: ''
181+
exitCode: null,
182+
stderrLines: [],
183+
stdoutLines: [],
184+
stderr: '',
185+
stdout: ''
183186
};
184187

185188
// DEVTEST: Echo a variety of path related info so we can see differences between local and CircleCI.
@@ -235,13 +238,14 @@ export async function executeWithInput(processPath:string, args:string[]=[], moc
235238
clearAllTimeouts(trackedTimeouts);
236239

237240
// Prep the Command Output variable for return.
238-
commandOutput.output = commandOutput.stdout.trim().split('\n');
239-
commandOutput.exitCode = code;
240-
commandOutput.signal = signal;
241+
commandOutput.stdoutLines = commandOutput.stdout.trim().split('\n');
242+
commandOutput.stderrLines = commandOutput.stderr.trim().split('\n');
243+
commandOutput.exitCode = code;
244+
commandOutput.signal = signal;
241245

242246
// Show the contents of the Command Output if the showResults option was set.
243247
if (opts && opts.showResult) {
244-
console.log('Command Output:\n%O', commandOutput);
248+
console.log(`Command Output:\n${util.inspect(commandOutput, {depth:10, maxArrayLength:1000, colors:true})}`);
245249
}
246250

247251
// Resolve the promise, returning the Command Output we've collected.
@@ -252,20 +256,20 @@ export async function executeWithInput(processPath:string, args:string[]=[], moc
252256

253257
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
254258
/**
255-
* @function getOutputLines
256-
* @param {CommandOutput} commandOutput Contains the output results of a call to executeWithInput().
257-
* @param {number[]} linesToGet Index values of individual line numbers to retrieve.
259+
* @function getLines
260+
* @param {string[]} stringArray Contains the output results of a call to executeWithInput().
261+
* @param {number[]} linesToGet Index values of individual line numbers to retrieve.
258262
* Negative numbers will fetch lines offset from the end of the output array.
259263
* @returns {string} Single concatenated string of all requested lines.
260264
* @description Given a CommandOutput object and an array of index values, returns a single string
261265
* concatenation of the requested line numbers.
262266
* @public
263267
*/
264268
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
265-
export function getOutputLines(commandOutput:CommandOutput, linesToGet:number[]):string {
269+
export function getLines(stringArray:string[], linesToGet:number[]):string {
266270

267-
// Return an empty string if we didn't get a populated string array in commandOutput.
268-
if (Array.isArray(commandOutput.output) === false || commandOutput.output.length === 0) {
271+
// Return an empty string if we didn't get a populated string array.
272+
if (Array.isArray(stringArray) === false || stringArray.length === 0) {
269273
return '';
270274
}
271275

@@ -285,14 +289,14 @@ export function getOutputLines(commandOutput:CommandOutput, linesToGet:number[])
285289
}
286290

287291
// Fetch lines from the END of the array if the requested line is a negative number.
288-
if (line < 0 && (commandOutput.output.length - line >= 0)) {
289-
returnString += commandOutput.output[commandOutput.output.length - Math.abs(line)];
292+
if (line < 0 && (stringArray.length - line >= 0)) {
293+
returnString += stringArray[stringArray.length - Math.abs(line)];
290294
continue;
291295
}
292296

293297
// Fetch lines by the normal array index if the requested line is a positive number.
294-
if (line >= 0 && (line <= commandOutput.output.length - 1)) {
295-
returnString += commandOutput.output[line];
298+
if (line >= 0 && (line <= stringArray.length - 1)) {
299+
returnString += stringArray[line];
296300
continue;
297301
}
298302
}

test/helpers/init.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ process.env.FALCON_COMMAND_RUNNER = path.resolve('bin/run'); // Pat
77
process.env.FALCON_TEST_TEMPDIR = path.resolve('test/temp'); // Path to the temp directory used during tests.
88
process.env.FALCON_TEST_PROJECTDIR = path.resolve('test/projects'); // Path to the directory that holds sample ADK projects.
99

10+
// Check environment for cues about handling debug. Allows CI environment to flip debug on/off.
11+
process.env.FALCON_TEST_SHOW_STDOUT = process.env.FALCON_TEST_SHOW_STDOUT || ''; // stdout from spawned process is piped to the main process.
12+
process.env.FALCON_TEST_SHOW_STDERR = process.env.FALCON_TEST_SHOW_STDERR || ''; // stderr from spawned process is piped to the main process.
13+
process.env.FALCON_TEST_SHOW_RESULT = process.env.FALCON_TEST_SHOW_RESULT || ''; // Prints internal commandResult object at the conclusion of executeWithInput().
14+
15+
// DEVTEST: Echo the various "debug" env vars.
16+
console.log(`FALCON_TEST_SHOW_STDOUT: ${process.env.FALCON_TEST_SHOW_STDOUT}`);
17+
console.log(`FALCON_TEST_SHOW_STDERR: ${process.env.FALCON_TEST_SHOW_STDERR}`);
18+
console.log(`FALCON_TEST_SHOW_RESULT: ${process.env.FALCON_TEST_SHOW_RESULT}`);
19+
20+
// DEVTEST: Demonstrate how boolean checks of env vars goes.
21+
if (process.env.FALCON_TEST_SHOW_STDOUT) {
22+
console.log('-->FALCON_TEST_SHOW_STDOUT environment var deemed TRUE<--');
23+
}
24+
if (process.env.FALCON_TEST_SHOW_STDERR) {
25+
console.log('-->FALCON_TEST_SHOW_STDERR environment var deemed TRUE<--');
26+
}
27+
if (process.env.FALCON_TEST_SHOW_RESULT) {
28+
console.log('-->FALCON_TEST_SHOW_RESULT environment var deemed TRUE<--');
29+
}
30+
1031
// Delete everything inside of the Falcon Test Temp Directory EXCEPT .gitignore
1132
del.sync(
1233
[

test/integration-tests/commands/falcon/adk/create.test.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
* @license MIT
1010
*/
1111
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
12-
// Import Modules=
13-
import { expect } from 'chai';
14-
import { executeWithInput } from '../../../../helpers/cmd';
15-
import { getOutputLines } from '../../../../helpers/cmd';
16-
import { KEY } from '../../../../helpers/cmd';
12+
// Import Modules
13+
import {expect} from 'chai';
14+
import {executeWithInput} from '../../../../helpers/cmd';
15+
import {KEY} from '../../../../helpers/cmd';
1716

1817

1918
//─────────────────────────────────────────────────────────────────────────────────────────────────┐
@@ -23,34 +22,36 @@ import { KEY } from '../../../../helpers/cmd';
2322
//─────────────────────────────────────────────────────────────────────────────────────────────────┘
2423
describe.skip('falcon:adk:create', () => {
2524

25+
//───────────────────────────────────────────────────────────────────────────┐
2626
// Test One
27+
//───────────────────────────────────────────────────────────────────────────┘
2728
it('should successfully create an ADK project', async () => {
2829
const commandResponse = await executeWithInput(
2930
process.env.FALCON_COMMAND_RUNNER, // Path to the process that will be run.
3031
[
3132
'falcon:adk:create' // First member of the array must be the CLI command we want to run.
3233
],
3334
[
34-
{input: KEY.ENTER, delay: 20000},
35-
{input: KEY.ENTER, delay: 200},
36-
{input: KEY.ENTER, delay: 200},
37-
{input: 'N' + KEY.ENTER, delay: 200},
38-
{input: 'Y' + KEY.ENTER, delay: 200},
39-
{input: KEY.ENTER, delay: 200},
40-
{input: KEY.ENTER, delay: 200},
41-
{input: KEY.ENTER, delay: 200},
42-
{input: KEY.ENTER, delay: 200},
43-
{input: 'Y' + KEY.ENTER, delay: 200}
35+
{input: KEY.ENTER, delay: 20000}, // Choose first DevHub listed
36+
{input: KEY.ENTER, delay: 200}, // ???
37+
{input: KEY.ENTER, delay: 200}, // ???
38+
{input: 'N' + KEY.ENTER, delay: 200}, // ???
39+
{input: 'Y' + KEY.ENTER, delay: 200}, // ???
40+
{input: KEY.ENTER, delay: 200}, // ???
41+
{input: KEY.ENTER, delay: 200}, // ???
42+
{input: KEY.ENTER, delay: 200}, // ???
43+
{input: KEY.ENTER, delay: 200}, // ???
44+
{input: 'Y' + KEY.ENTER, delay: 200} // ???
4445
],
4546
{
4647
envVars: {
47-
SFDX_JSON_TO_STDOUT: true, // Sends all JSON output to STDOUT
48-
SFDX_AUTOUPDATE_DISABLE: true // Disables the Salesforce CLI AutoUpdate feature
48+
SFDX_JSON_TO_STDOUT: true, // Sends all JSON output to STDOUT
49+
SFDX_AUTOUPDATE_DISABLE: true // Disables the Salesforce CLI AutoUpdate feature
4950
},
5051
workingDir: process.env.FALCON_TEST_TEMPDIR,
51-
showStdout: true,
52-
showStderr: true,
53-
showResult: true,
52+
showStdout: process.env.FALCON_TEST_SHOW_STDOUT ? true : false,
53+
showStderr: process.env.FALCON_TEST_SHOW_STDERR ? true : false,
54+
showResult: process.env.FALCON_TEST_SHOW_RESULT ? true : false,
5455
minTimeout: 100,
5556
maxTimeout: 300000
5657
}
@@ -59,13 +60,17 @@ describe.skip('falcon:adk:create', () => {
5960
// Check exit code.
6061
expect(commandResponse.exitCode)
6162
.to
62-
.equal(0, 'Non-zero Exit Code');
63-
// Check final output.
64-
expect(getOutputLines(commandResponse, [-1]))
63+
.equal(0, 'FAILURE! Non-zero exit code');
64+
65+
// Check final output for success indicators.
66+
expect(commandResponse.stdoutLines)
6567
.to
66-
.equal('Command Succeded : falcon:adk:create completed successfully', 'Incorrect Final Output');
67-
}).timeout(120000);
68+
.include('Command Succeded : falcon:adk:create completed successfully',
69+
'FAILURE! Final output missing success message');
70+
}).timeout(120000);
6871

69-
// Test Two...
72+
//───────────────────────────────────────────────────────────────────────────┐
73+
// Test Two
74+
//───────────────────────────────────────────────────────────────────────────┘
7075

7176
});

0 commit comments

Comments
 (0)