Skip to content

Commit d9ee3eb

Browse files
committed
Improve the testing README
1 parent 3c76a87 commit d9ee3eb

1 file changed

Lines changed: 67 additions & 22 deletions

File tree

features/README.md

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,74 @@
33
The automated tests for the DAP code are implemented using [cucumber-js](https://github.com/cucumber/cucumber-js)
44
and [puppeteer](https://pptr.dev/).
55

6-
By default the tests use the local version of the DAP javascript files. Loading
7-
the code into a test HTML page, performing various user actions, and testing
8-
the behavior of the code in response to the user actions.
6+
```mermaid
7+
---
8+
title: Testing architecture
9+
---
10+
11+
flowchart LR
12+
Runner("`Test Runner<br>*Cucumber.js*`"):::local
13+
Puppeteer("`Browser Automation<br>*Puppeteer*`"):::local
14+
Browser(Chromium):::local
15+
Site("`Test Website<br>*nginx in Docker*`"):::local
16+
config_startup@{ shape: diamond, label: "Configurable at<br>website startup" }
17+
subgraph code [DAP code]
18+
DAP_Local(DAP code - local):::local
19+
DAP_Staging(DAP code - staging):::remote
20+
DAP_Prod(DAP code - production):::remote
21+
end
22+
GA4(DAP GA4 test property):::remote
23+
subgraph Legend
24+
legend_local(Running locally):::local
25+
legend_remote(Running remotely):::remote
26+
end
27+
28+
classDef local fill:#f96
29+
classDef remote fill:#f9f
30+
31+
Runner -->|drives| Puppeteer -->|controls| Browser -->|loads| Site
32+
config_startup --> DAP_Local
33+
config_startup --> DAP_Staging
34+
config_startup --> DAP_Prod
35+
Site-.->|sends events to| GA4
36+
Site -->|loads one of|config_startup
37+
```
38+
39+
## Running the test site
40+
The test site is a simple nginx server running in a Docker container. It serves static HTML pages that include the DAP code, allowing us to test the DAP code's behavior in a realistic environment.
41+
42+
To start up the test site, run one of the `test-site-*` commands:
43+
44+
```bash
45+
npm run test-site-dev
46+
```
47+
This particular command will start up the test site at http://localhost:8080/. All pages will be configured to use your local version of the DAP code by including the script tag:
48+
49+
```angular2html
50+
<script async id="_fed_an_ua_tag" src="Universal-Federated-Analytics-Min.js"></script>
51+
```
52+
53+
You can also choose to run the test site configured to load a deployed version of the DAP code, either the staging or production version, by running `npm run test-site-stg` or `npm run test-site-prd`, respectively.
54+
55+
## Configuring DAP in the test site
56+
The DAP code is configurable at load time via query parameters. For instance, to enable DAP's YouTube tracking, a website
57+
can load the DAP code with the `yt` query parameter set to `true`.
58+
59+
```angular2html
60+
<script async type="text/javascript" id="_fed_an_ua_tag" src="https://dap.digitalgov.gov/Universal-Federated-Analytics-Min.js?agency=HHS&yt=true"></script>
61+
```
62+
63+
The full list of configurable options is available in the [DAP Code Capabilities Summary](https://github.com/digital-analytics-program/gov-wide-code/wiki/DAP-Code-Capabilities-Summary).
64+
65+
The test site is designed to pass through query parameters to the DAP code, allowing you to test different DAP configurations by changing the URL.
66+
For instance, opening http://localhost:8080/youtube.html?yt=true&search=nasa will load the page for testing DAP's YouTube tracking with YouTube tracking enbabled.
67+
Any query parameters that don't match one of DAP's configuration options will be treated as a normal query parameter (e.g. `search=nasa`).
968

10-
Use the `DAP_ENV` environment variable to insert live versions of the code into
11-
the test HTML page instead of the local version as described below.
69+
This capability is used extensively in the automated tests to check the DAP code's behavior in various configurations.
1270

1371
## Running the tests
1472

15-
Start up the test site at http://localhost:8080/:
73+
Start up the test site using any of the `test-site-*` commands:
1674

1775
```bash
1876
npm run test-site-dev
@@ -38,24 +96,11 @@ npm run cucumber:report
3896

3997
Test report should be available in `output/test-results.html`.
4098

41-
## Configuring with environment variables
99+
### Running the tests in verbose mode
42100

43-
### Verbose mode
44-
45-
Print debugging information to stdout while running the tests:
101+
Verbose mode logs events that occur within the browser during test execution. If you find yourself wishing that you could
102+
watch what's happening in browser devtools during test execution, try verbose mode:
46103

47104
```bash
48105
VERBOSE=true npm run cucumber
49106
```
50-
51-
### Run tests against the live staging environment
52-
53-
```bash
54-
DAP_ENV=staging npm run cucumber
55-
```
56-
57-
### Run tests against the live production environment
58-
59-
```bash
60-
DAP_ENV=production npm run cucumber
61-
```

0 commit comments

Comments
 (0)