diff --git a/README.md b/README.md index 131389b..5108d60 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Browser Worker +# Browser Web Worker -[![Build](https://github.com/rwv/browser-worker/actions/workflows/build.yml/badge.svg)](https://github.com/rwv/browser-worker/actions/workflows/build.yml) +[![Build](https://github.com/rwv/browser-web-worker/actions/workflows/build.yml/badge.svg)](https://github.com/rwv/browser-web-worker/actions/workflows/build.yml) Run Web Workers in Node.js using a real Chrome browser via Puppeteer. @@ -16,7 +16,7 @@ Run Web Workers in Node.js using a real Chrome browser via Puppeteer. ## Installation ```bash -pnpm add browser-worker puppeteer +pnpm add browser-web-worker puppeteer ``` ## Usage @@ -24,7 +24,7 @@ pnpm add browser-worker puppeteer ### Basic Example ```typescript -import { createWorkerFromString } from "browser-worker"; +import { createWorkerFromString } from "browser-web-worker"; import puppeteer from "puppeteer"; // Launch browser @@ -57,7 +57,7 @@ import { createWorkerFromString, createWorkerFromFile, createWorkerFromURL, -} from "browser-worker"; +} from "browser-web-worker"; // 1. From a string const worker1 = await createWorkerFromString(workerScript, page); diff --git a/package.json b/package.json index 30943f3..a836dbc 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "browser-worker", + "name": "browser-web-worker", "version": "1.0.0", "description": "Run Web Workers in Node.js using a real Chrome browser via Puppeteer", "main": "lib/index.js", @@ -27,10 +27,10 @@ ], "author": "rwv", "license": "MIT", - "repository": "https://github.com/rwv/browser-worker", - "homepage": "https://github.com/rwv/browser-worker", + "repository": "https://github.com/rwv/browser-web-worker", + "homepage": "https://github.com/rwv/browser-web-worker", "bugs": { - "url": "https://github.com/rwv/browser-worker/issues" + "url": "https://github.com/rwv/browser-web-worker/issues" }, "packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee", "files": [ diff --git a/src/browser-worker.test.ts b/src/browser-web-worker.test.ts similarity index 88% rename from src/browser-worker.test.ts rename to src/browser-web-worker.test.ts index c925d1d..19d145b 100644 --- a/src/browser-worker.test.ts +++ b/src/browser-web-worker.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, vi, beforeAll } from "vitest"; import puppeteer, { Page, Browser } from "puppeteer"; import { createWorkerURLFromString } from "./utils"; -import { BrowserWorker } from "./browser-worker"; +import { BrowserWebWorker } from "./browser-web-worker"; const testWorkerString = ` self.addEventListener('message', (event) => { @@ -10,7 +10,7 @@ self.addEventListener('message', (event) => { }); `; -describe("BrowserWorker", async () => { +describe("BrowserWebWorker", async () => { let browser: Browser; let page: Page; let workerScriptURL: string; @@ -26,14 +26,14 @@ describe("BrowserWorker", async () => { }); it("should create a worker from string", async () => { - const worker = new BrowserWorker({ workerScriptURL, page }); + const worker = new BrowserWebWorker({ workerScriptURL, page }); await worker.initPromise; expect(worker).toBeDefined(); expect(worker.postMessage).toBeDefined(); }); it("should handle message communication", async () => { - const worker = new BrowserWorker({ workerScriptURL, page }); + const worker = new BrowserWebWorker({ workerScriptURL, page }); await worker.initPromise; const messagePromise = new Promise((resolve) => { @@ -50,7 +50,7 @@ describe("BrowserWorker", async () => { }); it("should handle addEventListener for messages", async () => { - const worker = new BrowserWorker({ workerScriptURL, page }); + const worker = new BrowserWebWorker({ workerScriptURL, page }); await worker.initPromise; const messagePromise = new Promise((resolve) => { @@ -67,7 +67,7 @@ describe("BrowserWorker", async () => { }); it("should handle removeEventListener", async () => { - const worker = new BrowserWorker({ workerScriptURL, page }); + const worker = new BrowserWebWorker({ workerScriptURL, page }); await worker.initPromise; const listener = vi.fn(); @@ -83,7 +83,7 @@ describe("BrowserWorker", async () => { }); it("should handle multiple event listeners", async () => { - const worker = new BrowserWorker({ workerScriptURL, page }); + const worker = new BrowserWebWorker({ workerScriptURL, page }); await worker.initPromise; const listener1 = vi.fn(); @@ -114,7 +114,7 @@ describe("BrowserWorker", async () => { page, ); - const worker = new BrowserWorker({ + const worker = new BrowserWebWorker({ workerScriptURL: invalidScriptURL, page, }); diff --git a/src/browser-worker.ts b/src/browser-web-worker.ts similarity index 99% rename from src/browser-worker.ts rename to src/browser-web-worker.ts index 155b5fe..0dd9684 100644 --- a/src/browser-worker.ts +++ b/src/browser-web-worker.ts @@ -13,7 +13,7 @@ declare global { } } -export class BrowserWorker implements Worker, EventTarget { +export class BrowserWebWorker implements Worker, EventTarget { private readonly page: PuppeteerPage; private readonly workerScriptURL: string; private readonly eventListeners: Map< diff --git a/src/create.test.ts b/src/create.test.ts index d2e6b9d..92367cf 100644 --- a/src/create.test.ts +++ b/src/create.test.ts @@ -43,7 +43,7 @@ describe("create worker", async () => { }); it("should handle message communication using createWorkerFromFile", async () => { - const dir = await mkdtemp(path.join(tmpdir(), "browser-worker-test-")); + const dir = await mkdtemp(path.join(tmpdir(), "browser-web-worker-test-")); const filePath = path.join(dir, `test-worker.js`); await fs.writeFile(filePath, testWorkerString); const worker = await createWorkerFromFile(filePath, page); diff --git a/src/create.ts b/src/create.ts index 8dd296e..34507f7 100644 --- a/src/create.ts +++ b/src/create.ts @@ -1,6 +1,6 @@ import { Page as PuppeteerPage } from "puppeteer"; import { createWorkerURLFromString } from "./utils"; -import { BrowserWorker } from "./browser-worker"; +import { BrowserWebWorker } from "./browser-web-worker"; import fs from "fs/promises"; export async function createWorkerFromString( @@ -12,7 +12,7 @@ export async function createWorkerFromString( page, ); - const worker = new BrowserWorker({ workerScriptURL, page }); + const worker = new BrowserWebWorker({ workerScriptURL, page }); await worker.initPromise; return worker; } @@ -21,7 +21,7 @@ export async function createWorkerFromURL( workerScriptURL: string, page: PuppeteerPage, ) { - const worker = new BrowserWorker({ workerScriptURL, page }); + const worker = new BrowserWebWorker({ workerScriptURL, page }); await worker.initPromise; return worker; } diff --git a/src/index.ts b/src/index.ts index 26779df..3cc09e5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ /* v8 ignore start */ -export { BrowserWorker as default } from "./browser-worker"; +export { BrowserWebWorker as default } from "./browser-web-worker"; -export { BrowserWorker } from "./browser-worker"; +export { BrowserWebWorker } from "./browser-web-worker"; export { createWorkerFromString, createWorkerFromFile,