From 447bc3286e51704b3ed4b937eb7516f5a02d7e04 Mon Sep 17 00:00:00 2001 From: Wolfger Schramm Date: Fri, 28 Jun 2024 17:49:46 +0200 Subject: [PATCH] add first e2e tests to shae-worker --- .../shadow-ents-e2e/pages/shae-worker.html | 3 +- .../shadow-ents-e2e/src/remote-worker-env.js | 44 +++++++++++++++++++ packages/shadow-ents-e2e/src/shae-worker.js | 32 +++++++++----- .../shadow-ents-e2e/tests/shae-worker.spec.ts | 18 ++++++++ 4 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 packages/shadow-ents-e2e/src/remote-worker-env.js create mode 100644 packages/shadow-ents-e2e/tests/shae-worker.spec.ts diff --git a/packages/shadow-ents-e2e/pages/shae-worker.html b/packages/shadow-ents-e2e/pages/shae-worker.html index b00bed3..2e55986 100644 --- a/packages/shadow-ents-e2e/pages/shae-worker.html +++ b/packages/shadow-ents-e2e/pages/shae-worker.html @@ -7,7 +7,8 @@ shae-worker - + +
diff --git a/packages/shadow-ents-e2e/src/remote-worker-env.js b/packages/shadow-ents-e2e/src/remote-worker-env.js new file mode 100644 index 0000000..2b97b5a --- /dev/null +++ b/packages/shadow-ents-e2e/src/remote-worker-env.js @@ -0,0 +1,44 @@ +import {ComponentContext, RemoteWorkerEnv, ShadowEnv, ViewComponent} from '@spearwolf/shadow-ents'; +import './style.css'; +import {testAsyncAction} from './testAsyncAction.js'; +import {testBooleanAction} from './testBooleanAction.js'; + +main(); + +async function main() { + const shadowEnv = new ShadowEnv(); + + shadowEnv.view = ComponentContext.get(); + shadowEnv.envProxy = new RemoteWorkerEnv(); + + window.shadowEnv = shadowEnv; + console.log('shadowEnv', shadowEnv); + + await testAsyncAction('shadow-env-ready', async () => { + await shadowEnv.ready(); + }); + + await testAsyncAction('shadow-env-importScript', async () => { + await shadowEnv.envProxy.importScript('/mod-hello.js'); + }); + + testBooleanAction('shadow-env-isReady', shadowEnv.isReady); + + const foo = new ViewComponent('foo'); + foo.setProperty('xyz', 123); + + foo.on('helloFromFoo', (...args) => { + console.log('HELLO', ...args); + }); + + const bar = new ViewComponent('bar', {parent: foo}); + bar.setProperty('plah', 666); + + await testAsyncAction('shadow-env-1st-sync', async () => { + await shadowEnv.sync(); + }); + + await testAsyncAction('shadow-env-hello', async () => { + await foo.onceAsync('helloFromFoo'); + }); +} diff --git a/packages/shadow-ents-e2e/src/shae-worker.js b/packages/shadow-ents-e2e/src/shae-worker.js index a26e9d2..d119bd7 100644 --- a/packages/shadow-ents-e2e/src/shae-worker.js +++ b/packages/shadow-ents-e2e/src/shae-worker.js @@ -7,20 +7,32 @@ import {testBooleanAction} from './testBooleanAction.js'; main(); async function main() { - const worker = document.getElementById('worker'); - - window.worker = worker; - console.log('shae-worker element', worker); + const worker0 = document.getElementById('worker0'); + window.worker0 = worker0; + console.log('shae-worker #worker0', worker0); await testAsyncAction('shae-worker-whenDefined', () => customElements.whenDefined('shae-worker')); - const shadowEnv = worker.shadowEnv; - window.shadowEnv = shadowEnv; - console.log('shadowEnv', shadowEnv); + const shadowEnv0 = worker0.shadowEnv; + window.shadowEnv0 = shadowEnv0; + console.log('shadowEnv0', shadowEnv0); + + testBooleanAction('worker0-ns', () => worker0.ns === GlobalNS); + testAsyncAction('worker0-is-remote-env', () => shadowEnv0.envProxy.workerLoaded); + + await testAsyncAction('worker0-env-ready', async () => { + await shadowEnv0.ready(); + }); + + const worker1 = document.getElementById('worker1'); + const shadowEnv1 = worker1.shadowEnv; + window.shadowEnv1 = shadowEnv1; + console.log('shadowEnv1', shadowEnv1); - testBooleanAction('shae-worker-ns', () => worker.ns === GlobalNS); + testBooleanAction('worker1-ns', () => worker1.ns === 'local'); + testBooleanAction('worker1-is-local-env', () => shadowEnv1.envProxy.kernel != null); - await testAsyncAction('shadow-env-ready', async () => { - await shadowEnv.ready(); + await testAsyncAction('worker1-env-ready', async () => { + await shadowEnv1.ready(); }); } diff --git a/packages/shadow-ents-e2e/tests/shae-worker.spec.ts b/packages/shadow-ents-e2e/tests/shae-worker.spec.ts new file mode 100644 index 0000000..6982854 --- /dev/null +++ b/packages/shadow-ents-e2e/tests/shae-worker.spec.ts @@ -0,0 +1,18 @@ +import {test} from '@playwright/test'; +import {lookupTests} from './lookupTests.js'; + +test.describe('shae-worker', () => { + test.beforeEach('goto page', async ({page}) => { + await page.goto('/pages/shae-worker.html'); + }); + + lookupTests([ + 'shae-worker-whenDefined', + 'worker0-ns', + 'worker0-is-remote-env', + 'worker0-env-ready', + 'worker1-ns', + 'worker1-is-local-env', + 'worker1-env-ready', + ]); +});