1
1
import { logger } from "@coder/logger"
2
2
import { mockLogger } from "../../utils/helpers"
3
+ import * as semver from "semver"
3
4
4
5
describe ( "constants" , ( ) => {
5
6
let constants : typeof import ( "../../../src/node/constants" )
@@ -13,9 +14,15 @@ describe("constants", () => {
13
14
commit : "f6b2be2838f4afb217c2fd8f03eafedd8d55ef9b" ,
14
15
}
15
16
17
+ const mockCodePackageJson = {
18
+ name : "mock-code-oss-dev" ,
19
+ version : "1.2.3" ,
20
+ }
21
+
16
22
beforeAll ( ( ) => {
17
23
mockLogger ( )
18
24
jest . mock ( "../../../package.json" , ( ) => mockPackageJson , { virtual : true } )
25
+ jest . mock ( "../../../vendor/modules/code-oss-dev/package.json" , ( ) => mockCodePackageJson , { virtual : true } )
19
26
constants = require ( "../../../src/node/constants" )
20
27
} )
21
28
@@ -24,12 +31,44 @@ describe("constants", () => {
24
31
jest . resetModules ( )
25
32
} )
26
33
34
+ it ( "should provide the package name" , ( ) => {
35
+ expect ( constants . pkgName ) . toBe ( mockPackageJson . name )
36
+ } )
37
+
27
38
it ( "should provide the commit" , ( ) => {
28
39
expect ( constants . commit ) . toBe ( mockPackageJson . commit )
29
40
} )
30
41
31
42
it ( "should return the package.json version" , ( ) => {
32
43
expect ( constants . version ) . toBe ( mockPackageJson . version )
44
+
45
+ // Ensure the version is parseable as semver and equal
46
+ const actual = semver . parse ( constants . version )
47
+ const expected = semver . parse ( mockPackageJson . version )
48
+ expect ( actual ) . toBeTruthy ( )
49
+ expect ( actual ) . toStrictEqual ( expected )
50
+ } )
51
+
52
+ it ( "should include embedded Code version information" , ( ) => {
53
+ expect ( constants . codeVersion ) . toBe ( mockCodePackageJson . version )
54
+
55
+ // Ensure the version is parseable as semver and equal
56
+ const actual = semver . parse ( constants . codeVersion )
57
+ const expected = semver . parse ( mockCodePackageJson . version )
58
+ expect ( actual ) . toBeTruthy ( )
59
+ expect ( actual ) . toStrictEqual ( expected )
60
+ } )
61
+
62
+ it ( "should return a human-readable version string" , ( ) => {
63
+ expect ( constants . getVersionString ( ) ) . toStrictEqual ( `${ mockPackageJson . version } ${ mockPackageJson . commit } ` )
64
+ } )
65
+
66
+ it ( "should return a machine-readable version string" , ( ) => {
67
+ expect ( constants . getVersionJsonString ( ) ) . toStrictEqual ( JSON . stringify ( {
68
+ codeServer : mockPackageJson . version ,
69
+ commit : mockPackageJson . commit ,
70
+ vscode : mockCodePackageJson . version ,
71
+ } ) )
33
72
} )
34
73
35
74
describe ( "getPackageJson" , ( ) => {
@@ -47,6 +86,9 @@ describe("constants", () => {
47
86
// so to get the root package.json we need to use ../../
48
87
const packageJson = constants . getPackageJson ( "../../package.json" )
49
88
expect ( packageJson ) . toStrictEqual ( mockPackageJson )
89
+
90
+ const codePackageJson = constants . getPackageJson ( "../../vendor/modules/code-oss-dev/package.json" )
91
+ expect ( codePackageJson ) . toStrictEqual ( mockCodePackageJson )
50
92
} )
51
93
} )
52
94
} )
@@ -55,9 +97,13 @@ describe("constants", () => {
55
97
const mockPackageJson = {
56
98
name : "mock-code-server" ,
57
99
}
100
+ const mockCodePackageJson = {
101
+ name : "mock-code-oss-dev" ,
102
+ }
58
103
59
104
beforeAll ( ( ) => {
60
105
jest . mock ( "../../../package.json" , ( ) => mockPackageJson , { virtual : true } )
106
+ jest . mock ( "../../../vendor/modules/code-oss-dev/package.json" , ( ) => mockCodePackageJson , { virtual : true } )
61
107
constants = require ( "../../../src/node/constants" )
62
108
} )
63
109
@@ -69,6 +115,7 @@ describe("constants", () => {
69
115
it ( "version should return 'development'" , ( ) => {
70
116
expect ( constants . version ) . toBe ( "development" )
71
117
} )
118
+
72
119
it ( "commit should return 'development'" , ( ) => {
73
120
expect ( constants . commit ) . toBe ( "development" )
74
121
} )
0 commit comments