16
16
// under the License.
17
17
18
18
jest . mock ( 'os' )
19
- jest . mock ( '../src/ sh' )
19
+ jest . mock ( '../sh' )
20
20
import * as os from 'os'
21
- import { Chrome } from '../src/ chrome'
22
- import { sh , makeError } from '../src/ sh'
21
+ import { Chrome } from '../chrome'
22
+ import { sh , makeError } from '../sh'
23
23
24
24
const { getBrowserInfo, ChromeChannel } = Chrome
25
25
const mockSh = sh as unknown as jest . Mock < any , any >
26
26
const mockPlatform = os . platform as unknown as jest . Mock < any , any >
27
27
28
+ type Success = Chrome . BrowserInfo | Chrome . BrowserInfo [ ]
29
+
28
30
describe ( 'chrome browser info' , ( ) => {
29
31
describe ( 'macOS' , ( ) => {
30
32
beforeAll ( ( ) => {
@@ -39,10 +41,10 @@ describe('chrome browser info', () => {
39
41
mockSh . mockReturnValueOnce (
40
42
Promise . resolve ( { stdout : 'Google Chrome 76.0.3809.132\n' , stderr : '' } )
41
43
)
42
- expect ( await getBrowserInfo ( ChromeChannel . stable ) ) . toEqual ( {
44
+ expect ( await getBrowserInfo ( ChromeChannel . stable ) ) . toEqual < Success > ( {
43
45
binary : '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' ,
44
46
version : '76.0.3809.132' ,
45
- channel : ' stable' ,
47
+ channel : ChromeChannel . stable ,
46
48
} )
47
49
} )
48
50
it ( 'should fail to get chrome info when its not installed' , async ( ) => {
@@ -51,7 +53,9 @@ describe('chrome browser info', () => {
51
53
try {
52
54
await getBrowserInfo ( ChromeChannel . stable )
53
55
} catch ( err ) {
54
- expect ( err . message ) . toBe ( 'Unable to find Chrome installation' )
56
+ expect ( ( err as Error ) . message ) . toBe (
57
+ 'Unable to find Chrome installation'
58
+ )
55
59
}
56
60
} )
57
61
it ( 'should get all chrome info' , async ( ) => {
@@ -73,24 +77,24 @@ describe('chrome browser info', () => {
73
77
} )
74
78
}
75
79
} )
76
- expect ( await getBrowserInfo ( ) ) . toEqual ( [
80
+ expect ( await getBrowserInfo ( ) ) . toEqual < Success > ( [
77
81
{
78
82
binary :
79
83
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' ,
80
84
version : '76.0.3809.132' ,
81
- channel : ' stable' ,
85
+ channel : ChromeChannel . stable ,
82
86
} ,
83
87
{
84
88
binary :
85
89
'/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome' ,
86
90
version : '75.0.3770.75' ,
87
- channel : ' beta' ,
91
+ channel : ChromeChannel . beta ,
88
92
} ,
89
93
{
90
94
binary :
91
95
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary' ,
92
96
version : '79.0.3915.0' ,
93
- channel : ' canary' ,
97
+ channel : ChromeChannel . canary ,
94
98
} ,
95
99
] )
96
100
mockSh . mockReset ( )
@@ -111,18 +115,18 @@ describe('chrome browser info', () => {
111
115
} )
112
116
}
113
117
} )
114
- expect ( await getBrowserInfo ( ) ) . toEqual ( [
118
+ expect ( await getBrowserInfo ( ) ) . toEqual < Success > ( [
115
119
{
116
120
binary :
117
121
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' ,
118
122
version : '76.0.3809.132' ,
119
- channel : ' stable' ,
123
+ channel : ChromeChannel . stable ,
120
124
} ,
121
125
{
122
126
binary :
123
127
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary' ,
124
128
version : '79.0.3915.0' ,
125
- channel : ' canary' ,
129
+ channel : ChromeChannel . canary ,
126
130
} ,
127
131
] )
128
132
mockSh . mockReset ( )
@@ -153,15 +157,17 @@ describe('chrome browser info', () => {
153
157
try {
154
158
await getBrowserInfo ( ChromeChannel . stable )
155
159
} catch ( err ) {
156
- expect ( err . message ) . toBe ( 'Unable to find Chrome installation' )
160
+ expect ( ( err as Error ) . message ) . toBe (
161
+ 'Unable to find Chrome installation'
162
+ )
157
163
}
158
164
} )
159
165
it ( 'should fail to get canary chrome channel since it is not available on linux' , async ( ) => {
160
166
expect . assertions ( 1 )
161
167
try {
162
168
await getBrowserInfo ( ChromeChannel . canary )
163
169
} catch ( err ) {
164
- expect ( err . message ) . toBe ( 'Unsupported channel canary' )
170
+ expect ( ( err as Error ) . message ) . toBe ( 'Unsupported channel canary' )
165
171
}
166
172
} )
167
173
it ( 'should get all chrome info' , async ( ) => {
@@ -203,11 +209,11 @@ describe('chrome browser info', () => {
203
209
} )
204
210
}
205
211
} )
206
- expect ( await getBrowserInfo ( ) ) . toEqual ( [
212
+ expect ( await getBrowserInfo ( ) ) . toEqual < Success > ( [
207
213
{
208
214
binary : '/usr/local/sbin/google-chrome' ,
209
215
version : '76.0.3809.132' ,
210
- channel : ' stable' ,
216
+ channel : ChromeChannel . stable ,
211
217
} ,
212
218
] )
213
219
mockSh . mockReset ( )
0 commit comments