diff --git a/.vscode/settings.json b/.vscode/settings.json index 58f2f56..38b7e0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,18 +1,18 @@ { "search.useIgnoreFiles": true, "[json]": { - "editor.defaultFormatter": "biomejs.biome" + "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[typescript]": { - "editor.defaultFormatter": "biomejs.biome" + "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[javascript]": { - "editor.defaultFormatter": "biomejs.biome" + "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[javascriptreact]": { - "editor.defaultFormatter": "biomejs.biome" + "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[css]": { - "editor.defaultFormatter": "biomejs.biome" + "editor.defaultFormatter": "esbenp.prettier-vscode" } } diff --git a/package.json b/package.json index 777e856..03197cd 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,6 @@ "webpack-merge": "^6.0.1" }, "dependencies": { - "@types/bonjour": "^3.5.13", "@types/connect-history-api-fallback": "^1.5.4", "@types/express": "^4.17.25", "@types/express-serve-static-core": "^4.17.21", @@ -105,7 +104,6 @@ "@types/serve-static": "^1.15.5", "@types/sockjs": "^0.3.36", "@types/ws": "^8.5.10", - "bonjour-service": "^1.2.1", "chokidar": "^3.6.0", "compression": "^1.8.1", "connect-history-api-fallback": "^2.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1051c3e..a819e2b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,6 @@ importers: .: dependencies: - '@types/bonjour': - specifier: ^3.5.13 - version: 3.5.13 '@types/connect-history-api-fallback': specifier: ^1.5.4 version: 1.5.4 @@ -32,9 +29,6 @@ importers: '@types/ws': specifier: ^8.5.10 version: 8.5.10 - bonjour-service: - specifier: ^1.2.1 - version: 1.2.1 chokidar: specifier: ^3.6.0 version: 3.6.0 @@ -309,9 +303,6 @@ packages: peerDependencies: tslib: '2' - '@leichtgewicht/ip-codec@2.0.5': - resolution: {integrity: sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==} - '@module-federation/error-codes@0.22.0': resolution: {integrity: sha512-xF9SjnEy7vTdx+xekjPCV5cIHOGCkdn3pIxo9vU7gEZMIw0SvAEdsy6Uh17xaCpm8V0FWvR0SZoK9Ik6jGOaug==} @@ -514,9 +505,6 @@ packages: '@types/body-parser@1.19.5': resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==} - '@types/bonjour@3.5.13': - resolution: {integrity: sha512-z9fJ5Im06zvUL548KvYNecEVlA7cVDkGUi6kZusb04mpyEFKCIZJvloCcmpmLaIahDpOQGHaHmG6imtPMmPXGQ==} - '@types/chai@5.2.3': resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==} @@ -783,9 +771,6 @@ packages: resolution: {integrity: sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==} engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} - bonjour-service@1.2.1: - resolution: {integrity: sha512-oSzCS2zV14bh2kji6vNe7vrpJYCHGvcZnlffFQ1MEoX/WOeQ/teD8SYWKR942OI3INjq8OMNJlbPK5LLLUxFDw==} - braces@3.0.3: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} @@ -1049,10 +1034,6 @@ packages: dezalgo@1.0.4: resolution: {integrity: sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==} - dns-packet@5.6.1: - resolution: {integrity: sha512-l4gcSouhcgIKRvyy99RNVOgxXiicE+2jZoNmaNmZ6JXiGajBOJAesk1OBlJuM5k2c+eudGdLxDqXuPCKIj6kpw==} - engines: {node: '>=6'} - dunder-proto@1.0.1: resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==} engines: {node: '>= 0.4'} @@ -1598,10 +1579,6 @@ packages: ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - multicast-dns@7.2.5: - resolution: {integrity: sha512-2eznPJP8z2BFLX50tf0LuODrpINqP1RVIm/CObbTcBRITQgmC/TjcREF1NeTBzIcR5XO/ukWo+YHOjBbFwIupg==} - hasBin: true - nano-staged@0.8.0: resolution: {integrity: sha512-QSEqPGTCJbkHU2yLvfY6huqYPjdBrOaTMKatO1F8nCSrkQGXeKwtCiCnsdxnuMhbg3DTVywKaeWLGCE5oJpq0g==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -2086,9 +2063,6 @@ packages: peerDependencies: tslib: ^2 - thunky@1.1.0: - resolution: {integrity: sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==} - tinypool@1.1.1: resolution: {integrity: sha512-Zba82s87IFq9A9XmjiX5uZA/ARWDrB03OHlq+Vw1fSdt0I+4/Kutwy8BP4Y/y/aORMo61FQ0vIb5j44vSo5Pkg==} engines: {node: ^18.0.0 || >=20.0.0} @@ -2379,8 +2353,6 @@ snapshots: dependencies: tslib: 2.7.0 - '@leichtgewicht/ip-codec@2.0.5': {} - '@module-federation/error-codes@0.22.0': {} '@module-federation/runtime-core@0.22.0': @@ -2578,10 +2550,6 @@ snapshots: '@types/connect': 3.4.38 '@types/node': 24.10.7 - '@types/bonjour@3.5.13': - dependencies: - '@types/node': 24.10.7 - '@types/chai@5.2.3': dependencies: '@types/deep-eql': 4.0.2 @@ -2890,11 +2858,6 @@ snapshots: transitivePeerDependencies: - supports-color - bonjour-service@1.2.1: - dependencies: - fast-deep-equal: 3.1.3 - multicast-dns: 7.2.5 - braces@3.0.3: dependencies: fill-range: 7.1.1 @@ -3138,10 +3101,6 @@ snapshots: asap: 2.0.6 wrappy: 1.0.2 - dns-packet@5.6.1: - dependencies: - '@leichtgewicht/ip-codec': 2.0.5 - dunder-proto@1.0.1: dependencies: call-bind-apply-helpers: 1.0.2 @@ -3675,11 +3634,6 @@ snapshots: ms@2.1.3: {} - multicast-dns@7.2.5: - dependencies: - dns-packet: 5.6.1 - thunky: 1.1.0 - nano-staged@0.8.0: dependencies: picocolors: 1.1.0 @@ -4257,8 +4211,6 @@ snapshots: dependencies: tslib: 2.7.0 - thunky@1.1.0: {} - tinypool@1.1.1: {} to-regex-range@5.0.1: diff --git a/src/config.ts b/src/config.ts index 2954bd1..285366a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,4 @@ import type { - BonjourOptions, ClientConfiguration, ConnectHistoryApiFallbackOptions, DevServer, @@ -23,7 +22,6 @@ export interface ResolvedDevServer extends DevServer { proxy: Required; client: ClientConfiguration; allowedHosts: 'auto' | string[] | 'all'; - bonjour: false | Record | BonjourOptions; compress: boolean; historyApiFallback: false | ConnectHistoryApiFallbackOptions; server: ServerConfiguration; diff --git a/src/server.ts b/src/server.ts index bc09ada..69d3748 100644 --- a/src/server.ts +++ b/src/server.ts @@ -24,7 +24,6 @@ import type { Port, DevMiddlewareOptions, ConnectHistoryApiFallbackOptions, - BonjourOptions, WatchFiles, Static, ServerType, @@ -42,7 +41,6 @@ import type { EXPECTED_ANY, RequestHandler, Socket, - Bonjour, WebSocketServerImplementation, Stats, MultiStats, @@ -89,7 +87,6 @@ export interface Configuration< compress?: boolean; allowedHosts?: 'auto' | 'all' | string | string[]; historyApiFallback?: boolean | ConnectHistoryApiFallbackOptions; - bonjour?: boolean | Record | BonjourOptions; watchFiles?: string | string[] | WatchFiles | Array; static?: boolean | string | Static | Array; server?: ServerType | ServerConfiguration; @@ -177,7 +174,6 @@ class Server< sockets: Socket[]; currentHash: string | undefined; isTlsServer = false; - bonjour: Bonjour | undefined; webSocketServer: WebSocketServerImplementation | null | undefined; middleware: | import('webpack-dev-middleware').API @@ -801,12 +797,6 @@ class Server< options.allowedHosts = 'all'; } - if (typeof options.bonjour === 'undefined') { - options.bonjour = false; - } else if (typeof options.bonjour === 'boolean') { - options.bonjour = options.bonjour ? {} : false; - } - if ( typeof options.client === 'undefined' || (typeof options.client === 'object' && options.client !== null) @@ -2401,31 +2391,6 @@ class Server< ); } - runBonjour(): void { - const { Bonjour } = require('bonjour-service'); - - const type = this.isTlsServer ? 'https' : 'http'; - - this.bonjour = new Bonjour(); - this.bonjour?.publish({ - name: `Rspack Dev Server ${os.hostname()}:${this.options.port}`, - port: this.options.port as number, - type, - subtypes: ['rspack'], - ...(this.options.bonjour as Partial), - }); - } - - stopBonjour(callback: () => void = () => {}) { - this.bonjour?.unpublishAll(() => { - this.bonjour?.destroy(); - - if (callback) { - callback(); - } - }); - } - async logStatus() { const server = this.server as S; @@ -2520,18 +2485,6 @@ class Server< await this.openBrowser(openTarget); } } - - if (this.options.bonjour) { - const bonjourProtocol = - (this.options.bonjour as BonjourOptions | undefined)?.type || - this.isTlsServer - ? 'https' - : 'http'; - - this.logger.info( - `Broadcasting "${bonjourProtocol}" with subtype of "rspack" via ZeroConf DNS (Bonjour)`, - ); - } } setHeaders(req: Request, res: Response, next: NextFunction) { @@ -2892,10 +2845,6 @@ class Server< this.createWebSocketServer(); } - if (this.options.bonjour) { - this.runBonjour(); - } - await this.logStatus(); if (typeof this.options.onListening === 'function') { @@ -2910,14 +2859,6 @@ class Server< } async stop(): Promise { - if (this.bonjour) { - await new Promise((resolve) => { - this.stopBonjour(() => { - resolve(); - }); - }); - } - this.webSocketProxies = []; await Promise.all(this.staticWatchers.map((watcher) => watcher.close())); diff --git a/src/types.ts b/src/types.ts index 85e9fb4..31d516c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,8 +16,6 @@ export type { StatsCompilation, StatsOptions, } from '@rspack/core'; -import type { Bonjour, Service as BonjourOptions } from 'bonjour-service'; -export type { Bonjour, BonjourOptions }; import type { FSWatcher, WatchOptions } from 'chokidar'; export type { FSWatcher, WatchOptions }; import type { Options as ConnectHistoryApiFallbackOptions } from 'connect-history-api-fallback'; diff --git a/tests/e2e/__snapshots__/api.test.js.snap.webpack5 b/tests/e2e/__snapshots__/api.test.js.snap.webpack5 index e4d1da6..e0976ce 100644 --- a/tests/e2e/__snapshots__/api.test.js.snap.webpack5 +++ b/tests/e2e/__snapshots__/api.test.js.snap.webpack5 @@ -28,7 +28,7 @@ exports[`API > Server.checkHostHeader > should allow URLs with scheme for checki exports[`API > Server.checkHostHeader > should allow URLs with scheme for checking origin when the "option.client.webSocketURL" is object > response status 1`] = `200`; -exports[`API > Server.checkHostHeader > should allow URLs with scheme for checking origin when the "option.client.webSocketURL" is object > web socket URL 1`] = `"ws://test.host:8158/ws"`; +exports[`API > Server.checkHostHeader > should allow URLs with scheme for checking origin when the "option.client.webSocketURL" is object > web socket URL 1`] = `"ws://test.host:8156/ws"`; exports[`API > Server.getFreePort > should retry finding the port for up to defaultPortRetry times (number) > console messages 1`] = ` [ diff --git a/tests/e2e/__snapshots__/bonjour.test.js.snap.webpack5 b/tests/e2e/__snapshots__/bonjour.test.js.snap.webpack5 deleted file mode 100644 index 7bd07a0..0000000 --- a/tests/e2e/__snapshots__/bonjour.test.js.snap.webpack5 +++ /dev/null @@ -1,49 +0,0 @@ -// Rstest Snapshot v1 - -exports[`bonjour option > as object > should apply bonjour options > console messages 1`] = ` -[ - "[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.", - "[HMR] Waiting for update signal from WDS...", - "Hey.", -] -`; - -exports[`bonjour option > as object > should apply bonjour options > page errors 1`] = `[]`; - -exports[`bonjour option > as object > should apply bonjour options > response status 1`] = `200`; - -exports[`bonjour option > as true > should call bonjour with correct params > console messages 1`] = ` -[ - "[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.", - "[HMR] Waiting for update signal from WDS...", - "Hey.", -] -`; - -exports[`bonjour option > as true > should call bonjour with correct params > page errors 1`] = `[]`; - -exports[`bonjour option > as true > should call bonjour with correct params > response status 1`] = `200`; - -exports[`bonjour option > bonjour object and 'server' option > should apply bonjour options > console messages 1`] = ` -[ - "[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.", - "[HMR] Waiting for update signal from WDS...", - "Hey.", -] -`; - -exports[`bonjour option > bonjour object and 'server' option > should apply bonjour options > page errors 1`] = `[]`; - -exports[`bonjour option > bonjour object and 'server' option > should apply bonjour options > response status 1`] = `200`; - -exports[`bonjour option > with 'server' option > should call bonjour with 'https' type > console messages 1`] = ` -[ - "[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.", - "[HMR] Waiting for update signal from WDS...", - "Hey.", -] -`; - -exports[`bonjour option > with 'server' option > should call bonjour with 'https' type > page errors 1`] = `[]`; - -exports[`bonjour option > with 'server' option > should call bonjour with 'https' type > response status 1`] = `200`; diff --git a/tests/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 b/tests/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 index 6ad704d..e8c4486 100644 --- a/tests/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 +++ b/tests/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 @@ -20,10 +20,10 @@ exports[`client.reconnect option > specified as number > should try to reconnect "Hey.", "[rspack-dev-server] Disconnected!", "[rspack-dev-server] Trying to reconnect...", - "WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", + "WebSocket connection to 'ws://127.0.0.1:8161/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", "[rspack-dev-server] JSHandle@object", "[rspack-dev-server] Trying to reconnect...", - "WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", + "WebSocket connection to 'ws://127.0.0.1:8161/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", "[rspack-dev-server] JSHandle@object", ] `; diff --git a/tests/e2e/__snapshots__/port.test.js.snap.webpack5 b/tests/e2e/__snapshots__/port.test.js.snap.webpack5 index 78011d4..9b69bd0 100644 --- a/tests/e2e/__snapshots__/port.test.js.snap.webpack5 +++ b/tests/e2e/__snapshots__/port.test.js.snap.webpack5 @@ -20,7 +20,7 @@ exports[`port > should work using "0" port > console messages 1`] = ` exports[`port > should work using "0" port > page errors 1`] = `[]`; -exports[`port > should work using "8161" port > console messages 1`] = ` +exports[`port > should work using "8159" port > console messages 1`] = ` [ "[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.", "[HMR] Waiting for update signal from WDS...", @@ -28,7 +28,7 @@ exports[`port > should work using "8161" port > console messages 1`] = ` ] `; -exports[`port > should work using "8161" port > console messages 2`] = ` +exports[`port > should work using "8159" port > console messages 2`] = ` [ "[rspack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.", "[HMR] Waiting for update signal from WDS...", @@ -36,9 +36,9 @@ exports[`port > should work using "8161" port > console messages 2`] = ` ] `; -exports[`port > should work using "8161" port > page errors 1`] = `[]`; +exports[`port > should work using "8159" port > page errors 1`] = `[]`; -exports[`port > should work using "8161" port > page errors 2`] = `[]`; +exports[`port > should work using "8159" port > page errors 2`] = `[]`; exports[`port > should work using "auto" port > console messages 1`] = ` [ diff --git a/tests/e2e/bonjour.test.js b/tests/e2e/bonjour.test.js deleted file mode 100644 index c3fc4d6..0000000 --- a/tests/e2e/bonjour.test.js +++ /dev/null @@ -1,339 +0,0 @@ -const os = require('node:os'); -const webpack = require('@rspack/core'); -const { RspackDevServer: Server } = require('@rspack/dev-server'); -const config = require('../fixtures/simple-config/webpack.config'); -const runBrowser = require('../helpers/run-browser'); -const port = require('../helpers/ports-map').bonjour; - -describe('bonjour option', () => { - let mockPublish; - let mockUnpublishAll; - let mockDestroy; - - beforeEach(() => { - mockPublish = rstest.fn(); - mockUnpublishAll = rstest.fn((callback) => { - callback(); - }); - mockDestroy = rstest.fn(); - }); - - describe('as true', () => { - let compiler; - let server; - let page; - let browser; - let pageErrors; - let consoleMessages; - - beforeEach(async () => { - rs.doMockRequire('bonjour-service', () => { - return { - Bonjour: rs.fn().mockImplementation(() => { - return { - publish: mockPublish, - unpublishAll: mockUnpublishAll, - destroy: mockDestroy, - }; - }), - }; - }); - - compiler = webpack(config); - - server = new Server({ port, bonjour: true }, compiler); - - await server.start(); - - ({ page, browser } = await runBrowser()); - - pageErrors = []; - consoleMessages = []; - }); - - afterEach(async () => { - await browser.close(); - await server.stop(); - - mockPublish.mockReset(); - mockUnpublishAll.mockReset(); - mockDestroy.mockReset(); - }); - - it('should call bonjour with correct params', async () => { - page - .on('console', (message) => { - consoleMessages.push(message); - }) - .on('pageerror', (error) => { - pageErrors.push(error); - }); - - const response = await page.goto(`http://127.0.0.1:${port}/`, { - waitUntil: 'networkidle0', - }); - - expect(mockPublish).toHaveBeenCalledTimes(1); - - expect(mockPublish).toHaveBeenCalledWith({ - name: `Rspack Dev Server ${os.hostname()}:${port}`, - port, - type: 'http', - subtypes: ['rspack'], - }); - - expect(mockUnpublishAll).toHaveBeenCalledTimes(0); - expect(mockDestroy).toHaveBeenCalledTimes(0); - - expect(response.status()).toMatchSnapshot('response status'); - - expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages', - ); - - expect(pageErrors).toMatchSnapshot('page errors'); - }); - }); - - describe("with 'server' option", () => { - let compiler; - let server; - let page; - let browser; - let pageErrors; - let consoleMessages; - - beforeEach(async () => { - rs.doMockRequire('bonjour-service', () => { - return { - Bonjour: rs.fn().mockImplementation(() => { - return { - publish: mockPublish, - unpublishAll: mockUnpublishAll, - destroy: mockDestroy, - }; - }), - }; - }); - - compiler = webpack(config); - - server = new Server({ bonjour: true, port, server: 'https' }, compiler); - - await server.start(); - - ({ page, browser } = await runBrowser()); - - pageErrors = []; - consoleMessages = []; - }); - - afterEach(async () => { - await browser.close(); - await server.stop(); - }); - - it("should call bonjour with 'https' type", async () => { - page - .on('console', (message) => { - consoleMessages.push(message); - }) - .on('pageerror', (error) => { - pageErrors.push(error); - }); - - const response = await page.goto(`https://127.0.0.1:${port}/`, { - waitUntil: 'networkidle0', - }); - - expect(mockPublish).toHaveBeenCalledTimes(1); - - expect(mockPublish).toHaveBeenCalledWith({ - name: `Rspack Dev Server ${os.hostname()}:${port}`, - port, - type: 'https', - subtypes: ['rspack'], - }); - - expect(mockUnpublishAll).toHaveBeenCalledTimes(0); - expect(mockDestroy).toHaveBeenCalledTimes(0); - - expect(response.status()).toMatchSnapshot('response status'); - - expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages', - ); - - expect(pageErrors).toMatchSnapshot('page errors'); - }); - }); - - describe('as object', () => { - let compiler; - let server; - let page; - let browser; - let pageErrors; - let consoleMessages; - - beforeEach(async () => { - rs.doMockRequire('bonjour-service', () => { - return { - Bonjour: rs.fn().mockImplementation(() => { - return { - publish: mockPublish, - unpublishAll: mockUnpublishAll, - destroy: mockDestroy, - }; - }), - }; - }); - - compiler = webpack(config); - - server = new Server( - { - port, - bonjour: { - type: 'https', - protocol: 'udp', - }, - }, - compiler, - ); - - await server.start(); - - ({ page, browser } = await runBrowser()); - - pageErrors = []; - consoleMessages = []; - }); - - afterEach(async () => { - await browser.close(); - await server.stop(); - }); - - it('should apply bonjour options', async () => { - page - .on('console', (message) => { - consoleMessages.push(message); - }) - .on('pageerror', (error) => { - pageErrors.push(error); - }); - - const response = await page.goto(`http://127.0.0.1:${port}/`, { - waitUntil: 'networkidle0', - }); - - expect(mockPublish).toHaveBeenCalledTimes(1); - - expect(mockPublish).toHaveBeenCalledWith({ - name: `Rspack Dev Server ${os.hostname()}:${port}`, - port, - type: 'https', - protocol: 'udp', - subtypes: ['rspack'], - }); - - expect(mockUnpublishAll).toHaveBeenCalledTimes(0); - expect(mockDestroy).toHaveBeenCalledTimes(0); - - expect(response.status()).toMatchSnapshot('response status'); - - expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages', - ); - - expect(pageErrors).toMatchSnapshot('page errors'); - }); - }); - - describe("bonjour object and 'server' option", () => { - let compiler; - let server; - let page; - let browser; - let pageErrors; - let consoleMessages; - - beforeEach(async () => { - rs.doMockRequire('bonjour-service', () => { - return { - Bonjour: rs.fn().mockImplementation(() => { - return { - publish: mockPublish, - unpublishAll: mockUnpublishAll, - destroy: mockDestroy, - }; - }), - }; - }); - - compiler = webpack(config); - - server = new Server( - { - port, - bonjour: { - type: 'http', - protocol: 'udp', - }, - server: { - type: 'https', - }, - }, - compiler, - ); - - await server.start(); - - ({ page, browser } = await runBrowser()); - - pageErrors = []; - consoleMessages = []; - }); - - afterEach(async () => { - await browser.close(); - await server.stop(); - }); - - it('should apply bonjour options', async () => { - page - .on('console', (message) => { - consoleMessages.push(message); - }) - .on('pageerror', (error) => { - pageErrors.push(error); - }); - - const response = await page.goto(`https://127.0.0.1:${port}/`, { - waitUntil: 'networkidle0', - }); - - expect(mockPublish).toHaveBeenCalledTimes(1); - - expect(mockPublish).toHaveBeenCalledWith({ - name: `Rspack Dev Server ${os.hostname()}:${port}`, - port, - type: 'http', - protocol: 'udp', - subtypes: ['rspack'], - }); - - expect(mockUnpublishAll).toHaveBeenCalledTimes(0); - expect(mockDestroy).toHaveBeenCalledTimes(0); - - expect(response.status()).toMatchSnapshot('response status'); - - expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - 'console messages', - ); - - expect(pageErrors).toMatchSnapshot('page errors'); - }); - }); -}); diff --git a/tests/helpers/ports-map.js b/tests/helpers/ports-map.js index 831bb8c..b398ad0 100644 --- a/tests/helpers/ports-map.js +++ b/tests/helpers/ports-map.js @@ -19,7 +19,6 @@ const listOfTests = { 'module-federation': 1, 'multi-compiler': 1, // unit tests - bonjour: 1, 'client-option': 1, 'compress-option': 1, 'headers-option': 1, @@ -50,7 +49,6 @@ const listOfTests = { ipc: 1, stats: 1, 'cli-allowed-hosts': 1, - 'cli-bonjour': 1, 'cli-client': 1, 'cli-colors': 1, 'cli-compress': 1,