Skip to content

Commit

Permalink
Add simple e2e puppeteer test
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Dec 22, 2024
1 parent 0523664 commit 4291cdd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ jobs:
strategy:
matrix:
node: [ 18, 20, 22 ]
mode: [ 'dev', 'prod' ]
name: Node${{ matrix.node }}
env:
CI: true
START_MODE: ${{ matrix.mode }}
steps:
- uses: actions/checkout@v4
- name: Setup node ${{ matrix.node }}
Expand All @@ -20,6 +24,7 @@ jobs:
node-version: ${{ matrix.node }}
- run: npm install
- run: make public
- run: npm run test:e2e
- run: npm run build
- name: Archive production artifacts
uses: actions/upload-artifact@v4
Expand Down
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# # Pinning WASM build to last good revision (https://github.com/openscad/openscad-playground/issues/60)
# WASM_BUILD_URL=https://files.openscad.org/snapshots/OpenSCAD-2024.09.27.wasm20596-WebAssembly.zip
# # WASM_SNAPSHOT_JS_URL=https://files.openscad.org/snapshots/.snapshot_wasm.js
# # WASM_BUILD_URL=$(shell curl ${WASM_SNAPSHOT_JS_URL} 2>/dev/null | grep https | sed -E "s/.*(https:[^']+)'.*/\1/" )
# Pinning WASM build to https://github.com/openscad/openscad/pull/5515
WASM_BUILD_URL=https://output.circle-artifacts.com/output/job/9c136acb-541d-4f67-969c-fff96963c8aa/artifacts/0/wasm/OpenSCAD-2024.12.22.wasm21798_PR5515-WebAssembly-web.zip
# WASM_SNAPSHOT_JS_URL=https://files.openscad.org/snapshots/.snapshot_wasm.js
# WASM_BUILD_URL=$(shell curl ${WASM_SNAPSHOT_JS_URL} 2>/dev/null | grep https | sed -E "s/.*(https:[^']+)'.*/\1/" )

SINGLE_BRANCH_MAIN=--branch main --single-branch
SINGLE_BRANCH=--branch master --single-branch
Expand Down Expand Up @@ -54,18 +54,18 @@ src/wasm: libs/openscad-wasm
rm -f src/wasm
ln -sf "$(shell pwd)/libs/openscad-wasm" src/wasm

libs/openscad/build/openscad.js: libs/openscad
( cd libs/openscad && ./scripts/wasm-base-docker-run.sh emcmake cmake -B build -DCMAKE_BUILD_TYPE=Release -DEXPERIMENTAL=1 )
( cd libs/openscad && ./scripts/wasm-base-docker-run.sh /bin/bash -c "cmake --build build -j || cmake --build build -j2 || cmake --build build" )
# libs/openscad/build/openscad.js: libs/openscad
# ( cd libs/openscad && ./scripts/wasm-base-docker-run.sh emcmake cmake -B build -DCMAKE_BUILD_TYPE=Release -DEXPERIMENTAL=1 )
# ( cd libs/openscad && ./scripts/wasm-base-docker-run.sh /bin/bash -c "cmake --build build -j || cmake --build build -j2 || cmake --build build" )

libs/openscad-wasm: libs/openscad/build/openscad.js
mkdir -p libs/openscad-wasm
cp libs/openscad/build/openscad.* libs/openscad-wasm/

# libs/openscad-wasm:
# libs/openscad-wasm: libs/openscad/build/openscad.js
# mkdir -p libs/openscad-wasm
# wget ${WASM_BUILD_URL} -O libs/openscad-wasm.zip
# ( cd libs/openscad-wasm && unzip ../openscad-wasm.zip )
# cp libs/openscad/build/openscad.* libs/openscad-wasm/

libs/openscad-wasm:
mkdir -p libs/openscad-wasm
wget ${WASM_BUILD_URL} -O libs/openscad-wasm.zip
( cd libs/openscad-wasm && unzip ../openscad-wasm.zip )

public/openscad.js: libs/openscad-wasm libs/openscad-wasm/openscad.js
ln -sf libs/openscad-wasm/openscad.js public/openscad.js
Expand Down
12 changes: 12 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const isProd = process.env.START_MODE === 'prod';

module.exports = {
launch: {
headless: process.env.CI === "true",
},
server: {
command: `npm run start:${isProd ? 'prod' : 'dev'}`,
port: isProd ? 3000 : 4000,
launchTimeout: 180000,
},
};
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
preset: "jest-puppeteer",
testMatch: [
"**/tests/**/*.js",
],
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
"uzip": "^0.20201231.0"
},
"scripts": {
"start": "concurrently 'npx webpack serve --mode=development' 'NODE_ENV=development npx rollup --config openscad-worker.rollup.config.js --watch'",
"test:e2e": "jest",
"start:dev": "concurrently 'npx webpack serve --mode=development' 'NODE_ENV=development npx rollup --config openscad-worker.rollup.config.js --watch'",
"start:prod": "PUBLIC_URL=http://localhost:3000/dist/ npm run build && npx serve",
"start": "npm run start:dev",
"build": "NODE_ENV=production npx rollup --config openscad-worker.rollup.config.js && webpack --mode=production"
},
"eslintConfig": {
Expand Down Expand Up @@ -70,7 +72,10 @@
"concurrently": "^7.6.0",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.8.1",
"jest": "^29.7.0",
"jest-puppeteer": "^11.0.0",
"livereload": "^0.9.3",
"puppeteer": "^23.11.1",
"rollup": "^2.79.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-css": "^1.0.0",
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const longTimeout = 60000;

const isProd = process.env.START_MODE === 'prod';
const url = isProd ? 'http://localhost:3000/dist/' : 'http://localhost:4000';

describe('e2e', () => {
test('should load the page', async () => {
const messages = [];
page.on('console', (msg) => messages.push({type: msg.type(), text: msg.text()}));
page.goto(url);
await page.waitForSelector('model-viewer');

console.log('Messages:', JSON.stringify(messages, null, 2));

const errors = messages.filter(msg => msg.type === 'error');
expect(errors).toHaveLength(0);

const successMessage = messages.filter(msg => msg.type === 'debug' && msg.text === 'stderr: Top level object is a list of objects:');
expect(successMessage).toHaveLength(1);
}, longTimeout);
});

0 comments on commit 4291cdd

Please sign in to comment.