6
6
import * as assert from 'assert'
7
7
import { VSCODE_EXTENSION_ID } from '../../../shared/extensions'
8
8
import * as vscodeUtil from '../../../shared/utilities/vsCodeUtils'
9
+ import * as vscode from 'vscode'
9
10
10
11
describe ( 'vscodeUtils' , async function ( ) {
11
12
it ( 'activateExtension(), isExtensionActive()' , async function ( ) {
@@ -20,3 +21,81 @@ describe('vscodeUtils', async function () {
20
21
assert . deepStrictEqual ( vscodeUtil . isExtensionActive ( VSCODE_EXTENSION_ID . awstoolkit ) , true )
21
22
} )
22
23
} )
24
+
25
+ describe ( 'isExtensionInstalled()' , function ( ) {
26
+ const smallerVersion = '0.9.0'
27
+ const extVersion = '1.0.0'
28
+ const largerVersion = '2.0.0'
29
+ const extId = 'my.ext.id'
30
+ let ext : vscode . Extension < any >
31
+ let getExtension : ( extId : string ) => vscode . Extension < any >
32
+
33
+ beforeEach ( function ( ) {
34
+ ext = {
35
+ packageJSON : {
36
+ version : extVersion ,
37
+ } ,
38
+ } as vscode . Extension < any >
39
+ getExtension = _ => ext
40
+ } )
41
+
42
+ it ( 'fails if extension could not be found' , function ( ) {
43
+ const noExtFunc = ( extId : string ) => undefined
44
+ assert . ok ( ! vscodeUtil . isExtensionInstalled ( extId , undefined , noExtFunc ) )
45
+ } )
46
+
47
+ it ( 'succeeds on same min version' , function ( ) {
48
+ assert . ok ( vscodeUtil . isExtensionInstalled ( extId , extVersion , getExtension ) )
49
+ } )
50
+
51
+ it ( 'succeeds on smaller min version' , function ( ) {
52
+ assert . ok ( vscodeUtil . isExtensionInstalled ( extId , smallerVersion , getExtension ) )
53
+ } )
54
+
55
+ it ( 'fails on larger min version' , function ( ) {
56
+ assert . ok ( ! vscodeUtil . isExtensionInstalled ( extId , largerVersion , getExtension ) )
57
+ } )
58
+
59
+ it ( 'can handle labels on a version' , function ( ) {
60
+ ext . packageJSON . version = `${ extVersion } -SNAPSHOT`
61
+ assert . ok ( vscodeUtil . isExtensionInstalled ( extId , `${ smallerVersion } -ALPHA` , getExtension ) )
62
+ } )
63
+
64
+ it ( 'is valid when no min version is provided' , function ( ) {
65
+ assert . ok ( vscodeUtil . isExtensionInstalled ( extId , undefined , getExtension ) )
66
+ } )
67
+
68
+ it ( 'fails on malformed version' , function ( ) {
69
+ // malformed min version
70
+ assert . ok ( ! vscodeUtil . isExtensionInstalled ( extId , 'malformed.version' , getExtension ) )
71
+
72
+ // malformed ext version
73
+ ext . packageJSON . version = 'malformed.version'
74
+ assert . ok ( ! vscodeUtil . isExtensionInstalled ( extId , extVersion , getExtension ) )
75
+ } )
76
+ } )
77
+
78
+ describe ( 'buildMissingExtensionMessage()' , function ( ) {
79
+ const extId = 'MY.EXT.ID'
80
+ const extName = 'MY EXTENSION'
81
+ const minVer = '1.0.0'
82
+ const feat = 'FEATURE'
83
+
84
+ // Test when a minVer is given
85
+ it ( 'minVer' , function ( ) {
86
+ const message = vscodeUtil . buildMissingExtensionMessage ( extId , extName , minVer , feat )
87
+ assert . strictEqual (
88
+ message ,
89
+ `${ feat } requires the ${ extName } extension (\'${ extId } \' of version >=${ minVer } ) to be installed and enabled.`
90
+ )
91
+ } )
92
+
93
+ // Test when a minVer is not given
94
+ it ( 'no minVer' , function ( ) {
95
+ const message = vscodeUtil . buildMissingExtensionMessage ( extId , extName , undefined , feat )
96
+ assert . strictEqual (
97
+ message ,
98
+ `${ feat } requires the ${ extName } extension (\'${ extId } \') to be installed and enabled.`
99
+ )
100
+ } )
101
+ } )
0 commit comments