Skip to content

Commit

Permalink
Add ui tests (#12)
Browse files Browse the repository at this point in the history
* Add ui tests

* Add build cache

* Run docker in background
  • Loading branch information
trungleduc authored Jan 4, 2024
1 parent fd7ce53 commit c2ce83d
Show file tree
Hide file tree
Showing 10 changed files with 4,376 additions and 1 deletion.
85 changes: 85 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,91 @@ jobs:
jupyter labextension list 2>&1 | grep -ie "jupytercad-salome.*OK"
python -m jupyterlab.browser_check --no-browser-test
integration-tests:
name: Integration tests
needs: build
runs-on: ubuntu-latest

env:
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/pw-browsers

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Conda environment with Micromamba
uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: '1.5.5-0'
environment-name: cad
create-args: >-
jupyterlab=4
- name: Download extension package
uses: actions/download-artifact@v3
with:
name: extension-artifacts
path: ./ui-tests

- uses: docker/setup-buildx-action@v3

- name: Build docker image
uses: docker/build-push-action@v5
with:
context: ./ui-tests
file: ./ui-tests/Dockerfile
tags: jupytercad_salome
load: true
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Install dependencies
shell: bash -l {0}
working-directory: ui-tests
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
run: jlpm install

- name: Set up browser cache
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/pw-browsers
key: ${{ runner.os }}-${{ hashFiles('ui-tests/yarn.lock') }}

- name: Install browser
shell: bash -l {0}
run: npx playwright install chromium
working-directory: ui-tests

- name: Start Jupyterlab
shell: bash -l {0}
working-directory: ui-tests
run: |
docker image ls
docker run -d -p 8888:8888 jupytercad_salome:latest
- name: Wait for Jupyterlab
uses: ifaxity/wait-on-action@v1
with:
resource: http-get://localhost:8888/lab
timeout: 360000

- name: Execute integration tests
shell: bash -l {0}
working-directory: ui-tests
run: |
npx playwright test
- name: Upload Playwright Test report
if: always()
uses: actions/upload-artifact@v3
with:
name: jupytercad-playwright-tests
path: |
ui-tests/test-results
ui-tests/playwright-report
check_links:
name: Check Links
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,7 @@ dmypy.json
.ruff_cache
.jupyter_ystore.db
_client/

**/ui-tests/test-results/
**/ui-tests/playwright-report/
**/ui-tests/*.whl
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"node_modules",
"dist",
"coverage",
"**/*.d.ts"
"**/*.d.ts",
"ui-tests/"
],
"eslintConfig": {
"extends": [
Expand Down
12 changes: 12 additions & 0 deletions ui-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM trungleduc/salome-docker:9.10.0

ARG MAMBA_DOCKERFILE_ACTIVATE=1

WORKDIR /home/$MAMBA_USER/cad

COPY --chown=$MAMBA_USER:$MAMBA_USER ./jupyter_server_test_config.py ./jupytercad_salome*.whl ./

RUN python -m pip install jupyterlab "jupytercad>=1.0.0a4" jupytercad_salome*.whl

EXPOSE 8888
CMD source /home/user/salome_src/default_env_launch.sh && jupyter lab --config jupyter_server_test_config.py
14 changes: 14 additions & 0 deletions ui-tests/jupyter_server_test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Server configuration for integration tests.
!! Never use this configuration in production because it
opens the server to the world and provide access to JupyterLab
JavaScript objects through the global window variable.
"""

from jupyterlab.galata import configure_jupyter_server

configure_jupyter_server(c) # noqa F821
c.LabApp.collaborative = True # noqa F821
c.ServerApp.ip = "0.0.0.0" # noqa F821
# Uncomment to set server log level to debug level
# c.ServerApp.log_level = "DEBUG"
19 changes: 19 additions & 0 deletions ui-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "jupytercad-salome-ui-tests",
"version": "1.0.0",
"description": "JupyterCad Integration Tests",
"private": true,
"scripts": {
"test": "npx playwright test --workers 1",
"test:update": "npx playwright test --update-snapshots",
"test:debug": "PWDEBUG=1 npx playwright test --workers 1"
},
"devDependencies": {
"@jupyterlab/galata": "^5.0.8",
"@playwright/test": "^1.32.0",
"@types/klaw-sync": "^6.0.1"
},
"dependencies": {
"klaw-sync": "^6.0.0"
}
}
23 changes: 23 additions & 0 deletions ui-tests/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Configuration for Playwright using default from @jupyterlab/galata
*/
const baseConfig = require('@jupyterlab/galata/lib/playwright-config');

module.exports = {
...baseConfig,
webServer: {
url: 'http://localhost:8888/lab',
timeout: 120 * 1000,
reuseExistingServer: true
},
retries: 1,
use: {
...baseConfig.use,
trace: 'off'
},
expect: {
toMatchSnapshot: {
maxDiffPixelRatio: 0.02
}
}
};
70 changes: 70 additions & 0 deletions ui-tests/tests/ui.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { expect, test, galata } from '@jupyterlab/galata';
import path from 'path';

test.use({ autoGoto: false });

test.describe('UI Test', () => {
test.describe('Extension activation test', () => {
test('should emit an activation console message', async ({
page,
request
}) => {
const logs: string[] = [];

page.on('console', message => {
logs.push(message.text());
});

await page.goto();

expect(
logs.filter(s => s === 'jupytercad:salome is activated!')
).toHaveLength(1);
});
});

test.describe('Mesh generation test', () => {
let errors = 0;
test.beforeEach(async ({ page }) => {
page.setViewportSize({ width: 1920, height: 1080 });
page.on('console', message => {
if (message.type() === 'error') {
errors += 1;
}
});
});

test.afterEach(async ({ page }) => {
errors = 0;
});

test(`Should be able to create mesh without error`, async ({ page }) => {
await page.goto();
await page.locator('div.jpcad-Spinner').waitFor({ state: 'hidden' });

await page
.getByLabel('notebook content')
.getByText('New JCAD File')
.click();
await page.getByRole('button', { name: 'New Box' }).click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByRole('button', { name: 'Mesh creation' }).click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.waitForTimeout(1000);
await page
.getByRole('tablist', { name: 'main sidebar' })
.getByRole('tab', { name: 'JupyterCad Control Panel' })
.click();
await page
.getByRole('tablist', { name: 'alternate sidebar' })
.getByRole('tab', { name: 'JupyterCad Control Panel' })
.click();
await page.waitForTimeout(500);
const main = await page.$('#jp-main-split-panel');
expect(errors).toBe(0);
if (main) {
expect(await main.screenshot()).toMatchSnapshot();
}
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c2ce83d

Please sign in to comment.