File tree Expand file tree Collapse file tree 4 files changed +67
-14
lines changed Expand file tree Collapse file tree 4 files changed +67
-14
lines changed Original file line number Diff line number Diff line change 1
- import errorHandler from './shared/ErrorHandler ' ;
1
+ import initializeOptions from './shared/InitializeOptions ' ;
2
2
import PackageInfo from './shared/PackageInfo' ;
3
3
import rayMethodMixin from './shared/RayMethodMixin' ;
4
4
5
- const RayPlugin = {
5
+ export default {
6
6
install : function ( Vue , options ) {
7
7
Vue . prototype . $rayVersion = PackageInfo . VERSION ;
8
8
9
- if ( options . interceptErrors === true ) {
10
- Vue . config . errorHandler = errorHandler ;
11
- }
9
+ initializeOptions ( options , Vue . config ) ;
12
10
13
11
Vue . mixin ( {
14
12
methods : rayMethodMixin ,
15
13
} ) ;
16
14
} ,
17
15
} ;
18
-
19
- export default RayPlugin ;
Original file line number Diff line number Diff line change 1
- import errorHandler from './shared/ErrorHandler ' ;
1
+ import initializeOptions from './shared/InitializeOptions ' ;
2
2
import PackageInfo from './shared/PackageInfo' ;
3
3
import rayMethodMixin from './shared/RayMethodMixin' ;
4
4
5
- const RayPlugin = {
5
+ export default {
6
6
install : ( app , options ) => {
7
7
app . config . globalProperties . $rayVersion = PackageInfo . VERSION ;
8
8
9
- if ( options . interceptErrors === true ) {
10
- app . config . errorHandler = errorHandler ;
11
- }
9
+ initializeOptions ( options , app . config ) ;
12
10
13
11
app . provide ( 'ray' , options ) ;
14
12
@@ -17,5 +15,3 @@ const RayPlugin = {
17
15
} ) ;
18
16
} ,
19
17
} ;
20
-
21
- export default RayPlugin ;
Original file line number Diff line number Diff line change
1
+ const { Ray } = require ( 'node-ray/web' ) ;
2
+ import errorHandler from './ErrorHandler' ;
3
+
4
+ export const initializeOptions = ( options , vueConfig ) => {
5
+ if ( options . interceptErrors === true ) {
6
+ vueConfig . errorHandler = errorHandler ;
7
+ }
8
+
9
+ let host = 'localhost' ,
10
+ port = 23517 ;
11
+
12
+ if ( typeof options [ 'host' ] === 'string' ) {
13
+ host = options . host ;
14
+ }
15
+
16
+ if ( typeof options [ 'port' ] === 'number' ) {
17
+ port = options . port ;
18
+ }
19
+
20
+ Ray . useDefaultSettings ( { host, port } ) ;
21
+ } ;
22
+
23
+ export default initializeOptions ;
Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-undef */
2
+ /* eslint-disable no-unused-vars */
3
+ const { Ray } = require ( 'node-ray/web' ) ;
4
+
5
+ import { initializeOptions } from './../../src/shared/InitializeOptions' ;
6
+
7
+ let options , vueConfig ;
8
+
9
+ beforeEach ( ( ) => {
10
+ options = { } ;
11
+ vueConfig = { errorHandler : null } ;
12
+ } ) ;
13
+
14
+ describe ( 'Option Initializer:' , ( ) => {
15
+ it ( 'initializes interceptErrors option' , ( ) => {
16
+ options . initializeOptions = true ;
17
+
18
+ initializeOptions ( options , vueConfig ) ;
19
+
20
+ expect ( typeof vueConfig . errorHandler ) . toBe ( 'object' ) ;
21
+ } ) ;
22
+
23
+ it ( 'initializes host option' , ( ) => {
24
+ options . host = 'otherhost' ;
25
+
26
+ initializeOptions ( options , vueConfig ) ;
27
+
28
+ expect ( Ray . defaultSettings . host ) . toBe ( 'otherhost' ) ;
29
+ } ) ;
30
+
31
+ it ( 'initializes port option' , ( ) => {
32
+ options . port = 12345 ;
33
+
34
+ initializeOptions ( options , vueConfig ) ;
35
+
36
+ expect ( Ray . defaultSettings . port ) . toBe ( 12345 ) ;
37
+ } ) ;
38
+ } ) ;
You can’t perform that action at this time.
0 commit comments