File size: 2,855 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
<div style="width: 45%; float:left" align="left"><a href="./setup.md"><-- Setup</a> </div>
<div style="width: 5%; float:left" align="center"><a href="./../README.md">Top</a></div>
<div style="width: 45%; float:right"align="right"><a href="./tests_local.md">Running tests on your machine --></a> </div>
<br><br>
# Test Environment
<!-- TOC -->
- [Test Environment](#test-environment)
- [Environment Variables](#environment-variables)
- [Secrets File](#secrets-file)
- [Decrypting the Secrets](#decrypting-the-secrets)
- [Using the Secrets](#using-the-secrets)
<!-- /TOC -->
The environment configuration for these tests comes from two different sources: environment variables and an encrypted secrets file.
## Environment Variables
Most non-sensitive runtime configuration comes from environment variables. All of our environment variables have fallback defaults.
For example:
```
VIEWPORT_NAME=mobile yarn jest specs/<etc>
```
The list of supported environment variables are found in [`env-variables.ts`](../../../packages/calypso-e2e//src/env-variables.ts). This file also adds static type checking and is the most up-to-date resource. The [Environment Variables](./environment_variables.md) page may be out of date but will contain explanations of what the individual variables mean.
To use:
```typescript
import { envVariables } from '@automattic/calypso-e2e';
// Later
if ( envVariables.VIEWPORT_NAME === 'mobile' ) {
// Do x ;
}
```
## Secrets File
### Decrypting the Secrets
Within `@automattic/calypso-e2e/src/secrets` is an encrypted file that holds various sensitive secrets, such as API keys and test account information. This must be decrypted prior to use.
**Automatticians**: please refer to the Field Guide page - PCYsg-vnR-p2 for more information.
**Trialmatticians**: please contact a team member in your Slack chat for the decryption key.
First set the environment variable `E2E_SECRETS_KEY` to the "Calypso E2E Config decode key" from the Automattic secret store.
```bash
export E2E_SECRETS_KEY='<Calypso E2E Config decode key from the secret store>'
```
Then run the following command to decrypt the secrets:
```bash
# If within test/e2e directory
yarn decrypt-secrets
# If at repo root
yarn workspace wp-e2e-tests decrypt-secrets
```
The decrypted file must **NEVER be committed.** There are `.gitignore` rules to protect against this, but be vigilant nonetheless!
### Using the Secrets
The secrets are read and validated at runtime. They are accessed through the [`SecretsManager`](../../../packages/calypso-e2e/src/secrets/secrets-manager.ts) static class, which presents the secrets with static typings.
To use:
```typescript
import { SecretsManager } from '@automattic/calypso-e2e';
// Later in the spec
const credentials = SecretsManager.secrets.testAccounts.<test_account_name>;
```
|