|  | 
|  | 1 | +# Integration Testing | 
|  | 2 | + | 
|  | 3 | +This folder contains the integration tests of the extension. | 
|  | 4 | + | 
|  | 5 | +They are defined using [Playwright](https://playwright.dev/docs/intro) test runner | 
|  | 6 | +and [Galata](https://github.com/jupyterlab/jupyterlab/tree/main/galata) helper. | 
|  | 7 | + | 
|  | 8 | +The Playwright configuration is defined in [playwright.config.js](./playwright.config.js). | 
|  | 9 | + | 
|  | 10 | +The JupyterLab server configuration to use for the integration test is defined | 
|  | 11 | +in [jupyter_server_test_config.py](./jupyter_server_test_config.py). | 
|  | 12 | + | 
|  | 13 | +The default configuration will produce video for failing tests and an HTML report. | 
|  | 14 | + | 
|  | 15 | +> There is a UI mode that you may like; see [that video](https://www.youtube.com/watch?v=jF0yA-JLQW0). | 
|  | 16 | +
 | 
|  | 17 | +## Run the tests | 
|  | 18 | + | 
|  | 19 | +> All commands are assumed to be executed from the root directory | 
|  | 20 | +
 | 
|  | 21 | +To run the tests, you need to: | 
|  | 22 | + | 
|  | 23 | +1. Compile the extension: | 
|  | 24 | + | 
|  | 25 | +```sh | 
|  | 26 | +jlpm install | 
|  | 27 | +jlpm build:prod | 
|  | 28 | +``` | 
|  | 29 | + | 
|  | 30 | +> Check the extension is installed in JupyterLab. | 
|  | 31 | +
 | 
|  | 32 | +2. Install test dependencies (needed only once): | 
|  | 33 | + | 
|  | 34 | +```sh | 
|  | 35 | +cd ./ui-tests | 
|  | 36 | +jlpm install | 
|  | 37 | +jlpm playwright install | 
|  | 38 | +cd .. | 
|  | 39 | +``` | 
|  | 40 | + | 
|  | 41 | +3. Execute the [Playwright](https://playwright.dev/docs/intro) tests: | 
|  | 42 | + | 
|  | 43 | +```sh | 
|  | 44 | +cd ./ui-tests | 
|  | 45 | +jlpm playwright test | 
|  | 46 | +``` | 
|  | 47 | + | 
|  | 48 | +Test results will be shown in the terminal. In case of any test failures, the test report | 
|  | 49 | +will be opened in your browser at the end of the tests execution; see | 
|  | 50 | +[Playwright documentation](https://playwright.dev/docs/test-reporters#html-reporter) | 
|  | 51 | +for configuring that behavior. | 
|  | 52 | + | 
|  | 53 | +## Update the tests snapshots | 
|  | 54 | + | 
|  | 55 | +> All commands are assumed to be executed from the root directory | 
|  | 56 | +
 | 
|  | 57 | +If you are comparing snapshots to validate your tests, you may need to update | 
|  | 58 | +the reference snapshots stored in the repository. To do that, you need to: | 
|  | 59 | + | 
|  | 60 | +1. Compile the extension: | 
|  | 61 | + | 
|  | 62 | +```sh | 
|  | 63 | +jlpm install | 
|  | 64 | +jlpm build:prod | 
|  | 65 | +``` | 
|  | 66 | + | 
|  | 67 | +> Check the extension is installed in JupyterLab. | 
|  | 68 | +
 | 
|  | 69 | +2. Install test dependencies (needed only once): | 
|  | 70 | + | 
|  | 71 | +```sh | 
|  | 72 | +cd ./ui-tests | 
|  | 73 | +jlpm install | 
|  | 74 | +jlpm playwright install | 
|  | 75 | +cd .. | 
|  | 76 | +``` | 
|  | 77 | + | 
|  | 78 | +3. Execute the [Playwright](https://playwright.dev/docs/intro) command: | 
|  | 79 | + | 
|  | 80 | +```sh | 
|  | 81 | +cd ./ui-tests | 
|  | 82 | +jlpm playwright test -u | 
|  | 83 | +``` | 
|  | 84 | + | 
|  | 85 | +> Some discrepancy may occurs between the snapshots generated on your computer and | 
|  | 86 | +> the one generated on the CI. To ease updating the snapshots on a PR, you can | 
|  | 87 | +> type `please update playwright snapshots` to trigger the update by a bot on the CI. | 
|  | 88 | +> Once the bot has computed new snapshots, it will commit them to the PR branch. | 
|  | 89 | +
 | 
|  | 90 | +## Create tests | 
|  | 91 | + | 
|  | 92 | +> All commands are assumed to be executed from the root directory | 
|  | 93 | +
 | 
|  | 94 | +To create tests, the easiest way is to use the code generator tool of playwright: | 
|  | 95 | + | 
|  | 96 | +1. Compile the extension: | 
|  | 97 | + | 
|  | 98 | +```sh | 
|  | 99 | +jlpm install | 
|  | 100 | +jlpm build:prod | 
|  | 101 | +``` | 
|  | 102 | + | 
|  | 103 | +> Check the extension is installed in JupyterLab. | 
|  | 104 | +
 | 
|  | 105 | +2. Install test dependencies (needed only once): | 
|  | 106 | + | 
|  | 107 | +```sh | 
|  | 108 | +cd ./ui-tests | 
|  | 109 | +jlpm install | 
|  | 110 | +jlpm playwright install | 
|  | 111 | +cd .. | 
|  | 112 | +``` | 
|  | 113 | + | 
|  | 114 | +3. Start the server: | 
|  | 115 | + | 
|  | 116 | +```sh | 
|  | 117 | +cd ./ui-tests | 
|  | 118 | +jlpm start | 
|  | 119 | +``` | 
|  | 120 | + | 
|  | 121 | +4. Execute the [Playwright code generator](https://playwright.dev/docs/codegen) in **another terminal**: | 
|  | 122 | + | 
|  | 123 | +```sh | 
|  | 124 | +cd ./ui-tests | 
|  | 125 | +jlpm playwright codegen localhost:8888 | 
|  | 126 | +``` | 
|  | 127 | + | 
|  | 128 | +## Debug tests | 
|  | 129 | + | 
|  | 130 | +> All commands are assumed to be executed from the root directory | 
|  | 131 | +
 | 
|  | 132 | +To debug tests, a good way is to use the inspector tool of playwright: | 
|  | 133 | + | 
|  | 134 | +1. Compile the extension: | 
|  | 135 | + | 
|  | 136 | +```sh | 
|  | 137 | +jlpm install | 
|  | 138 | +jlpm build:prod | 
|  | 139 | +``` | 
|  | 140 | + | 
|  | 141 | +> Check the extension is installed in JupyterLab. | 
|  | 142 | +
 | 
|  | 143 | +2. Install test dependencies (needed only once): | 
|  | 144 | + | 
|  | 145 | +```sh | 
|  | 146 | +cd ./ui-tests | 
|  | 147 | +jlpm install | 
|  | 148 | +jlpm playwright install | 
|  | 149 | +cd .. | 
|  | 150 | +``` | 
|  | 151 | + | 
|  | 152 | +3. Execute the Playwright tests in [debug mode](https://playwright.dev/docs/debug): | 
|  | 153 | + | 
|  | 154 | +```sh | 
|  | 155 | +cd ./ui-tests | 
|  | 156 | +jlpm playwright test --debug | 
|  | 157 | +``` | 
|  | 158 | + | 
|  | 159 | +## Upgrade Playwright and the browsers | 
|  | 160 | + | 
|  | 161 | +To update the web browser versions, you must update the package `@playwright/test`: | 
|  | 162 | + | 
|  | 163 | +```sh | 
|  | 164 | +cd ./ui-tests | 
|  | 165 | +jlpm up "@playwright/test" | 
|  | 166 | +jlpm playwright install | 
|  | 167 | +``` | 
0 commit comments