Skip to content

Commit

Permalink
add first e2e tests to shae-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
spearwolf committed Jun 28, 2024
1 parent 465577c commit 447bc32
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/shadow-ents-e2e/pages/shae-worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<title>shae-worker</title>
</head>
<body>
<shae-worker id="worker"></shae-worker>
<shae-worker id="worker0"></shae-worker>
<shae-worker id="worker1" local ns="local"></shae-worker>
<section id="tests"></section>
<script type="module" src="/src/shae-worker.js"></script>
</body>
Expand Down
44 changes: 44 additions & 0 deletions packages/shadow-ents-e2e/src/remote-worker-env.js
Original file line number Diff line number Diff line change
@@ -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');
});
}
32 changes: 22 additions & 10 deletions packages/shadow-ents-e2e/src/shae-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
18 changes: 18 additions & 0 deletions packages/shadow-ents-e2e/tests/shae-worker.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
]);
});

0 comments on commit 447bc32

Please sign in to comment.