Skip to content

Commit

Permalink
cli-hooks(fix): remove environment variable requirements from the sta…
Browse files Browse the repository at this point in the history
…rt hook (#1835)
  • Loading branch information
zimeg authored Jun 28, 2024
1 parent 9e20ca3 commit e527b43
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 62 deletions.
19 changes: 0 additions & 19 deletions packages/cli-hooks/src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ if (fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
* @param {string} cwd - The current working directory of the project.
*/
export default function start(cwd) {
validateEnvironment();

const customPath = process.env.SLACK_CLI_CUSTOM_FILE_PATH;
const pkgJSONMain = getPackageJSONMain(cwd);
const pkgJSONDefault = 'app.js';
Expand Down Expand Up @@ -53,20 +51,3 @@ function getPackageJSONMain(cwd) {
return undefined;
}
}

/**
* Confirms environment variables are prepared by the CLI.
*/
function validateEnvironment() {
const missingTokenError = `Missing the {type} token needed to start the app with Socket Mode.
Hints: Setting the {token} environment variable is required.
Check: Confirm that you are using the latest version of the Slack CLI.`;
if (!process.env.SLACK_CLI_XOXB) {
const missingBotTokenError = missingTokenError.replace('{type}', 'bot').replace('{token}', 'SLACK_CLI_XOXB');
throw new Error(missingBotTokenError);
}
if (!process.env.SLACK_CLI_XAPP) {
const missingAppTokenError = missingTokenError.replace('{type}', 'app').replace('{token}', 'SLACK_CLI_XAPP');
throw new Error(missingAppTokenError);
}
}
43 changes: 0 additions & 43 deletions packages/cli-hooks/src/start.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,47 +126,4 @@ describe('start implementation', async () => {
});
});
});

describe('without valid tokens', async () => {
beforeEach(() => {
sinon.stub(console, 'log');
delete process.env.SLACK_CLI_XOXB;
delete process.env.SLACK_CLI_XAPP;
});
afterEach(() => {
sinon.restore();
delete process.env.SLACK_CLI_XOXB;
delete process.env.SLACK_CLI_XAPP;
});

it('should error without a bot token', async () => {
try {
process.env.SLACK_CLI_XAPP = 'xapp-example';
start('./');
} catch (err) {
if (err instanceof Error) {
assert(err.message.includes('Missing the bot token needed to start the app with Socket Mode.'));
assert(err.message.includes('Hints: Setting the SLACK_CLI_XOXB environment variable is required.'));
assert(err.message.includes('Check: Confirm that you are using the latest version of the Slack CLI.'));
return;
}
}
assert(false);
});

it('should error without an app token', async () => {
try {
process.env.SLACK_CLI_XOXB = 'xoxb-example';
start('./');
} catch (err) {
if (err instanceof Error) {
assert(err.message.includes('Missing the app token needed to start the app with Socket Mode.'));
assert(err.message.includes('Hints: Setting the SLACK_CLI_XAPP environment variable is required.'));
assert(err.message.includes('Check: Confirm that you are using the latest version of the Slack CLI.'));
return;
}
}
assert(false);
});
});
});

0 comments on commit e527b43

Please sign in to comment.