-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' of github.com:HubSpot/hubspot-cli into jy/integra…
…te-new-http-error-object
- Loading branch information
Showing
39 changed files
with
844 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Create image based on the official Node image from dockerhub | ||
FROM node:16 | ||
|
||
# Create base directory | ||
WORKDIR /usr/src/hubspot-cli | ||
|
||
# Get all the code needed to run the app locally | ||
COPY . . | ||
|
||
# Install dependencies | ||
RUN yarn |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,75 @@ | ||
# HubSpot CLI Acceptance Tests | ||
|
||
This project tests `hs.*` commands as if they were being used by an end-user. | ||
This project tests our CLI's `hs <*>` commands as if they were being used by an end-user. | ||
|
||
## Getting Started | ||
|
||
The main test execution is kicked off by running `yarn test-cli` from the root of `hubspot-cli`. This will run the `run-tests` scipe which itself is a CLI, so to see the available options, you can `run-tests --help`. This was done so that the tests can be installed against any given version of the CLI and tested against it. In addition, it was done to keep the test logic separated from the CLI library. | ||
The main test execution is kicked off by running `yarn test-cli` from the root of `hubspot-cli`. This will run the `run-tests` script which itself is a CLI, so to see the available options, you can `run-tests --help`. This was done so that the tests can be installed against any given version of the CLI and tested against it. In addition, it was done to keep the test logic separated from the CLI library. | ||
|
||
Note that if you are testing against a QA portal, not a PROD one, you'll need to add the `--qa` flag when running the script. There is still an outstanding issue with this because we attempt to add the `--qa` flag to all `hs` commands, however it is not available for all commands. | ||
|
||
### Setup | ||
|
||
To setup these tests, first [create an app](https://developers.hubspot.com/docs/api/creating-an-app) in a [HubSpot developer account](https://app.hubspot.com/signup-hubspot/crm). Under the "Auth" tab, give your app at least one scope, and set the redirect URL to `localhost:3000/oauth-callback`, and save your changes. Also, take note of your Client ID, and Client Secret and click "Copy full URL". ![image](https://user-images.githubusercontent.com/48874841/175648758-b2fdb491-90f8-4573-ad9e-af7e1236548c.png) | ||
To setup these tests, there are two required arguments and one optional one: | ||
|
||
Next, in the navigation bar, click "Testing", and then "Create app test account". Then, paste the OAuth URL you copied earlier into your browser, choose your newly created test account, and click "Connect App". | ||
|
||
Now, navigate back to the "Testing" page, and click your test account. Take note of the Account ID in the URL (`https://app.hubspot.com/dashboard-library/ACCOUNT_ID`). Then [navigate to the following page and generate a personal access key](https://app.hubspot.com/portal-recommend/l?slug=personal-access-key) that is associated with your test account. | ||
|
||
Generate [a github token](https://github.com/settings/tokens/new) to test with. | ||
|
||
You know have all the information required to create a `.env` file in the [Configuration](./README.md#configuration) section. | ||
|
||
Finally, you must add an asset to your new test account. To do this, navigate to the [HubSpot marketplace](https://ecosystem.hubspot.com/marketplace/website/free-cms-accelerator-themes), log into your test account, and install an asset. | ||
1. The ID of a HubSpot account that you are a user in | ||
2. Your generated personal access key in that account (available in [personal access key ui](https://app.hubspot.com/l/personal-access-key)) | ||
3. [Optional] A path to an instance of the CLI. The test runner will execute the commands against this provided instance | ||
- The default behavior is to use `../packages/cli/bin/hs` | ||
|
||
### Configuration | ||
|
||
There are four ways to pass in necessary configuration to the script. | ||
There are three ways to pass in necessary configuration to the script. | ||
|
||
1. Creating a `.env` file in `acceptance-tests` folder. Note that each variable must be on a new line - you may need to bypass the formatter of your IDE for this. | ||
1. Creating a `.env` file in `acceptance-tests` folder. | ||
|
||
```bash | ||
ACCOUNT_ID="9289088" | ||
CLI_PATH="hs" | ||
ACCOUNT_ID="123456789" | ||
PERSONAL_ACCESS_KEY="AiRiNGU2Y***************m1wLi2s8k2UlMYHEX" | ||
GITHUB_TOKEN="123a4b56-****-****-****-************" | ||
CLI_PATH="hs" | ||
``` | ||
|
||
2. Through environment variables. | ||
|
||
```bash | ||
|
||
export ACCOUNT_ID="9289088" | ||
export CLI_PATH="hs" | ||
export ACCOUNT_ID="123456789" | ||
export PERSONAL_ACCESS_KEY="AiRiNGU2Y***************m1wLi2s8k2UlMYHEX" | ||
export GITHUB_TOKEN="123a4b56-****-****-****-************" | ||
export CLI_PATH="hs" | ||
``` | ||
|
||
3. Through arguments on the `run-tests` script | ||
|
||
```bash | ||
run-tests --accountId=9289088 --cliPath=hs --personalAccessKey="*********" --githubToken="********" | ||
yarn run-tests --accountId=123456789 --personalAccessKey="*********" --cliPath=hs | ||
``` | ||
|
||
4. If you need to override any environment variables at a test variable, you can do that via the `setLocalTestOverrides` function available in `env.js` | ||
Alternatively, we support the following aliases: | ||
|
||
The priority is Local Test Overrides > CLI Arg Overrides > Environment Variables | ||
```bash | ||
yarn run-tests --a=123456789 --pak="*********" --c=hs | ||
``` | ||
|
||
### Running Locally | ||
|
||
1. Run `lerna bootstrap` to install dependencies | ||
2. Run `yarn test-cli` | ||
2. Run `yarn test-cli` from the root of the CLI repo | ||
|
||
**NOTE:** Include the `--debug` flag for more verbose output | ||
|
||
## Why Jasmine | ||
|
||
You may be wondering why we are using Jasmine, and not Jest. The reason is because Jest does not provide an API for executing the tests within code. We need to do this since we are wrapping the tests within a CLI. | ||
|
||
## Accounts | ||
|
||
A couple of account have been set up specifically for testing. They are QA Account 105786502 and Prod Account 9289088. If you add any test data to the accounts for testing, ensure you add it to the above two. | ||
A couple of accounts have been set up specifically for testing. They are QA Account 105786502 and Prod Account 9289088. If you add any test data to the accounts for testing, ensure you add it to the above two. | ||
|
||
## Issues | ||
|
||
The `.env` file does not get recognized when running [act](https://github.com/nektos/act) locally to run the tests within the github action. To bypass this, you can comment out the `.env` line in the `.gitignore` file and run `act again`. See https://github.com/nektos/act/issues/193 for more info. | ||
|
||
## To Do | ||
|
||
- Only add `--qa` flag when needed to `hs` commands | ||
|
||
- Bulk out test coverage | ||
|
||
- Sometimes the initial bootstrapping said the auth token is no longer valid, not too sure why this is. Investigate | ||
|
||
## Gotchas | ||
|
||
- Currently sometimes the personal-access-key test is flakey. Run the tests again and it should pass. | ||
- Currently the personal-access-key test is flakey. Run the tests again and it should pass. | ||
|
||
- The tests seem to trip up on usages of the `ora` library. To get around this, we have a list of blacklisted strings. If your test is being picky about ora, add the error message to the blacklist in `cmd.js` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const CONFIG_FILE_PATH = 'acceptance-test.config.yml'; | ||
const CONFIG_FILE_NAME = 'hs-acceptance-test.config.yml'; | ||
const DEFAULT_CLI_PATH = '../packages/cli/bin/hs'; | ||
|
||
module.exports = { | ||
CONFIG_FILE_PATH, | ||
CONFIG_FILE_NAME, | ||
DEFAULT_CLI_PATH, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.