Skip to content

Commit bce87e3

Browse files
arjxn-pymartinRenougithub-actions[bot]pre-commit-ci[bot]
authored
Configure UI tests for Lite Deployment (#689)
* Configure UI tests for Lite Deployment * add script to start lite server * not needed * Configure lite tests * Change playwright report name * Fix test command * Fix test cmd * Do jlpm install * try correct path * Try another path * try without cd * try corrected path * try ls * try ls .. * Update .github/workflows/build.yml Co-authored-by: martinRenou <[email protected]> * Add a step to upload lite-artifacts * prevent name conflict * try ./lite/dist again * debug path * run lite tests on 8888 only * try again on 8866 * try defining only port * port 8888 * could this be it? * use some options same as jupyterlite * add option to Galata take control of the app object * try this * update lock file * reduce timeout, comment not needed part * increase timeout a little * maybe not * And maybe? * temporarily try opening just filename * Bump galata * try a test from jupyterlite * just leave one test to run for now * just run extension activation test * not required * try another test * let's see * seems to work * Separate file for lite tests? * nope * Uncomment tests * test:lite * ignore lite test for lab * install jcad metapackage in update snapshots * add updatelite script * Update Playwright Snapshots * add a test for notebook * fix test * try with existing file * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * skip * increase timeout * test works for notebook * remove timeouts for now * Update Playwright Snapshots * uncomment lab ui tests * use only viewport of jcad * Update Playwright Snapshots * a 10 second timeout before taking ss * Update Playwright Snapshots * Cleanup Co-authored-by: martinRenou <[email protected]> * minor fixes * might have been pushed by mistake * more cleanup --------- Co-authored-by: martinRenou <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4af2c27 commit bce87e3

File tree

13 files changed

+1658
-1572
lines changed

13 files changed

+1658
-1572
lines changed

.github/workflows/build.yml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ jobs:
244244
working-directory: lite
245245
run: |
246246
set -eux
247-
mkdir -p content && cp ../examples/*.jcad ../examples/*.STEP ../examples/*.stl ../examples/Notebook.ipynb ./content
247+
mkdir -p content && cp ../examples/*.jcad ../examples/*.STEP ../examples/*.stl ../examples/Notebook.ipynb ../examples/jcad.ipynb ./content
248248
jupyter lite build --contents content --output-dir dist
249249
250250
- name: Upload github-pages artifact
@@ -254,6 +254,13 @@ jobs:
254254
path: ./lite/dist
255255
retention-days: 30
256256

257+
- name: Upload lite artifact
258+
id: upload-lite-artifact
259+
uses: actions/upload-artifact@v4
260+
with:
261+
name: lite-artifacts
262+
path: ./lite/dist
263+
257264
- name: Save artifact data
258265
uses: trungleduc/appsharingspace-pr-comment/.github/actions/save-artifact-link@v2
259266
with:
@@ -275,3 +282,64 @@ jobs:
275282
- name: Deploy to GitHub Pages
276283
id: deployment
277284
uses: actions/deploy-pages@v4
285+
286+
integration-tests-lite:
287+
name: Integration tests Lite
288+
needs: build-lite
289+
runs-on: ubuntu-latest
290+
291+
env:
292+
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/pw-browsers
293+
294+
steps:
295+
- name: Checkout
296+
uses: actions/checkout@v3
297+
298+
- name: Install Conda environment with Micromamba
299+
uses: mamba-org/setup-micromamba@v1
300+
with:
301+
micromamba-version: '1.5.5-0'
302+
environment-name: cad
303+
create-args: >-
304+
python=3.9
305+
jupyterlab
306+
307+
- name: Download extension package
308+
uses: actions/download-artifact@v4
309+
with:
310+
name: lite-artifacts
311+
path: dist
312+
313+
- name: Install dependencies
314+
shell: bash -l {0}
315+
working-directory: ui-tests
316+
env:
317+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
318+
run: jlpm install
319+
320+
- name: Set up browser cache
321+
uses: actions/cache@v4
322+
with:
323+
path: |
324+
${{ github.workspace }}/pw-browsers
325+
key: ${{ runner.os }}-${{ hashFiles('ui-tests/yarn.lock') }}
326+
327+
- name: Install browser
328+
shell: bash -l {0}
329+
run: npx playwright install chromium
330+
working-directory: ui-tests
331+
332+
- name: Execute integration tests
333+
shell: bash -l {0}
334+
working-directory: ui-tests
335+
run: jlpm run test:lite
336+
337+
- name: Upload Playwright Test report
338+
id: upload-galata-artifact
339+
if: always()
340+
uses: actions/upload-artifact@v4
341+
with:
342+
name: jupytercad-lite-playwright-tests
343+
path: |
344+
ui-tests/test-results
345+
ui-tests/playwright-report

examples/jcad.ipynb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"vscode": {
8+
"languageId": "plaintext"
9+
}
10+
},
11+
"outputs": [],
12+
"source": [
13+
"from jupytercad import CadDocument\n",
14+
"doc = CadDocument()\n",
15+
"doc.add_cone().add_sphere(radius=0.8).cut(color='#ff0000')"
16+
]
17+
}
18+
],
19+
"metadata": {
20+
"language_info": {
21+
"name": "python"
22+
}
23+
},
24+
"nbformat": 4,
25+
"nbformat_minor": 2
26+
}

lite/jupyter-lite.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"jupyter-lite-schema-version": 0,
3-
"jupyter-config-data": {}
3+
"jupyter-config-data": {},
4+
"exposeAppInBrowser": true
45
}

ui-tests/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
"private": true,
66
"scripts": {
77
"start": "jupyter lab --config jupyter_server_test_config.py",
8+
"start:lite": "cd ../dist && python -m http.server -b 127.0.0.1 8000",
89
"test": "npx playwright test --workers 1",
10+
"test:lite": "npx playwright test tests/lite.spec.ts --workers 1 --config playwright-lite.config.js",
911
"test:update": "npx playwright test --update-snapshots",
1012
"test:updatelite": "jlpm run test:lite --update-snapshots",
1113
"test:debug": "PWDEBUG=1 npx playwright test --workers 1"
1214
},
1315
"devDependencies": {
14-
"@jupyterlab/galata": "^5.2.5",
16+
"@jupyterlab/galata": "^5.3.4",
1517
"@playwright/test": "^1.32.0",
1618
"@types/klaw-sync": "^6.0.1"
1719
},

ui-tests/playwright-lite.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Configuration for Playwright using default from @jupyterlab/galata
3+
*/
4+
const baseConfig = require('@jupyterlab/galata/lib/playwright-config');
5+
6+
module.exports = {
7+
...baseConfig,
8+
webServer: {
9+
command: 'jlpm start:lite',
10+
url: 'http://localhost:8000/',
11+
timeout: 10 * 1000,
12+
reuseExistingServer: false
13+
},
14+
retries: 1,
15+
use: {
16+
...baseConfig.use,
17+
acceptDownloads: true,
18+
appPath: '',
19+
autoGoto: false,
20+
baseURL: 'http://localhost:8000',
21+
trace: 'retain-on-failure',
22+
video: 'retain-on-failure',
23+
},
24+
expect: {
25+
toMatchSnapshot: {
26+
maxDiffPixelRatio: 0.002,
27+
},
28+
},
29+
};

ui-tests/playwright.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ module.exports = {
2222
maxDiffPixelRatio: 0.002,
2323
},
2424
},
25+
testIgnore: ["tests/lite.spec.ts"],
2526
};

