@@ -103,7 +103,7 @@ describe('SettingsManager: tests', function () {
103
103
function ( ) {
104
104
const writeToFile = sandbox . stub ( fs , 'writeFileSync' ) ;
105
105
const stateMock : IState = {
106
- version : '0' ,
106
+ version : '0.0.0 ' ,
107
107
status : ExtensionStatus . notActivated ,
108
108
welcomeShown : false ,
109
109
} ;
@@ -138,8 +138,13 @@ describe('SettingsManager: tests', function () {
138
138
139
139
it ( 'returns the state from the settings file' ,
140
140
function ( ) {
141
- const stateMock = '{ "version": "1.0.0", "status": 0, "welcomeShown": true}' ;
142
- sandbox . stub ( fs , 'readFileSync' ) . returns ( stateMock ) ;
141
+ const stateMock : IState = {
142
+ version : "1.0.0" ,
143
+ status : ExtensionStatus . enabled ,
144
+ welcomeShown : true ,
145
+ } ;
146
+ sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
147
+ sandbox . stub ( fs , 'readFileSync' ) . returns ( JSON . stringify ( stateMock ) ) ;
143
148
const state = settingsManager . getState ( ) ;
144
149
expect ( state ) . to . be . an . instanceOf ( Object ) ;
145
150
expect ( state ) . to . have . all . keys ( 'version' , 'status' , 'welcomeShown' ) ;
@@ -148,19 +153,29 @@ describe('SettingsManager: tests', function () {
148
153
149
154
it ( 'returns a default state if no settings file exists' ,
150
155
function ( ) {
151
- sandbox . stub ( fs , 'readFileSync ' ) . returns ( 'test' ) ;
156
+ sandbox . stub ( fs , 'existsSync ' ) . returns ( false ) ;
152
157
const state = settingsManager . getState ( ) ;
153
158
expect ( state ) . to . be . instanceOf ( Object ) ;
154
- expect ( state . version ) . to . be . equal ( '0' ) ;
159
+ expect ( state . version ) . to . be . equal ( '0.0.0 ' ) ;
155
160
} ) ;
156
161
157
162
it ( 'returns a default state if reading the file fails' ,
158
163
function ( ) {
164
+ sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
159
165
sandbox . stub ( fs , 'readFileSync' ) . throws ( Error ) ;
160
166
sandbox . stub ( console , 'error' ) ;
161
167
const state = settingsManager . getState ( ) ;
162
168
expect ( state ) . to . be . instanceOf ( Object ) ;
163
- expect ( state . version ) . to . be . equal ( '0' ) ;
169
+ expect ( state . version ) . to . be . equal ( '0.0.0' ) ;
170
+ } ) ;
171
+
172
+ it ( 'returns a default state if parsing the file content fails' ,
173
+ function ( ) {
174
+ sandbox . stub ( fs , 'existsSync' ) . returns ( true ) ;
175
+ sandbox . stub ( fs , 'readFileSync' ) . returns ( 'test' ) ;
176
+ const state = settingsManager . getState ( ) ;
177
+ expect ( state ) . to . be . instanceOf ( Object ) ;
178
+ expect ( state . version ) . to . be . equal ( '0.0.0' ) ;
164
179
} ) ;
165
180
166
181
} ) ;
@@ -169,7 +184,11 @@ describe('SettingsManager: tests', function () {
169
184
170
185
it ( 'truthy for a new extension version' ,
171
186
function ( ) {
172
- const stateMock = { version : "1.0.0" , status : 2 , welcomeShown : true } ;
187
+ const stateMock : IState = {
188
+ version : "1.0.0" ,
189
+ status : ExtensionStatus . notActivated ,
190
+ welcomeShown : true ,
191
+ } ;
173
192
const getState = sinon . stub ( settingsManager , 'getState' ) . returns ( stateMock ) ;
174
193
settingsManager . getSettings ( ) ;
175
194
expect ( settingsManager . isNewVersion ( ) ) . to . be . true ;
@@ -178,7 +197,11 @@ describe('SettingsManager: tests', function () {
178
197
179
198
it ( 'falsy for the same extension version' ,
180
199
function ( ) {
181
- const stateMock = { version : extensionSettings . version , status : 2 , welcomeShown : true } ;
200
+ const stateMock : IState = {
201
+ version : extensionSettings . version ,
202
+ status : ExtensionStatus . notActivated ,
203
+ welcomeShown : true ,
204
+ } ;
182
205
const getState = sinon . stub ( settingsManager , 'getState' ) . returns ( stateMock ) ;
183
206
settingsManager . getSettings ( ) ;
184
207
expect ( settingsManager . isNewVersion ( ) ) . to . be . false ;
@@ -187,7 +210,11 @@ describe('SettingsManager: tests', function () {
187
210
188
211
it ( 'falsy for an older extension version' ,
189
212
function ( ) {
190
- const stateMock = { version : "100.0.0" , status : 2 , welcomeShown : true } ;
213
+ const stateMock : IState = {
214
+ version : "100.0.0" ,
215
+ status : ExtensionStatus . notActivated ,
216
+ welcomeShown : true ,
217
+ } ;
191
218
const getState = sinon . stub ( settingsManager , 'getState' ) . returns ( stateMock ) ;
192
219
settingsManager . getSettings ( ) ;
193
220
expect ( settingsManager . isNewVersion ( ) ) . to . be . false ;
0 commit comments