1
- import chai from 'chai'
2
- import Vue from 'vue'
1
+ import Vue from 'vue/dist/vue.min'
3
2
import VueLogger from '../src/logger'
3
+ import chai from 'chai'
4
4
5
+ const { print, isValidOptions, initLoggerInstance, logLevels, install} = VueLogger
5
6
const expect = chai . expect
6
- const { print, validateOptions, initLoggerInstance, logLevels, install} = VueLogger
7
7
8
8
describe ( 'Logger.js' , ( ) => {
9
-
10
- describe ( 'install()' , ( ) => {
11
-
12
- it ( 'install() should work with the correct params.' , ( ) => {
9
+ describe ( 'getMethodName()' , ( ) => {
10
+ it ( 'Should show the parent function.' , ( ) => {
13
11
const options = {
14
12
logLevel : 'debug' ,
15
13
stringifyByDefault : false ,
16
14
showLogLevel : false ,
15
+ showMethodName : true
17
16
}
18
-
19
17
Vue . use ( { install} , options )
20
18
21
19
new Vue ( {
22
- created ( ) {
23
- expect ( this . $log ) . to . be . a ( 'object' )
24
- expect ( this . $log . debug ) . to . be . a ( 'function' )
25
- expect ( this . $log . info ) . to . be . a ( 'function' )
26
- expect ( this . $log . warn ) . to . be . a ( 'function' )
27
- expect ( this . $log . error ) . to . be . a ( 'function' )
28
- expect ( this . $log . fatal ) . to . be . a ( 'function' )
20
+ created ( ) {
21
+ this . foo ( )
22
+ } ,
23
+ template : '<bar></bar>' ,
24
+ methods : {
25
+ foo ( ) {
26
+ this . $log . fatal ( 'first level call.' )
27
+ externalFunction ( )
28
+ }
29
29
}
30
30
} )
31
31
32
+ function externalFunction ( ) {
33
+ Vue . $log . fatal ( 'calling external function.' )
34
+ }
35
+ } )
36
+ } )
37
+ describe ( 'install()' , ( ) => {
38
+
39
+ it ( 'install() should work with the correct params.' , ( ) => {
40
+ const options = {
41
+ logLevel : 'debug' ,
42
+ stringifyByDefault : false ,
43
+ showLogLevel : false ,
44
+ showMethodName : false
45
+ }
46
+ Vue . use ( { install} , options )
32
47
expect ( Vue . $log ) . to . be . a ( 'object' )
33
48
expect ( Vue . $log . debug ) . to . be . a ( 'function' )
34
49
expect ( Vue . $log . info ) . to . be . a ( 'function' )
@@ -37,6 +52,15 @@ describe('Logger.js', () => {
37
52
expect ( Vue . $log . fatal ) . to . be . a ( 'function' )
38
53
} )
39
54
55
+ it ( 'install() should throw an error with the an incorrect log showMethodName parameter.' , ( ) => {
56
+ const options = {
57
+ showMethodName : 'foo'
58
+ }
59
+ expect ( ( ) => { install ( Vue , options ) } )
60
+ . to
61
+ . throw ( Error , 'Provided options for vuejs-logger are not valid.' )
62
+ } )
63
+
40
64
it ( 'install() should throw an error with the an incorrect log level.' , ( ) => {
41
65
const options = {
42
66
logLevel : 'foo'
@@ -76,17 +100,26 @@ describe('Logger.js', () => {
76
100
77
101
describe ( 'initLoggerInstance()' , ( ) => {
78
102
79
- it ( 'initLoggerInstance() should ignore logLevels that are more restrictive than set logLevel.' , ( ) => {
103
+ it ( 'initLoggerInstance() should ignore logLevels that are more restrictive than set logLevel.' , function testFn ( ) {
80
104
// with options enabled
81
- const a = initLoggerInstance ( { logLevel : 'info' , showLogLevel : true , stringifyArguments : true } , logLevels )
105
+ const a = initLoggerInstance ( {
106
+ logLevel : 'info' ,
107
+ showLogLevel : true ,
108
+ stringifyArguments : true ,
109
+ showMethodName : false
110
+ } , logLevels )
82
111
a . debug ( 'test' )
83
112
a . info ( 'test' , [ 'test args' ] , [ 'test args' ] )
84
113
a . warn ( 'test' , [ 'test args' ] )
85
114
a . error ( 'test' , 'test args' )
86
115
a . fatal ( 'test' , [ 'test args' ] , 'test args' , 'test args' )
87
-
88
116
// with options disabled
89
- const b = initLoggerInstance ( { logLevel : 'info' , showLogLevel : false , stringifyArguments : false } , logLevels )
117
+ const b = initLoggerInstance ( {
118
+ logLevel : 'info' ,
119
+ showLogLevel : false ,
120
+ stringifyArguments : false ,
121
+ showMethodName : true
122
+ } , logLevels )
90
123
b . debug ( 'test' )
91
124
b . info ( 'test' , [ 'test args' ] , [ 'test args' ] )
92
125
b . warn ( 'test' , [ 'test args' ] )
@@ -95,49 +128,62 @@ describe('Logger.js', () => {
95
128
} )
96
129
} )
97
130
98
- describe ( 'validateOptions ()' , ( ) => {
131
+ describe ( 'isValidOptions ()' , ( ) => {
99
132
100
- it ( 'validateOptions () should pass with correct options.' , ( ) => {
101
- expect ( validateOptions ( {
133
+ it ( 'isValidOptions () should pass with correct options.' , ( ) => {
134
+ expect ( isValidOptions ( {
102
135
logLevel : 'debug' ,
103
136
stringifyByDefault : false ,
104
137
showLogLevel : false ,
138
+ showMethodName : true
105
139
} , logLevels ) ) . to . equal ( true )
106
140
} )
107
141
108
- it ( 'validateOptions() should fail with incorrect options.' , ( ) => {
109
- expect ( validateOptions ( {
142
+ it ( 'isValidOptions() should fail with incorrect options.' , ( ) => {
143
+
144
+ expect ( isValidOptions ( {
145
+ logLevel : 'debug' ,
146
+ stringifyArguments : false ,
147
+ showLogLevel : false ,
148
+ showMethodName : 'TEST' ,
149
+ } , logLevels ) ) . to . equal ( false )
150
+
151
+ expect ( isValidOptions ( {
110
152
logLevel : 'debug' ,
111
153
stringifyArguments : 'TEST' ,
112
154
showLogLevel : false ,
155
+ showMethodName : false ,
113
156
} , logLevels ) ) . to . equal ( false )
114
157
115
- expect ( validateOptions ( {
158
+ expect ( isValidOptions ( {
116
159
logLevel : 'debug' ,
117
160
stringifyArguments : false ,
118
161
showLogLevel : 'TEST' ,
162
+ showMethodName : false ,
119
163
} , logLevels ) ) . to . equal ( false )
120
164
121
- expect ( validateOptions ( {
165
+ expect ( isValidOptions ( {
122
166
logLevel : 'TEST' ,
123
167
stringifyArguments : false ,
124
168
showLogLevel : false ,
169
+ showMethodName : false ,
125
170
} , logLevels ) ) . to . equal ( false )
171
+
172
+ expect ( isValidOptions ( {
173
+ logLevel : 'debug' ,
174
+ } , logLevels ) ) . to . equal ( true )
126
175
} )
127
176
} )
128
177
129
178
describe ( 'print()' , ( ) => {
130
-
131
179
it ( 'print() should use console.error() with fatal logLevel' , ( ) => {
132
- print ( 'fatal' , 'fatal |' , [ 'test' ] )
180
+ print ( 'fatal' , 'fatal |' , 'METHOD NAME | ' , [ 'test' ] )
133
181
} )
134
-
135
182
it ( 'print() should use console.error() with error logLevel' , ( ) => {
136
- print ( 'error' , 'error |' , [ 'test' ] )
183
+ print ( 'error' , 'error |' , 'METHOD NAME |' , [ 'test' ] )
137
184
} )
138
-
139
185
it ( 'print() should use console.log() with any other logLevel' , ( ) => {
140
- print ( 'debug' , 'debug |' , [ 'test' ] )
186
+ print ( 'debug' , 'debug |' , 'METHOD NAME |' , [ 'test' ] )
141
187
} )
142
188
} )
143
189
} )
0 commit comments