Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli-hooks(fix): remove environment variable requirements from the start hook #1835

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});