Skip to content

Commit 60e900a

Browse files
authored
Improving tests (#118)
* Try unit tests * Tolerate playwright absence * Correct handling of environments list * Add end to end tests * Fix list removal * Fix playwright setup * Optimize testing jobs * Correct pytest target for coverage job * Fix right of e2e test folder * Deactivate integration tests for now * Correct installation of coveralls * Fix shell
1 parent fb97583 commit 60e900a

16 files changed

+24311
-54
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
**/node_modules/

.github/workflows/build.yml

+69-46
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,94 @@ on:
77
branches: "*"
88

99
jobs:
10-
test-conda-3x:
11-
name: Test Conda Python ${{ matrix.python-version }}
10+
test-backend-conda:
11+
name: Test server with Conda Python ${{ matrix.python-version }}
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
1515
python-version: [3.6, 3.9]
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v2
19-
2019
- name: Cache conda
2120
uses: actions/cache@v2
2221
env:
2322
# Increase this value to reset cache
24-
CACHE_NUMBER: 2
23+
CACHE_NUMBER: 3
2524
with:
2625
path: ~/conda_pkgs_dir
2726
key: ${{ runner.os }}-conda-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
2827
restore-keys: |
2928
${{ runner.os }}-conda-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
3029
${{ runner.os }}-conda-${{ matrix.python-version }}
30+
- name: Setup Python ${{ matrix.python-version }}
31+
uses: conda-incubator/setup-miniconda@v2
32+
with:
33+
activate-environment: test_gator
34+
auto-update-conda: true
35+
channels: conda-forge
36+
python-version: ${{ matrix.python-version }}
37+
show-channel-urls: true
38+
use-only-tar-bz2: true
39+
- name: Install dependencies
40+
run: |
41+
conda activate test_gator
42+
conda install -n test_gator --file requirements_dev.txt
43+
pip install .
44+
shell: bash -l {0}
45+
- name: Test the server extension
46+
run: |
47+
conda activate test_gator
48+
python -m pytest mamba_gator
49+
shell: bash -l {0}
3150

32-
- name: Get yarn cache directory path
33-
id: yarn-cache-dir-path
34-
run: echo "::set-output name=dir::$(yarn cache dir)"
35-
- name: Setup yarn cache
51+
test-backend-mamba:
52+
name: Test server with Mamba Python ${{ matrix.python-version }}
53+
runs-on: ubuntu-latest
54+
strategy:
55+
matrix:
56+
# Skip 3.7 as it is used for integration tests
57+
python-version: [3.6, 3.8, 3.9]
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v2
61+
- name: Cache conda
3662
uses: actions/cache@v2
37-
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
3863
env:
39-
# Increase this value to reset cache
40-
CACHE_NUMBER: 4
64+
# Increase this value to reset cache if requirements_dev.txt has not changed
65+
CACHE_NUMBER: 1
4166
with:
42-
path: |
43-
${{ steps.yarn-cache-dir-path.outputs.dir }}
44-
**/node_modules
45-
key: ${{ runner.os }}-yarn-${{ env.CACHE_NUMBER }}-${{ hashFiles('**/yarn.lock') }}
67+
path: ~/conda_pkgs_dir
68+
key: ${{ runner.os }}-mamba-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
4669
restore-keys: |
47-
${{ runner.os }}-yarn-${{ env.CACHE_NUMBER }}
48-
${{ runner.os }}-yarn-
49-
70+
${{ runner.os }}-mamba-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
71+
${{ runner.os }}-mamba-${{ matrix.python-version }}
5072
- name: Setup Python ${{ matrix.python-version }}
5173
uses: conda-incubator/setup-miniconda@v2
5274
with:
5375
activate-environment: test_gator
5476
auto-update-conda: true
5577
channels: conda-forge
78+
mamba-version: "*"
5679
python-version: ${{ matrix.python-version }}
5780
show-channel-urls: true
5881
use-only-tar-bz2: true
59-
6082
- name: Install dependencies
6183
run: |
6284
conda activate test_gator
63-
conda install -n test_gator --file requirements_dev.txt
64-
yarn install
85+
mamba install -n test_gator --file requirements_dev.txt
86+
conda install -n test_gator jupyterlab=2
6587
pip install .
88+
# Check pip dependencies
89+
pip check
6690
shell: bash -l {0}
67-
68-
- name: Test the extension
91+
- name: Test the server extension
6992
run: |
7093
conda activate test_gator
7194
python -m pytest mamba_gator
7295
shell: bash -l {0}
7396

74-
test-conda-os:
97+
test-all-os:
7598
name: Test Conda Python 3.7 on ${{ matrix.os }}
7699
runs-on: ${{ matrix.os }}
77100
continue-on-error: true
@@ -150,28 +173,23 @@ jobs:
150173
if [ "${OS_RUNNER}" != "windows-latest" ]; then python -m jupyterlab.browser_check; fi
151174
shell: bash -l {0}
152175

153-
test-mamba-3x:
154-
name: Test Mamba Python ${{ matrix.python-version }}
176+
test-integration:
177+
name: All tests on Ubuntu Mamba Python 3.7
155178
runs-on: ubuntu-latest
156-
strategy:
157-
matrix:
158-
python-version: [3.6, 3.7, 3.8, 3.9]
159179
steps:
160180
- name: Checkout
161181
uses: actions/checkout@v2
162-
163182
- name: Cache conda
164183
uses: actions/cache@v2
165184
env:
166185
# Increase this value to reset cache if requirements_dev.txt has not changed
167186
CACHE_NUMBER: 0
168187
with:
169188
path: ~/conda_pkgs_dir
170-
key: ${{ runner.os }}-mamba-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
189+
key: ${{ runner.os }}-mamba-3.7-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
171190
restore-keys: |
172-
${{ runner.os }}-mamba-${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
173-
${{ runner.os }}-mamba-${{ matrix.python-version }}
174-
191+
${{ runner.os }}-mamba-3.7-${{ env.CACHE_NUMBER }}-${{ hashFiles('requirements_dev.txt') }}
192+
${{ runner.os }}-mamba-3.7
175193
- name: Get yarn cache directory path
176194
id: yarn-cache-dir-path
177195
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -190,14 +208,14 @@ jobs:
190208
${{ runner.os }}-yarn-${{ env.CACHE_NUMBER }}
191209
${{ runner.os }}-yarn-
192210
193-
- name: Setup Python ${{ matrix.python-version }}
211+
- name: Setup Python 3.7
194212
uses: conda-incubator/setup-miniconda@v2
195213
with:
196214
activate-environment: test_gator
197215
auto-update-conda: true
198216
channels: conda-forge
199217
mamba-version: "*"
200-
python-version: ${{ matrix.python-version }}
218+
python-version: "3.7"
201219
show-channel-urls: true
202220
use-only-tar-bz2: true
203221

@@ -216,10 +234,13 @@ jobs:
216234
- name: Test the extension
217235
run: |
218236
conda activate test_gator
237+
# Run linter
219238
flake8 setup.py mamba_gator
239+
yarn run eslint:check
240+
241+
# Run test
220242
coverage run -m pytest mamba_gator
221243
coverage report
222-
yarn run eslint:check
223244
yarn run test
224245
225246
jupyter serverextension list 1>serverextensions 2>&1
@@ -228,6 +249,13 @@ jobs:
228249
cat labextensions | grep "@mamba-org/gator-lab.*OK"
229250
python -m jupyterlab.browser_check
230251
shell: bash -l {0}
252+
# - name: Integration tests
253+
# run: |
254+
# chmod -R a+rx ./e2e-tests
255+
# docker-compose -f "docker-compose.yml" run e2e ./e2e-tests/run_e2e.sh
256+
# - name: Stop containers
257+
# if: always()
258+
# run: docker-compose -f "docker-compose.yml" down
231259

232260
- name: Install Ruby
233261
uses: ruby/setup-ruby@v1
@@ -246,16 +274,11 @@ jobs:
246274
cd ../../
247275
python -m coveralls --merge=common-jscoverage.json
248276
shell: bash -l {0}
249-
250-
coveralls:
251-
name: Finish Coveralls
252-
needs: test-mamba-3x
253-
runs-on: ubuntu-latest
254-
container: python:3-slim
255-
steps:
256-
- name: Finished
277+
- name: Coverage finished
257278
run: |
258-
pip3 install --upgrade coveralls
279+
conda activate test_gator
280+
pip install --upgrade coveralls
259281
coveralls --finish
260282
env:
261283
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
284+
shell: bash -l {0}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ mamba_gator/labextension/**
7373
packages/navigator/webpack-report.html
7474
mamba_gator/nbextension/static/**
7575
!mamba_gator/nbextension/static/favicon.svg
76+
.playwright/

docker-compose.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "3.7"
2+
3+
services:
4+
notebook:
5+
build:
6+
context: .
7+
dockerfile: ./e2e-tests/Dockerfile
8+
command: ["start-notebook.sh", "--no-browser", "--ip=0.0.0.0", "--port=8888", "--NotebookApp.token=''", "--NotebookApp.allow_remote_access=True"]
9+
networks:
10+
- frontend
11+
ports:
12+
- 8888:8888
13+
14+
e2e:
15+
# FIXME when https://github.com/microsoft/playwright-python/issues/338 is fixed, use official python-playwright image
16+
image: mcr.microsoft.com/playwright:focal
17+
entrypoint: ["./e2e-tests/wait-for-it.sh", "notebook:8888", "--strict", "--timeout=10", "--"]
18+
command: './e2e-tests/run_e2e.sh'
19+
networks:
20+
- frontend
21+
depends_on:
22+
- notebook
23+
volumes:
24+
- $PWD:/tmp/mamba_gator
25+
working_dir: /tmp/mamba_gator
26+
27+
networks:
28+
frontend:

e2e-tests/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM jupyter/minimal-notebook
2+
3+
COPY . /tmp/gator
4+
5+
RUN python -m pip install /tmp/gator

e2e-tests/conftest.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
from slugify import slugify
5+
6+
7+
def take_screenshot(page, uid):
8+
screenshot_dir = Path(".playwright") / "screenshots"
9+
screenshot_dir.mkdir(exist_ok=True)
10+
page.screenshot(path=str(screenshot_dir / f"{uid}.png"))
11+
12+
13+
def pytest_runtest_makereport(item, call) -> None:
14+
if call.when == "call":
15+
if call.excinfo is not None:
16+
if "page" in item.funcargs:
17+
take_screenshot(item.funcargs["page"], slugify(item.nodeid))
18+
if "context" in item.funcargs:
19+
for idx, page in enumerate(item.funcargs["context"].pages):
20+
take_screenshot(page, "-".join((slugify(item.nodeid), str(idx))))
21+
if "browser" in item.funcargs:
22+
for cidx, context in enumerate(item.funcargs["browser"].contexts):
23+
for idx, page in enumerate(context.pages):
24+
take_screenshot(
25+
page, "-".join((slugify(item.nodeid), str(cidx), str(idx)))
26+
)
27+
28+
29+
@pytest.fixture(scope="session")
30+
def browser_context_args(browser_context_args):
31+
return {
32+
**browser_context_args,
33+
"recordVideo": {"dir": str(Path(".playwright") / "videos/")},
34+
}

0 commit comments

Comments
 (0)