Skip to content

Commit

Permalink
test(e2e): add test case for new web worker (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Feb 18, 2024
1 parent 7cfb0b0 commit b492547
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions e2e/cases/web-worker/new-worker/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import path from 'node:path';
import { expect, test } from '@playwright/test';
import { build, gotoPage } from '@e2e/helper';

test('should allow to build web-worker with new Worker', async ({ page }) => {
const rsbuild = await build({
cwd: __dirname,
runServer: true,
});

await gotoPage(page, rsbuild);
await expect(page.locator('#root')).toHaveText(
'The Answer to the Ultimate Question of Life, The Universe, and Everything: 42',
);
});
10 changes: 10 additions & 0 deletions e2e/cases/web-worker/new-worker/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const worker = new Worker(new URL('./worker.js', import.meta.url));

worker.postMessage({
question:
'The Answer to the Ultimate Question of Life, The Universe, and Everything',
});

worker.onmessage = ({ data: { answer } }) => {
document.getElementById('root').innerHTML = answer;
};
5 changes: 5 additions & 0 deletions e2e/cases/web-worker/new-worker/src/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
self.onmessage = ({ data: { question } }) => {
self.postMessage({
answer: `${question}: 42`,
});
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b492547

Please sign in to comment.