@@ -133,4 +133,38 @@ describe('rc-config', () => {
133
133
await fs . rm ( tempDir , { recursive : true , force : true } )
134
134
}
135
135
} )
136
+
137
+ it ( 'auto detect .ncurc.json' , async ( ) => {
138
+ const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'npm-check-updates-' ) )
139
+ const configFile = path . join ( tempDir , '.ncurc.json' )
140
+ const pkgFile = path . join ( tempDir , 'package.json' )
141
+ await fs . writeFile ( configFile , '{"filter": "ncu-test-v2"}' , 'utf-8' )
142
+ await fs . writeFile ( pkgFile , '{ "dependencies": { "ncu-test-v2": "1.0.0", "ncu-test-tag": "0.1.0" } }' , 'utf-8' )
143
+ try {
144
+ // awkwardly, we have to set mergeConfig to enable autodetecting the rcconfig because otherwise it is explicitly disabled for tests
145
+ const text = await spawn ( 'node' , [ bin , '--mergeConfig' ] , { cwd : tempDir } )
146
+ // On OSX tempDir is /var/folders/cb/12345, but npm-check-updates recieves /private/var/folders/cb/12345 (maybe symlink?).
147
+ // Therefore, ignore any directories prepended to the config file path.
148
+ text . should . match ( new RegExp ( `Using config file ([^\n]*)?${ configFile } ` ) )
149
+ } finally {
150
+ await fs . rm ( tempDir , { recursive : true , force : true } )
151
+ }
152
+ } )
153
+
154
+ it ( 'auto detect .ncurc.cjs' , async ( ) => {
155
+ const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'npm-check-updates-' ) )
156
+ const configFile = path . join ( tempDir , '.ncurc.cjs' )
157
+ const pkgFile = path . join ( tempDir , 'package.json' )
158
+ await fs . writeFile ( configFile , 'module.exports = { "filter": "ncu-test-v2" }' , 'utf-8' )
159
+ await fs . writeFile ( pkgFile , '{ "dependencies": { "ncu-test-v2": "1.0.0", "ncu-test-tag": "0.1.0" } }' , 'utf-8' )
160
+ try {
161
+ // awkwardly, we have to set mergeConfig to enable autodetecting the rcconfig because otherwise it is explicitly disabled for tests
162
+ const text = await spawn ( 'node' , [ bin , '--mergeConfig' ] , { cwd : tempDir } )
163
+ // On OSX tempDir is /var/folders/cb/12345, but npm-check-updates recieves /private/var/folders/cb/12345 (maybe symlink?).
164
+ // Therefore, ignore any directories prepended to the config file path.
165
+ text . should . match ( new RegExp ( `Using config file ([^\n]*)?${ configFile } ` ) )
166
+ } finally {
167
+ await fs . rm ( tempDir , { recursive : true , force : true } )
168
+ }
169
+ } )
136
170
} )
0 commit comments