@@ -68,6 +68,61 @@ test("adds 'renovate' entry to package.json if it did not exist", async () => {
68
68
} ) ;
69
69
} ) ;
70
70
71
+ test ( "preserves spacing for JSON files" , async ( ) => {
72
+ const path = "renovate.json" ;
73
+
74
+ const originalPackageJson = {
75
+ name : "octoherd-cli" ,
76
+ version : "0.0.0" ,
77
+ description : "" ,
78
+ main : "index.js" ,
79
+ scripts : {
80
+ test : 'echo "Error: no test specified" && exit 1' ,
81
+ } ,
82
+ author : "" ,
83
+ license : "ISC" ,
84
+ } ;
85
+
86
+ nock ( "https://api.github.com" )
87
+ . get ( `/repos/${ repository . owner . login } /${ repository . name } /contents/${ path } ` )
88
+ . reply ( 200 , {
89
+ type : "file" ,
90
+ sha : "randomSha" ,
91
+ content : Buffer . from ( JSON . stringify ( originalPackageJson ) ) . toString (
92
+ "base64"
93
+ ) ,
94
+ } )
95
+ . put (
96
+ `/repos/${ repository . owner . login } /${ repository . name } /contents/${ path } ` ,
97
+ ( body ) => {
98
+ equal (
99
+ Buffer . from ( body . content , "base64" ) . toString ( ) ,
100
+ "{\n" +
101
+ '\t"name": "octoherd-cli",\n' +
102
+ '\t"version": "0.0.0",\n' +
103
+ '\t"description": "",\n' +
104
+ '\t"main": "index.js",\n' +
105
+ '\t"scripts": {\n' +
106
+ '\t\t"test": "echo \\"Error: no test specified\\" && exit 1"\n' +
107
+ "\t},\n" +
108
+ '\t"author": "",\n' +
109
+ '\t"license": "ISC",\n' +
110
+ '\t"extends": [\n' +
111
+ '\t\t"github>octoherd/.github"\n' +
112
+ "\t]\n" +
113
+ "}"
114
+ ) ;
115
+
116
+ return true ;
117
+ }
118
+ )
119
+ . reply ( 200 , { commit : { html_url : "link to commit" } } ) ;
120
+
121
+ await script ( getOctokitForTests ( ) , repository , {
122
+ extends : "github>octoherd/.github" ,
123
+ path,
124
+ } ) ;
125
+ } ) ;
71
126
test ( "adds 'renovate' entry ONLY to package.json files" , async ( ) => {
72
127
const path = "renovate.json" ;
73
128
0 commit comments