Skip to content

Commit 484de84

Browse files
committed
docs: update some docs
1 parent 40de8b5 commit 484de84

2 files changed

Lines changed: 63 additions & 45 deletions

File tree

CONTRIBUTING.md

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
2. Install dependencies
1818

19-
> Note: Make sure to run these commands in your `sfdx-browserforce-plugin` directory.
19+
> [!NOTE]
20+
> Make sure to run these commands in your `sfdx-browserforce-plugin` directory.
2021
21-
```console
22+
```shell
2223
npm ci
2324
```
2425

@@ -29,44 +30,58 @@ Please note that this is only an example. In fact this is supported in the Metad
2930

3031
You can scaffold a new plugin by running:
3132

32-
```console
33+
```shell
3334
npm run generate:plugin --name AdminsCanLogInAsAnyUser
3435
```
3536

36-
Run `git status` afterwards to see what files have been generated.
37-
38-
Want to see it in action?
37+
Bravo 👏, you have just generated a working browserforce plugin!
3938

4039
## Building
4140

4241
TypeScript code needs to be transpiled to JavaScript.
4342
To do this, run the following command:
4443

45-
```console
44+
```shell
4645
npm run build
4746
```
4847

49-
Bravo 👏, you have just generated a working browserforce plugin!
48+
Want to see it in action?
5049

51-
Create a scratch org and try it yourself:
50+
Let's create a Scratch Org
5251

53-
```console
54-
sf org create scratch -f config/project-scratch-def.json -a browserforce-dev -d
55-
BROWSER_DEBUG=true ./bin/run browserforce apply -f src/plugins/admins-can-log-in-as-any-user/enable.json -o browserforce-dev
56-
BROWSER_DEBUG=true ./bin/run browserforce apply -f src/plugins/admins-can-log-in-as-any-user/disable.json -o browserforce-dev
52+
```shell
53+
npm run develop
5754
```
5855

59-
Now it's your turn!
56+
and now we can run it:
57+
58+
```shell
59+
BROWSER_DEBUG=true ./bin/run browserforce apply -f src/plugins/admins-can-log-in-as-any-user/enable.json
60+
BROWSER_DEBUG=true ./bin/run browserforce apply -f src/plugins/admins-can-log-in-as-any-user/disable.json
61+
```
62+
63+
> [!TIP]
64+
> Instead of manually running these commands while developing, we will run the E2E tests instead:
65+
66+
```shell
67+
npm run test:e2e -- -g "AdminsCanLogInAsAnyUser"
68+
AdminsCanLogInAsAnyUser
69+
✔ should enable
70+
✔ should already be enabled
71+
✔ should disable
72+
✔ should already be disabled
73+
4 passing (6s)
74+
```
6075

6176
## Developing plugins
6277

6378
For the following, we assume that your scaffolded plugin lives in `src/plugins/admins-can-log-in-as-any-user`.
6479

65-
```console
80+
```shell
6681
$ tree src/plugins/admins-can-log-in-as-any-user
6782
src/plugins/admins-can-log-in-as-any-user
68-
├── disable.json <-- example config file for e2e test
69-
├── enable.json <-- example config file for e2e test
83+
├── disable.json <-- example config file for manual testing
84+
├── enable.json <-- example config file for manual testing
7085
├── index.e2e-spec.ts <-- end-to-end test
7186
├── index.ts <-- implementation
7287
└── schema.json <-- schema for configuration
@@ -149,32 +164,35 @@ The execution will apply as few changes as necessary and so you will be able to
149164
Both the result of the `retrieve` function and the argument of the `apply` function are objects in the format defined in your `schema.json`.
150165
In this example, you would return `{enabled: boolean}` as part of `retrieve`, and expect `{enabled: boolean}` as argument in `apply`.
151166

152-
## Debugging
153-
154-
The [Salesforce CLI Plug-In Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_plugins.meta/sfdx_cli_plugins/cli_plugins_debug.htm) describes debugging sfdx plugins using VS Code very well.
155-
156167
## Testing
157168

158169
To run **unit tests**:
159170

160-
> Note: Make sure to run these commands in your sfdx-browserforce-plugin directory.
171+
> [!NOTE]
172+
> Make sure to run these commands in your sfdx-browserforce-plugin directory.
161173
162-
```console
174+
```shell
163175
npm run test
164176
```
165177

166-
To run the **end to end tests**, you might want to create a new **default scratch org** first.
178+
To run **end to end tests**:
167179

168-
> Note: Your default scratch org will be used in the tests!
180+
> [!CAUTION]
181+
> Your default scratch org will be used in the E2E tests!
169182
170-
```console
171-
sf org create scratch -f config/project-scratch-def.json -d
183+
```shell
184+
npm run test:e2e -- -g "AdminsCanLogInAsAnyUser" # will only run tests matching `AdminsCanLogInAsAnyUser`
172185
```
173186

