@@ -10,42 +10,87 @@ describe("convertVSCodeConfig", () => {
10
10
const editorSettings = { unrelated : true } ;
11
11
12
12
// Act
13
- const result = convertVSCodeConfig ( JSON . stringify ( editorSettings ) , stubSettings ) ;
13
+ const result = convertVSCodeConfig ( JSON . stringify ( editorSettings , null , 4 ) , stubSettings ) ;
14
14
15
15
// Assert
16
- expect ( result ) . toEqual ( {
17
- contents : JSON . stringify ( editorSettings , null , 4 ) ,
18
- missing : [ ] ,
19
- } ) ;
16
+ expect ( result ) . toMatchInlineSnapshot ( `
17
+ Object {
18
+ "contents": "{
19
+ \\"unrelated\\": true
20
+ }",
21
+ "missing": Array [],
22
+ }
23
+ ` ) ;
20
24
} ) ;
21
25
22
- it ( "includes eslint.autoFixOnSave when source.fixAll.tslint exists" , ( ) => {
26
+ it ( "preserves original settings when the input structure is not an object" , ( ) => {
27
+ // Arrange
28
+ const editorSettings : never [ ] = [ ] ;
29
+
30
+ // Act
31
+ const result = convertVSCodeConfig ( JSON . stringify ( editorSettings , null , 4 ) , stubSettings ) ;
32
+
33
+ // Assert
34
+ expect ( result ) . toMatchInlineSnapshot ( `
35
+ Object {
36
+ "contents": "[]",
37
+ "missing": Array [],
38
+ }
39
+ ` ) ;
40
+ } ) ;
41
+
42
+ it ( "does not include eslint.autoFixOnSave when source.fixAll.tslint is false" , ( ) => {
23
43
// Arrange
24
44
const editorSettings = {
25
45
"editor.codeActionsOnSave" : {
26
- "source.fixAll.tslint" : true ,
46
+ "source.fixAll.tslint" : false ,
27
47
} ,
28
48
unrelated : true ,
29
49
} ;
30
50
31
51
// Act
32
- const result = convertVSCodeConfig ( JSON . stringify ( editorSettings ) , stubSettings ) ;
52
+ const result = convertVSCodeConfig ( JSON . stringify ( editorSettings , null , 4 ) , stubSettings ) ;
33
53
34
54
// Assert
35
- expect ( result ) . toEqual ( {
36
- contents : JSON . stringify (
37
- {
38
- "editor.codeActionsOnSave" : {
39
- "source.fixAll.tslint" : true ,
40
- "eslint.autoFixOnSave" : true ,
41
- } ,
42
- unrelated : true ,
43
- } ,
44
- null ,
45
- 4 ,
46
- ) ,
47
- missing : [ ] ,
48
- } ) ;
55
+ expect ( result ) . toMatchInlineSnapshot ( `
56
+ Object {
57
+ "contents": "{
58
+ \\"editor.codeActionsOnSave\\": {
59
+ \\"source.fixAll.tslint\\": false
60
+ },
61
+ \\"unrelated\\": true
62
+ }",
63
+ "missing": Array [],
64
+ }
65
+ ` ) ;
66
+ } ) ;
67
+
68
+ it ( "includes eslint.autoFixOnSave when source.fixAll.tslint is true" , ( ) => {
69
+ // Arrange
70
+ const editorSettings = {
71
+ "editor.codeActionsOnSave" : {
72
+ "source.fixAll.tslint" : true ,
73
+ } ,
74
+ unrelated : false ,
75
+ } ;
76
+
77
+ // Act
78
+ const result = convertVSCodeConfig ( JSON . stringify ( editorSettings , null , 4 ) , stubSettings ) ;
79
+
80
+ // Assert
81
+ expect ( result ) . toMatchInlineSnapshot ( `
82
+ Object {
83
+ "contents": "{
84
+ \\"editor.codeActionsOnSave\\": {
85
+ \\"source.fixAll.tslint\\": true,
86
+ \\"eslint.autoFixOnSave\\": true
87
+ },
88
+ \\"unrelated\\": false
89
+ }
90
+ ",
91
+ "missing": Array [],
92
+ }
93
+ ` ) ;
49
94
} ) ;
50
95
51
96
it ( "does not include configFile when tslint.configFile does not match the output config" , ( ) => {
@@ -56,7 +101,7 @@ describe("convertVSCodeConfig", () => {
56
101
} ;
57
102
58
103
// Act
59
- const result = convertVSCodeConfig ( JSON . stringify ( editorSettings ) , stubSettings ) ;
104
+ const result = convertVSCodeConfig ( JSON . stringify ( editorSettings , null , 4 ) , stubSettings ) ;
60
105
61
106
// Assert
62
107
expect ( result ) . toEqual ( {
@@ -73,23 +118,22 @@ describe("convertVSCodeConfig", () => {
73
118
} ;
74
119
75
120
// Act
76
- const result = convertVSCodeConfig ( JSON . stringify ( editorSettings ) , stubSettings ) ;
121
+ const result = convertVSCodeConfig ( JSON . stringify ( editorSettings , null , 4 ) , stubSettings ) ;
77
122
78
123
// Assert
79
- expect ( result ) . toEqual ( {
80
- contents : JSON . stringify (
81
- {
82
- "tslint.configFile" : "./tslint.json" ,
83
- unrelated : true ,
84
- "eslint.options" : {
85
- configFile : stubSettings . config ,
86
- } ,
87
- } ,
88
- null ,
89
- 4 ,
90
- ) ,
91
- missing : [ ] ,
92
- } ) ;
124
+ expect ( result ) . toMatchInlineSnapshot ( `
125
+ Object {
126
+ "contents": "{
127
+ \\"tslint.configFile\\": \\"./tslint.json\\",
128
+ \\"unrelated\\": true,
129
+ \\"eslint.options\\": {
130
+ \\"configFile\\": \\".eslintrc.js\\"
131
+ }
132
+ }
133
+ ",
134
+ "missing": Array [],
135
+ }
136
+ ` ) ;
93
137
} ) ;
94
138
95
139
it ( "includes missing notices when known missing settings are included" , ( ) => {
@@ -103,18 +147,26 @@ describe("convertVSCodeConfig", () => {
103
147
} ;
104
148
105
149
// Act
106
- const result = convertVSCodeConfig ( JSON . stringify ( editorSettings ) , stubSettings ) ;
150
+ const result = convertVSCodeConfig ( JSON . stringify ( editorSettings , null , 4 ) , stubSettings ) ;
107
151
108
152
// Assert
109
- expect ( result ) . toEqual ( {
110
- contents : JSON . stringify ( editorSettings , null , 4 ) ,
111
- missing : [
112
- "tslint.alwaysShowRuleFailuresAsWarnings" ,
113
- "tslint.exclude" ,
114
- "tslint.ignoreDefinitionFiles" ,
115
- "tslint.jsEnable" ,
116
- "tslint.suppressWhileTypeErrorsPresent" ,
117
- ] ,
118
- } ) ;
153
+ expect ( result ) . toMatchInlineSnapshot ( `
154
+ Object {
155
+ "contents": "{
156
+ \\"tslint.alwaysShowRuleFailuresAsWarnings\\": true,
157
+ \\"tslint.exclude\\": true,
158
+ \\"tslint.ignoreDefinitionFiles\\": true,
159
+ \\"tslint.jsEnable\\": true,
160
+ \\"tslint.suppressWhileTypeErrorsPresent\\": true
161
+ }",
162
+ "missing": Array [
163
+ "tslint.alwaysShowRuleFailuresAsWarnings",
164
+ "tslint.exclude",
165
+ "tslint.ignoreDefinitionFiles",
166
+ "tslint.jsEnable",
167
+ "tslint.suppressWhileTypeErrorsPresent",
168
+ ],
169
+ }
170
+ ` ) ;
119
171
} ) ;
120
172
} ) ;
0 commit comments