|
1 | 1 | # Developing `trustify-tests` |
2 | 2 |
|
3 | | -This document describes how to setup your environment to run the `trustify-tests` |
4 | | -on your local environment. |
| 3 | +This document describes: |
| 4 | + |
| 5 | +- the layout of the `trustify-tests` repository |
| 6 | + |
| 7 | +- how to contribute a test |
| 8 | + |
| 9 | +- how to setup your environment to run the `trustify-tests` on your local |
| 10 | + environment |
| 11 | + |
| 12 | +## Repository Layout |
| 13 | + |
| 14 | +The layout of the `trustify-tests` repository looks like follows: |
| 15 | + |
| 16 | +``` |
| 17 | +. |
| 18 | +├── package.json |
| 19 | +├── playwright.config.ts |
| 20 | +├── config |
| 21 | +├── etc |
| 22 | +└── tests |
| 23 | + ├── api |
| 24 | + │ ├── fixtures.ts |
| 25 | + │ ├── client |
| 26 | + │ ├── dependencies |
| 27 | + │ ├── features |
| 28 | + │ └── helpers |
| 29 | + ├── common |
| 30 | + │ ├── constants.ts |
| 31 | + │ └── assets |
| 32 | + │ ├── csaf |
| 33 | + │ └── sbom |
| 34 | + └── ui |
| 35 | + ├── dependencies |
| 36 | + ├── features |
| 37 | + │ ├── *.feature |
| 38 | + │ ├── @sbom-explorer |
| 39 | + │ └── @vulnerability-explorer |
| 40 | + ├── helpers |
| 41 | + └── steps |
| 42 | +``` |
| 43 | + |
| 44 | +- `package.json` - project configuration the `npm` ([Node.js Package Manager](https://docs.npmjs.com/)) |
| 45 | + understands; you can define your scripts (commands) here that you can then |
| 46 | + execute by `npm run <your command>` |
| 47 | + |
| 48 | +- `playwright.config.ts` - a configuration for [Playwright](https://playwright.dev/docs/intro) |
| 49 | + and [Playwright-BDD](https://vitalets.github.io/playwright-bdd/#/) |
| 50 | + |
| 51 | +- `config` contains configuration files that are common for the repository; |
| 52 | + currently it contains |
| 53 | + |
| 54 | + - `openapi.yaml` - a file with the [Trustify](https://github.com/trustification/trustify) |
| 55 | + API definition; every time the file changes on the [Trustify](https://github.com/trustification/trustify) |
| 56 | + side it should be also updated here |
| 57 | + |
| 58 | + - `openapi-ts.config.ts` - a configuration for `@hey-api/openapi-ts` telling |
| 59 | + it how to generate the content of `tests/api/client`; whenever this or |
| 60 | + `openapi.yaml` file changes `npm run openapi` should be executed to update |
| 61 | + the content of `tests/api/client` |
| 62 | + |
| 63 | +- `etc` contains auxiliary files such as Podman/Docker compose files to start |
| 64 | + a Playwright container |
| 65 | + |
| 66 | +- `tests/api` contains API tests organized as follows |
| 67 | + |
| 68 | + - `fixtures.ts` - API tests fixtures written in TypeScript |
| 69 | + |
| 70 | + - `client` contains a TypeScript interface to [Trustify](https://github.com/trustification/trustify) |
| 71 | + API generated from `config/openapi.yaml` by `npm run openapi` |
| 72 | + |
| 73 | + - `dependencies` contains setup and tear down routines which are run before |
| 74 | + the start and after the end of the API test suite, respectively |
| 75 | + |
| 76 | + - `features` contains API tests itself; `_openapi_client_examples.ts` shows |
| 77 | + how to use generated TypeScript interface to [Trustify](https://github.com/trustification/trustify) |
| 78 | + in API tests |
| 79 | + |
| 80 | + - `helpers` contains auxiliary utilities used by API tests |
| 81 | + |
| 82 | +- `tests/common` contains data and definitions shared by both API and UI tests |
| 83 | + |
| 84 | + - `constants.ts` - constant definitions used by both API and UI tests |
| 85 | + |
| 86 | + - `assets/csaf` contains compressed (`bz2`) samples of CSAF files |
| 87 | + |
| 88 | + - `assets/sboms` contains compressed (`bz2`) samples of SBOM files |
| 89 | + |
| 90 | +- `tests/ui` contains UI tests; UI tests are developed following BDD (Behavior |
| 91 | + Driven Development) methodology; the directory is organized as follows |
| 92 | + |
| 93 | + - `dependencies` contains setup and tear down routines which are run before |
| 94 | + the start and after the end of the UI test suite, respectively |
| 95 | + |
| 96 | + - `features` contains the UI tests itself; the content of the directory is |
| 97 | + further organized as follows |
| 98 | + |
| 99 | + - `*.feature` files are test scenarios described in [Gherkin](https://cucumber.io/docs/gherkin/); |
| 100 | + `*.feature` files on the top level of the `tests/ui/features` directory |
| 101 | + describe scenarios that need to be implemented first in the [front end](https://github.com/trustification/trustify-ui); |
| 102 | + that is, they describe the expected front end behavior |
| 103 | + |
| 104 | + - `@*` directories contain `*.feature` files and `*.step.ts` files used to |
| 105 | + test the so far implemented [front end](https://github.com/trustification/trustify-ui) |
| 106 | + features; see also [Tags from path](https://vitalets.github.io/playwright-bdd/#/writing-steps/scoped?id=tags-from-path) |
| 107 | + documentation |
| 108 | + |
| 109 | + - `helpers` contains auxiliary utilities used by UI tests |
| 110 | + |
| 111 | + - `steps` contains implementation of common BDD steps used in `tests/ui/features` |
| 112 | + |
| 113 | +## Contributing a Test |
| 114 | + |
| 115 | +To contribute an API test, put your code under the `tests/api/features` directory. |
| 116 | +If the test also contains a generic code that could be shared by more API tests, |
| 117 | +put that code under the `tests/api/helpers` directory. In a case that code is |
| 118 | +also intended to be shared by UI tests, put it under the `tests/common` directory |
| 119 | +instead. If you have also some assets that need to be contributed together with |
| 120 | +the test, put them under the `tests/common/assets` directory. |
| 121 | + |
| 122 | +To contribute a UI (front end) test, put your code under the `tests/ui/features` |
| 123 | +directory. Depending on the status of a feature your test is trying to cover, |
| 124 | +there are two ways of how to proceed: |
| 125 | + |
| 126 | +1. **A test is covering an implemented UI feature.** Put your test under |
| 127 | + a `tests/ui/features/@*` directory. You can choose from the existing or create |
| 128 | + your own depending on your use case. |
| 129 | + |
| 130 | +1. **A test is covering a use case (scenario) not yet implemented.** Describe |
| 131 | + your use case in [Gherkin](https://cucumber.io/docs/gherkin/) and put it |
| 132 | + inside a `tests/ui/features/*.feature` file. The use case should be |
| 133 | + communicated with the [upstream](https://github.com/trustification/trustify-ui) |
| 134 | + before. Once the upstream implements the requested features covering your use |
| 135 | + case, the next step is to put your `*.feature` file(s) under a `tests/ui/features/@*` |
| 136 | + directory and implement missing steps to make it work under the Playwright |
| 137 | + BDD framework. |
| 138 | + |
| 139 | +Other directories you should be interested in when contributing a UI test: |
| 140 | + |
| 141 | +- `tests/common` (described earlier) |
| 142 | + |
| 143 | +- `tests/ui/helpers` follows the same rules as `tests/api/helpers` |
| 144 | + |
| 145 | +- `tests/ui/steps` is intended to be a right place for steps that are common |
| 146 | + across many use cases (scenarios) |
5 | 147 |
|
6 | 148 | ## System Requirements |
7 | 149 |
|
|
0 commit comments