@@ -8,14 +8,15 @@ import * as vscode from 'vscode'
8
8
import { DevSettings , Experiments , fromExtensionManifest , PromptSettings , Settings } from '../../shared/settings'
9
9
import { TestSettings } from '../utilities/testSettingsConfiguration'
10
10
import { ClassToInterfaceType } from '../../shared/utilities/tsUtils'
11
+ import { Optional } from '../../shared/utilities/typeConstructors'
11
12
12
13
const SETTINGS_TARGET = vscode . ConfigurationTarget . Workspace
13
14
14
15
describe ( 'Settings' , function ( ) {
15
16
// These tests use an actual extension setting, because vscode.WorkspaceConfiguration fails when
16
17
// you attempt to update one that isn't defined in package.json. We will restore the setting value
17
18
// at the end of the tests.
18
- const SETTING_KEY = 'aws.telemetry '
19
+ const SETTING_KEY = 'aws.samcli.lambdaTimeout '
19
20
20
21
let sut : Settings
21
22
@@ -67,11 +68,10 @@ describe('Settings', function () {
67
68
//
68
69
// Setting exists but has wrong type:
69
70
//
70
- await settings . update ( SETTING_KEY , true , SETTINGS_TARGET )
71
+ await settings . update ( SETTING_KEY , 123 , SETTINGS_TARGET )
71
72
assert . throws ( ( ) => sut . get ( SETTING_KEY , String ) )
72
- assert . throws ( ( ) => sut . get ( SETTING_KEY , Number ) )
73
73
assert . throws ( ( ) => sut . get ( SETTING_KEY , Object ) )
74
- assert . throws ( ( ) => sut . get ( SETTING_KEY , Number ) )
74
+ assert . throws ( ( ) => sut . get ( SETTING_KEY , Boolean ) )
75
75
} )
76
76
} )
77
77
@@ -140,6 +140,11 @@ describe('Settings', function () {
140
140
assert . strictEqual ( instance . get ( 'profile' , 'bar' ) , 'bar' )
141
141
} )
142
142
143
+ it ( 'can use `undefined` as a default value' , function ( ) {
144
+ const OptionalProfile = fromExtensionManifest ( 'aws' , { profile : Optional ( String ) } )
145
+ assert . strictEqual ( new OptionalProfile ( settings ) . get ( 'profile' , undefined ) , undefined )
146
+ } )
147
+
143
148
it ( 'can use a saved setting' , async function ( ) {
144
149
await settings . update ( 'aws.profile' , 'foo' )
145
150
assert . strictEqual ( instance . get ( 'profile' ) , 'foo' )
@@ -150,6 +155,11 @@ describe('Settings', function () {
150
155
assert . strictEqual ( instance . get ( 'profile' , 'bar' ) , 'foo' )
151
156
} )
152
157
158
+ it ( 'uses the default value if the setting is invalid' , async function ( ) {
159
+ await settings . update ( 'aws.profile' , true )
160
+ assert . strictEqual ( instance . get ( 'profile' , 'foo' ) , 'foo' )
161
+ } )
162
+
153
163
it ( 'throws when the types do not match' , async function ( ) {
154
164
assert . throws ( ( ) => instance . get ( 'profile' ) )
155
165
@@ -200,17 +210,6 @@ describe('DevSetting', function () {
200
210
assert . strictEqual ( sut . get ( TEST_SETTING , false ) , true )
201
211
assert . deepStrictEqual ( await state , { [ TEST_SETTING ] : true } )
202
212
} )
203
-
204
- it ( 'bubbles up errors when in automation' , async function ( ) {
205
- await settings . update ( `aws.dev.${ TEST_SETTING } ` , 'junk' )
206
- assert . throws ( ( ) => sut . get ( TEST_SETTING , false ) )
207
- } )
208
-
209
- it ( 'only throws in automation' , async function ( ) {
210
- const noAutomation = new DevSettings ( settings , false )
211
- await settings . update ( `aws.dev.${ TEST_SETTING } ` , 'junk' )
212
- assert . strictEqual ( noAutomation . get ( TEST_SETTING , true ) , true )
213
- } )
214
213
} )
215
214
216
215
describe ( 'PromptSetting' , function ( ) {
0 commit comments