File tree Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Original file line number Diff line number Diff line change 11export default {
22 buildModules : [ '@nuxtjs/tailwindcss' ] ,
3- modules : [ '@nuxt/typescript-build' , '../src/module.ts' ]
3+ modules : [ '@nuxt/typescript-build' , '../src/module.ts' ] ,
4+ websocket : {
5+ url : 'wss://echo.websocket.events/'
6+ }
47}
Original file line number Diff line number Diff line change 6969 <button
7070 :disabled =" isSendDisabled"
7171 class =" btn btn-blue"
72- :class =" { 'cursor-not-allowed opacity-50': isSendDisabled}"
72+ :class =" { 'cursor-not-allowed opacity-50': isSendDisabled }"
7373 @click.prevent =" sendMessage"
7474 >
7575 Send message
Original file line number Diff line number Diff line change @@ -17,13 +17,21 @@ import WebSocketManager from './WebSocketManager'
1717
1818const reconnectInterval = Number ( '<%= options.reconnectInterval %>' ) || 1000
1919const urlFromOptions = '<%= options.url %>'
20+
2021export default ( { app } : { app : NuxtAppOptions } , inject : Inject ) : void => {
2122 /* istanbul ignore next */
2223 const runtimeConfig = ( app . $config && app . $config . websocket ) || { }
2324
2425 /* istanbul ignore next */
25- const url =
26- runtimeConfig . url || urlFromOptions || 'wss://echo.websocket.events/'
26+ const url = runtimeConfig . url || urlFromOptions
27+
28+ /* istanbul ignore next */
29+ if ( ! url ) {
30+ // eslint-disable-next-line no-console
31+ return console . error (
32+ 'WebSocket connection URL is required. Please specify it via options or runtime configuration.'
33+ )
34+ }
2735
2836 const emitter = new Vue ( )
2937 const manager = new WebSocketManager ( url , emitter , reconnectInterval )
Original file line number Diff line number Diff line change 1- import { expectModuleToBeCalledWith , setupTest } from '@nuxt/test-utils'
1+ import {
2+ expectModuleToBeCalledWith ,
3+ getNuxt ,
4+ setupTest
5+ } from '@nuxt/test-utils'
26
37describe ( 'module' , ( ) => {
48 setupTest ( {
@@ -10,15 +14,15 @@ describe('module', () => {
1014 expectModuleToBeCalledWith ( 'addPlugin' , {
1115 src : 'src/templates/plugin.ts' ,
1216 fileName : 'nuxt-websocket/websocket.client.ts' ,
13- options : { }
17+ options : getNuxt ( ) . options . websocket
1418 } )
1519 } )
1620
1721 test ( 'should render the template' , ( ) => {
1822 expectModuleToBeCalledWith ( 'addTemplate' , {
1923 src : 'src/templates/WebSocketManager.ts' ,
2024 fileName : 'nuxt-websocket/WebSocketManager.ts' ,
21- options : { }
25+ options : getNuxt ( ) . options . websocket
2226 } )
2327 } )
2428} )
You can’t perform that action at this time.
0 commit comments