Skip to content

Commit

Permalink
Restore help commands test to old location
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Aug 22, 2024
1 parent c37e3b0 commit cad2e86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
15 changes: 9 additions & 6 deletions packages/imperative/__tests__/src/TestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ export function executeTestCLICommand(cliBinModule: string, testContext: any, ar
execDir?: string, pipeContent?: string | Buffer,
env: { [key: string]: string } = process.env): SpawnSyncReturns<string> {
const testLogger = TestLogger.getTestLogger();
const isLocalFile = fs.existsSync(cliBinModule);
const isLocalFile = fs.existsSync(cliBinModule) && fs.statSync(cliBinModule).isFile();
const nodeCommand = isLocalFile ? "node" : "npx";
// run the command with ts-node/register
const starterArguments = isLocalFile ? ["--require", "ts-node/register", cliBinModule] : [cliBinModule];
args = starterArguments.concat(args);
if (!isLocalFile) {
execDir ??= nodePath.dirname(expect.getState().testPath);
if (isLocalFile) {
// run the command with ts-node/register if local file specified
const starterArguments = ["--require", "ts-node/register", cliBinModule];
args = starterArguments.concat(args);
} else {
// run the command with package bin script if directory specified
args.unshift(Object.keys(require(cliBinModule + "/package.json").bin).pop());
execDir ??= cliBinModule;
}

const commandExecutionMessage = "Executing " + nodeCommand + " " + args.join(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import * as T from "../../../TestUtil";
import { IImperativeConfig } from "../../../../../src/imperative/index";

describe("Imperative help should be available for a range of definitions", function () {
const cliWithBin = Object.keys(require(__dirname + "/../package.json").bin)[0];
const cliWithoutBin = __dirname + "/../../with_profiles/ProfileExampleCLI.ts";
const config: IImperativeConfig = require(__dirname + "/../ProfileBinExampleConfiguration");
const cliWithBin = __dirname + "/../../../example_clis/with_bin_package";
const cliWithoutBin = __dirname + "/../../../example_clis/with_profiles/ProfileExampleCLI.ts";
const config: IImperativeConfig = require(__dirname + "/../../../example_clis/with_bin_package/ProfileBinExampleConfiguration");
/**
* Clean up the home directory before and after each test.
*/
Expand All @@ -26,22 +26,16 @@ describe("Imperative help should be available for a range of definitions", funct
T.rimraf(T.TEST_HOME);
});

it("We should be able to get --help for our example CLI - without bin script", function () {
it("We should be able to get --help for our example CLI - no bin specified in package", function () {
T.findExpectedOutputInCommand(cliWithoutBin, ["--help"],
[config.productDisplayName, "log"], "stdout", true,
this, T.CMD_TYPE.INTERACTIVE, undefined, undefined, {
IMPERATIVE_CALLER_LOCATION: T.TEST_HOME
});
this, T.CMD_TYPE.INTERACTIVE);
T.findExpectedOutputInCommand(cliWithoutBin, ["log", "--help"],
["ProfileExampleCLI.ts", "Log example messages", "messages"], "stdout", true,
this, T.CMD_TYPE.INTERACTIVE, undefined, undefined, {
IMPERATIVE_CALLER_LOCATION: T.TEST_HOME
});
this, T.CMD_TYPE.INTERACTIVE);
T.findExpectedOutputInCommand(cliWithoutBin, ["log", "messages", "--help"],
["ProfileExampleCLI.ts", "Log example messages", "messages", "level"], "stdout", true,
this, T.CMD_TYPE.INTERACTIVE, undefined, undefined, {
IMPERATIVE_CALLER_LOCATION: T.TEST_HOME
});
this, T.CMD_TYPE.INTERACTIVE);
});

it("should display --version in the root help", function () {
Expand All @@ -50,7 +44,7 @@ describe("Imperative help should be available for a range of definitions", funct
this, T.CMD_TYPE.INTERACTIVE);
});

it("We should be able to get --help for our example CLI - with bin script", function () {
it("We should be able to get --help for our example CLI - with bin in package", function () {
T.findExpectedOutputInCommand(cliWithBin, ["--help"],
[config.productDisplayName, "ape", "bat", "cat"], "stdout", true,
this, T.CMD_TYPE.INTERACTIVE);
Expand Down

0 comments on commit cad2e86

Please sign in to comment.