1
- import { getRefFromVersion } from '@src/routes/utils'
1
+ import { getAppVersion , getRefFromVersion } from '@src/routes/utils'
2
+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
3
+
4
+ beforeEach ( ( ) => {
5
+ const mockElectron = {
6
+ packageJson : {
7
+ version : 'mocked-version' ,
8
+ } ,
9
+ }
10
+ vi . stubGlobal ( 'window' , { electron : mockElectron } )
11
+ } )
12
+
13
+ afterEach ( ( ) => {
14
+ vi . unstubAllGlobals ( )
15
+ } )
2
16
3
17
describe ( 'Routes utility functions' , ( ) => {
4
18
describe ( 'getRefFromVersion' , ( ) => {
@@ -12,4 +26,70 @@ describe('Routes utility functions', () => {
12
26
expect ( getRefFromVersion ( 'main' ) ) . toBeUndefined ( )
13
27
} )
14
28
} )
29
+
30
+ describe ( 'getAppVersion' , ( ) => {
31
+ it ( 'should return 0.0.0 for web testing' , ( ) => {
32
+ const expected = '0.0.0'
33
+ const actual = getAppVersion ( {
34
+ isTestEnvironment : true ,
35
+ NODE_ENV : 'development' ,
36
+ isDesktop : false ,
37
+ } )
38
+ expect ( actual ) . toBe ( expected )
39
+ } )
40
+ it ( 'should return 0.0.0 for desktop testing' , ( ) => {
41
+ const expected = '0.0.0'
42
+ const actual = getAppVersion ( {
43
+ isTestEnvironment : true ,
44
+ NODE_ENV : 'development' ,
45
+ isDesktop : true ,
46
+ } )
47
+ expect ( actual ) . toBe ( expected )
48
+ } )
49
+ it ( 'should return another mocked packageJson version' , ( ) => {
50
+ const expected = 'mocked-version'
51
+ const actual = getAppVersion ( {
52
+ isTestEnvironment : false ,
53
+ NODE_ENV : 'development' ,
54
+ isDesktop : true ,
55
+ } )
56
+ expect ( actual ) . toBe ( expected )
57
+ } )
58
+ it ( 'should return another mocked packageJson version' , ( ) => {
59
+ const expected = 'mocked-version'
60
+ const actual = getAppVersion ( {
61
+ isTestEnvironment : true ,
62
+ NODE_ENV : 'not-development' ,
63
+ isDesktop : true ,
64
+ } )
65
+ expect ( actual ) . toBe ( expected )
66
+ } )
67
+ it ( 'should return dev' , ( ) => {
68
+ const expected = 'dev'
69
+ const actual = getAppVersion ( {
70
+ isTestEnvironment : false ,
71
+ NODE_ENV : 'development' ,
72
+ isDesktop : false ,
73
+ } )
74
+ expect ( actual ) . toBe ( expected )
75
+ } )
76
+ it ( 'should return main' , ( ) => {
77
+ const expected = 'main'
78
+ const actual = getAppVersion ( {
79
+ isTestEnvironment : false ,
80
+ NODE_ENV : 'not-development' ,
81
+ isDesktop : false ,
82
+ } )
83
+ expect ( actual ) . toBe ( expected )
84
+ } )
85
+ it ( 'should return main because NODE_ENV is production' , ( ) => {
86
+ const expected = 'main'
87
+ const actual = getAppVersion ( {
88
+ isTestEnvironment : false ,
89
+ NODE_ENV : 'production' ,
90
+ isDesktop : false ,
91
+ } )
92
+ expect ( actual ) . toBe ( expected )
93
+ } )
94
+ } )
15
95
} )
0 commit comments