ui-tests/tests/lite.spec.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { expect, test, galata } from '@jupyterlab/galata';
2+
3+
test.use({ autoGoto: false });
4+
5+
test.describe('UI Test', () => {
6+
const fileList = ['test.jcad', '3M_CONNECTOR.STEP', 'fan.stl'];
7+
let errors = 0;
8+
test.beforeEach(async ({ page }) => {
9+
page.setViewportSize({ width: 1920, height: 1080 });
10+
page.on('console', message => {
11+
if (message.type() === 'error') {
12+
console.log('ERROR MSG', message.text());
13+
errors += 1;
14+
}
15+
});
16+
});
17+
18+
test.afterEach(async ({ page }) => {
19+
errors = 0;
20+
});
21+
22+
for (const file of fileList) {
23+
test(`Should be able to render ${file} without error`, async ({
24+
browser
25+
}) => {
26+
const context = await browser.newContext();
27+
const page = await context.newPage();
28+
29+
await page.goto(`lab/index.html?path=${file}`, {
30+
waitUntil: 'domcontentloaded'
31+
});
32+
33+
await page.locator('div.jpcad-Spinner').waitFor({ state: 'hidden' });
34+
35+
if (await page.getByRole('button', { name: 'Ok' }).isVisible()) {
36+
await page.getByRole('button', { name: 'Ok' }).click();
37+
}
38+
39+
const main = await page.waitForSelector('.jp-MainAreaWidget', {
40+
state: 'visible'
41+
});
42+
43+
await page.waitForTimeout(10000);
44+
45+
expect(errors).toBe(0);
46+
if (main) {
47+
expect(await main.screenshot()).toMatchSnapshot({
48+
name: `Render-${file}.png`,
49+
maxDiffPixelRatio: 0.01
50+
});
51+
}
52+
});
53+
}
54+
55+
test('Should open jcad.ipynb and execute it', async ({ browser }) => {
56+
const context = await browser.newContext();
57+
const page = await context.newPage();
58+
await page.goto('lab/index.html?path=jcad.ipynb', {
59+
waitUntil: 'domcontentloaded'
60+
});
61+
62+
const Notebook = await page.waitForSelector('.jp-Notebook', {
63+
state: 'visible'
64+
});
65+
await Notebook.click();
66+
67+
await page.keyboard.press('Control+Enter');
68+
69+
await page.locator('.jp-InputArea-prompt >> text="[1]:"').first().waitFor();
70+
71+
const outputErrors = await page.$$('.jp-OutputArea-error');
72+
expect(outputErrors.length).toBe(0);
73+
74+
const jcadWidget = await page.waitForSelector(
75+
'.jupytercad-notebook-widget',
76+
{
77+
state: 'visible'
78+
}
79+
);
80+
81+
expect(await jcadWidget.screenshot()).toMatchSnapshot({
82+
name: 'Render-notebook.png',
83+
maxDiffPixelRatio: 0.01
84+
});
85+
});
86+
});
12.7 KB
Loading
12.7 KB
Loading
18.8 KB
Loading

0 commit comments

Comments
 (0)