174-
```console
175-
npm run test:e2e
176-
npm run test:e2e -- -g "AdminsCanLogInAsAnyUser" # will only run tests matching `AdminsCanLogInAsAnyUser`
187+
> [!IMPORTANT]
188+
> E2E tests should be implemented to be **re-runnable**.
189+
>
190+
> Please run the test at least 7 times to reduce the risk of a flaky implementation:
191+
192+
```shell
193+
for i in {1..7}; do npm run test:e2e -- -g "AdminsCanLogInAsAnyUser"; done
177194
```
178195

179-
> Note: You can run the e2e tests in non-headless mode (opening a browser) by setting the environment variable `BROWSER_DEBUG=true`.
180-
> Note: You can also slow down the e2e test in non-headless mode by setting the environmnet variable, where the number is milliseconds of delay `BROWSER_SLOWMO=250`.
196+
## Debugging
197+
198+
The [Salesforce CLI Plug-In Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_plugins.meta/sfdx_cli_plugins/cli_plugins_debug.htm) describes debugging sfdx plugins using VS Code very well.

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For example, the Currency Locale in `Setup -> Company Settings -> Company Inform
2424

2525
👉 This is where Browserforce (sfdx-browserforce-plugin) comes to the rescue. It fills this gap by applying these unsupported settings through browser automation!
2626

27-
# Example
27+
## Example
2828

2929
To change the Currency Locale, the Browserforce config file (here: `./config/currency.json`) looks like this:
3030

@@ -50,13 +50,13 @@ $ sf browserforce apply -f ./config/currency.json --target-org myOrg@example.com
5050
logging out... done
5151
```
5252

53-
# Key Concepts
53+
## Key Concepts
5454

5555
- 🔧 configuration using JSON Schema (similar to the [Scratch Org Definition Configuration](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_def_file.htm))
5656
- 🧠 idempotency of the `apply` command only applies what's necessary and allows re-execution (concept similar to [terraform](https://www.terraform.io/docs/commands/apply.html))
5757
- 🏎️ browser automation powered by Puppeteer and "Chrome for Testing", [learn more about Puppeteer and Browserforce](#puppeteer)
5858

59-
# Supported Browserforce Settings
59+
## Supported Browserforce Settings
6060

6161
Top settings:
6262

@@ -75,11 +75,11 @@ But there's more:
7575
- Please see the [Browserforce Settings](https://github.com/amtrack/sfdx-browserforce-plugin/wiki/Browserforce-Settings) wiki page with screenshots.
7676
- Explore the JSON schema powered configuration using a [full-blown example](https://github.dev/amtrack/sfdx-browserforce-plugin/blob/main/examples/full.json) or start with an [empty configuration](https://github.dev/amtrack/sfdx-browserforce-plugin/blob/main/examples/empty.json).
7777

78-
# Installation
78+
## Installation
7979

8080
There are several different methods to install `sfdx-browserforce-plugin`:
8181

82-
```console
82+
```shell
8383
# as an sf plugin globally
8484
sf plugins install sfdx-browserforce-plugin
8585

@@ -90,11 +90,11 @@ npm install --global sfdx-browserforce-plugin
9090
npm install --save-dev sfdx-browserforce-plugin
9191
```
9292

93-
# Usage
93+
## Usage
9494

9595
Depending on your choice of installation, you can find the `browserforce` namespace:
9696

97-
```console
97+
```shell
9898
# globally in the sf cli
9999
sf browserforce
100100

@@ -119,14 +119,14 @@ COMMANDS
119119

120120
Both the `browserforce apply` and `browserforce plan` commands expect a config file and a target username or alias for the org.
121121

122-
# Environment Variables
122+
## Environment Variables
123123

124124
- `BROWSER_DEBUG` run in non-headless mode (default: `false`)
125125
- `BROWSERFORCE_NAVIGATION_TIMEOUT_MS`: adjustable for slow internet connections (default: `90000`)
126126
- `BROWSERFORCE_RETRY_MAX_RETRIES`: number of retries on failures opening a page (default: `4`)
127127
- `BROWSERFORCE_RETRY_TIMEOUT_MS`: initial time between retries in exponential mode (default: `4000`)
128128

129-
# Puppeteer
129+
## Puppeteer
130130

131131
We use [Puppeteer](https://github.com/puppeteer/puppeteer) for browser automation which comes with its own "Chrome for Testing" browser.
132132

@@ -147,19 +147,19 @@ export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
147147
sf browserforce:apply ...
148148
```
149149

150-
Troubleshooting:
150+
## Troubleshooting
151151

152152
- The installation is triggered via the `postinstall` hook of npm/yarn. If you've disabled running scripts with npm (`--ignore-scripts` or via config file), it will not download the browser.
153153

154-
# Contributing
154+
## Contributing
155155

156156
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for getting started.
157157

158-
# Sponsors
158+
## Sponsors
159159

160160
- [PARX](https://www.parx.com)
161161
- [IPfolio](https://www.ipfolio.com)
162162

163-
# License
163+
## License
164164

165165
MIT © [Matthias Rolke](mailto:mr.amtrack@gmail.com)

0 commit comments

Comments
 (0)