Running Tests
Introduction
In order to allow us to make changes quickly, often and with a high level of confidence, we heavily rely on tests within the web repository.
All the steps below require you to have the web repo cloned locally and dependencies installed.
This can be achieved by running
$ git clone https://github.com/owncloud/web.git
$ cd web
$ pnpm install
Unit Tests
We have a steadily growing coverage of unit tests. You can run them locally via
$ pnpm test:unit
$ pnpm -r test:unit
You can also specify which package to run the test on, such as: pnpm --filter @ownclouders/web-pkg test:unit.
Alternatively, tests can also be run by navigating to the package name and then running pnpm test:unit.
Unit Test File Structure
Our unit tests spec files follow a simple structure:
-
fixtures and mocks at the top
-
helper functions at the bottom
-
tests in between
We usually organize tests with nested describe blocks. If you would like to get feedback from the core team about
the structure, scope and goals of your unit tests before actually writing some, we invite you to make a pull request
with only describe blocks and nested it.todo("put your test description here") lines.
E2E Tests (Playwright)
Our end-to-end test suite is built upon the Playwright Framework, which makes it easy to write tests, debug them and have them run cross-browser with minimal overhead.
Preparation
Please make sure you have installed all dependencies and started the server(s) as described in tooling.
Prepare Web
Bundle the web frontend with the following command:
$ pnpm build
Our compose setup automatically mounts it into an oCIS backend, respectively. Web also gets recompiled on changes.
Start Web
Start the web with the following command:
docker compose up
This will start all the services. The ENV variables specific to each services are defined in the docker-compose.yml file.
Run E2E Tests
The following command will run all available e2e tests:
$ pnpm test:e2e:playwright 'tests/e2e/specs/**/*.spec.ts'
Options
To run a particular test, simply add the spec file and line number to the test command, e.g. pnpm test:e2e:playwright tests/e2e/specs/admin-settings/users.feature:14
Various options are available via ENV variables, e.g.
-
BASIC_AUTH=trueuse basic authorization for api requests. -
RETRY=nto retry failuresntimes -
SLOW_MO=nto slow the execution time bynmilliseconds -
TIMEOUT=nto set tests to timeout afternmilliseconds -
HEADLESS=boolto open the browser while the tests run (defaults to true ⇒ headless mode) -
BROWSER=nameto run tests against a specific browser. Defaults to chromium, available are chromium, firefox, webkit, chromium -
ADMIN_PASSWORDto set administrator password. By default, theadminpassword is used in the test
For debugging reasons, you may want to record a video or traces of your test run. Again, you can use the following ENV variables in your command:
-
REPORT_DIR=another/pathto set a directory for your recorded files (defaults to "reports") -
REPORT_VIDEO=trueto record a video of the test run -
REPORT_HAR=trueto save request information from the test run -
REPORT_TRACING=trueto record traces from the test run
To then open e.g. the tracing from the REPORT_DIR, run
$ npx playwright show-trace path/to/file.zip
Analyze the Test Report
After running tests, report artifacts are written under REPORT_DIR (defaults to reports/e2e).
-
Accessibility report:
reports/e2e/a11y-report.json -
Traces (when
REPORT_TRACING=true):reports/e2e/playwright/tracing/*.zip -
Optional videos/HAR files (when enabled via
REPORT_VIDEO=trueorREPORT_HAR=true) are also stored in the report directory.
To inspect a trace file:
npx playwright show-trace reports/e2e/playwright/tracing/<trace-file>.zip
If you want an HTML Playwright report for a run, execute tests with the HTML reporter enabled and then open it:
pnpm test:e2e:playwright -- --reporter=html
npx playwright show-report
E2E Tests on oCIS with Keycloak
We can run some of the e2e tests on oCIS setup with Keycloak as an external idp. To run tests against locally, please follow the steps below:
Run oCIS with Keycloak
There’s a documentation to serve oCIS with Keycloak. Please follow each step to run oCIS with Keycloak.
Run E2E Tests
KEYCLOAK=true \
BASE_URL_OCIS=ocis.owncloud.test \
pnpm run test:e2e:playwright tests/e2e/specs/journeys
Following environment variables come in use while running e2e tests on oCIS with Keycloak:
-
BASE_URL_OCIS
sets oCIS url (e.g.: ocis.owncloud.test) -
KEYCLOAK_HOST
sets Keycloak url (e.g.: keycloak.owncloud.test) -
KEYCLOAK=true
runs the tests with Keycloak -
KEYCLOAK_REALM
sets oCIS realm name used on Keycloak
E2E Tests with Predefined Users (@predefined-users)
It is possible to run e2e tests with predefined users. This is useful for running tests in a production-like environment. The following environment variables are used to run the tests with predefined users:
-
PREDEFINED_USERS:true|false -
PREDEFINED_USERS_FILE: path to a JSON file mapping predefined users
We have to create a JSON file that contains the mapping of the users. JSON file MUST contain the following keys:
{
"alice": {// map user},
"brian": {// mapuser},
"carol": {// mapuser},
}
And the user object MUST have the following properties defined:
{
"id": "<usernmae>",
"displayName": "<display-name>",
"password": "<password>",
"email": "<email>"
}
A complete example of a JSON file.
{
"alice": {
"id": "einstein",
"displayName": "Albert Einstein",
"password": "relativity",
"email": "einstein@example.org"
},
"brian": {
"id": "marie",
"displayName": "Marie Skłodowska Curie",
"password": "radioactivity",
"email": "marie@example.org"
},
"carol": {
"id": "moss",
"displayName": "Maurice Moss",
"password": "vista",
"email": "moss@example.org"
}
}
The test scenarios that can run with predefined users are marked with the @predefined-users tag and can be run with the following command:
PREDEFINED_USERS=true \
PREDEFINED_USERS_FILE='<path-to>/users.json' \
pnpm test:e2e:playwright tests/e2e/specs/file-action/rename.feature --tags '@predefined-users'
The following tests cannot be run with predefined users:
All tests which are related to:
-
Admin Actions
-
Groups
The tests might show flakiness or fail due to the following reasons:
-
Slower network connection
-
Features enabled/disabled
-
Running latest tests against an older version of oCIS/Web
-
Large file uploads may take longer time
Usage of web-packages.txt in the Test Suite
Test suites may include the web-packages.txt file to denote which web packages changes affect the defined test scenarios. This information is used in CI pipelines to determine which test suites to run based on the changed web packages.
The web-packages.txt file should be included within the test suite directory as shown below:
└── tests/e2e/specs
└── admin-settings
├── users.feature
└── web-packages.txt
And the web-packages.txt file should list the dependent web packages, one per line, for example:
The package name should start with web- in order to be recognized correctly, if not, the line will be ignored.
|
web-app-files web-app-admin-settings