Currently there are only unit tests covering path normalization.
Running the unit tests:
yarn test
There is an extensive matrix of end-to-end tests that run on CI and test:
- All supported versions of Electron (2.0+)
- All major platforms (Windows, macOS and Linux)
- All features and integrations
- Event and session submission to mock Sentry server
- Successful bundling and subsequent event submission
Running the end-to-end tests:
yarn e2e
If the ELECTRON_VERSION
environment variable is set, only that version of Electron will be tested, otherwise all
versions will be tested.
Each individual e2e test consists of a test recipe which is a self contained application in its own right. There are simple functional test recipes and example app recipes.
Each recipe should contain:
recipe.yml
(details below)package.json
with a uniquename
- Events expected to be sent to the server (
event*.json
/session*.json
)
The recipe.yml
contains a number of optional keys with only description
required.
Run a single test by renaming to recipe.only.yml
.
Key | Type | Description |
---|---|---|
description |
string |
Friendly name displayed in test output |
category |
string |
Used for grouping test output |
command |
string |
Initialization/build command to run in app root |
condition |
string |
JavaScript expression for conditionally skipping a test |
timeout |
number |
Test timeout in seconds |
runTwice |
boolean |
If the application should be run twice |
expectedError |
string |
Expected error string in log output |
A JavaScript expression evaluated to boolean
and used to determine whether the test should be run for the current
platform and version of Electron. A number of variables are available to simplify usage:
namespace Global {
const platform: 'win32' | 'darwin' | 'linux';
const version: { major: number; minor: number; patch: number };
const supportsContextIsolation: boolean;
}
If a test should only run for Electron >= v5, the condition
would be:
version.major >= 5;
Some tests require that the application is run a second time so that crashes or sessions can be sent from the first run.
In the app, you can differentiate between the first and second run via the APP_FIRST_RUN
environment variable. Recipe
apps are expected to close themselves after the first run.
Some test are expected to throw errors or log output to the console. If expectedError
is defined, the test will fail
if the string cannot be found in the application log output.
- If
condition
is defined, it's evaluated and the recipe is skipped if it returnsfalse
- All files apart from
recipe.yaml
/event*.json
/session*.json
are copied to a temporary directory - Occurrences of
__DSN__
found in any file are replaced with the the mock server localhost DSN - If
@sentry/electron
is found in the dependencies inpackage.json
, the version is replaced with a path to the npm packed SDK in the project rootfile:../../../sentry-electron-{version}.tgz
- If
command
is defined, it's run viaspawnSync(command, { shell: true})
in the root of the recipe and a non-zero exit code results in test failure - Application is started with a specific Electron version
- If
runTwice == true
, the app will be started again when it closes - Wait for the expected number of events to be sent to the mock server
- Compare received events and ensure they match events found in
event*.json
/session*.json
files- Server events are normalized by replacing timestamps, versions and IDs so they can be compared
event*.json
/session*.json
may contain acondition
key so event matching can vary by platform or Electron version
- If
expectedError
is defined, ensure string is found in log output