@@ -47,11 +47,11 @@ describe('Svelte Plugin', () => {
47
47
} ) ;
48
48
49
49
describe ( '#formatDocument' , ( ) => {
50
- function stubPrettier ( configExists : boolean ) {
50
+ function stubPrettier ( config : any ) {
51
51
const formatStub = sinon . stub ( ) . returns ( 'formatted' ) ;
52
52
53
53
sinon . stub ( importPackage , 'importPrettier' ) . returns ( < any > {
54
- resolveConfig : ( ) => Promise . resolve ( configExists && { fromConfig : true } ) ,
54
+ resolveConfig : ( ) => Promise . resolve ( config ) ,
55
55
getFileInfo : ( ) => ( { ignored : false } ) ,
56
56
format : formatStub ,
57
57
getSupportInfo : ( ) => ( { languages : [ { name : 'svelte' } ] } ) ,
@@ -60,12 +60,9 @@ describe('Svelte Plugin', () => {
60
60
return formatStub ;
61
61
}
62
62
63
- async function testFormat ( configExists : boolean , fallbackPrettierConfigExists : boolean ) {
64
- const { plugin, document } = setup (
65
- 'unformatted' ,
66
- fallbackPrettierConfigExists ? { fallbackConfig : true } : undefined ,
67
- ) ;
68
- const formatStub = stubPrettier ( configExists ) ;
63
+ async function testFormat ( config : any , fallbackPrettierConfig : any ) {
64
+ const { plugin, document } = setup ( 'unformatted' , fallbackPrettierConfig ) ;
65
+ const formatStub = stubPrettier ( config ) ;
69
66
70
67
const formatted = await plugin . formatDocument ( document , {
71
68
insertSpaces : true ,
@@ -95,7 +92,7 @@ describe('Svelte Plugin', () => {
95
92
} ) ;
96
93
97
94
it ( 'should use config for formatting' , async ( ) => {
98
- const formatStub = await testFormat ( true , true ) ;
95
+ const formatStub = await testFormat ( { fromConfig : true } , { fallbackConfig : true } ) ;
99
96
sinon . assert . calledOnceWithExactly ( formatStub , 'unformatted' , {
100
97
fromConfig : true ,
101
98
plugins : [ ] ,
@@ -104,7 +101,7 @@ describe('Svelte Plugin', () => {
104
101
} ) ;
105
102
106
103
it ( 'should use prettier fallback config for formatting' , async ( ) => {
107
- const formatStub = await testFormat ( false , true ) ;
104
+ const formatStub = await testFormat ( undefined , { fallbackConfig : true } ) ;
108
105
sinon . assert . calledOnceWithExactly ( formatStub , 'unformatted' , {
109
106
fallbackConfig : true ,
110
107
plugins : [ ] ,
@@ -113,7 +110,17 @@ describe('Svelte Plugin', () => {
113
110
} ) ;
114
111
115
112
it ( 'should use FormattingOptions for formatting' , async ( ) => {
116
- const formatStub = await testFormat ( false , false ) ;
113
+ const formatStub = await testFormat ( undefined , undefined ) ;
114
+ sinon . assert . calledOnceWithExactly ( formatStub , 'unformatted' , {
115
+ tabWidth : 4 ,
116
+ useTabs : false ,
117
+ plugins : [ ] ,
118
+ parser : 'svelte' ,
119
+ } ) ;
120
+ } ) ;
121
+
122
+ it ( 'should use FormattingOptions for formatting when configs are empty objects' , async ( ) => {
123
+ const formatStub = await testFormat ( { } , { } ) ;
117
124
sinon . assert . calledOnceWithExactly ( formatStub , 'unformatted' , {
118
125
tabWidth : 4 ,
119
126
useTabs : false ,
0 commit comments