| 
									
										
										
										
											2020-08-11 12:32:44 -06:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { execSync } = require('child_process'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | const { readFileSync } = require('fs'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var assert = require('assert'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | describe('Package install', () => { | 
					
						
							|  |  |  | 	it('should remove non-`nodebb-` modules not specified in `install/package.json`', () => { | 
					
						
							| 
									
										
										
										
											2020-08-11 12:32:44 -06:00
										 |  |  | 		const packageFilePath = path.join(__dirname, '../package.json'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// install an extra package
 | 
					
						
							|  |  |  | 		// chose dotenv because it's a popular package
 | 
					
						
							|  |  |  | 		// and we use nconf instead
 | 
					
						
							|  |  |  | 		execSync('npm install dotenv --save --production'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// assert it saves in package.json
 | 
					
						
							|  |  |  | 		const packageWithExtras = JSON.parse(readFileSync(packageFilePath, 'utf8')); | 
					
						
							|  |  |  | 		assert(packageWithExtras.dependencies.dotenv, 'dependency did not save'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// update the package file
 | 
					
						
							|  |  |  | 		require('../src/cli/package-install').updatePackageFile(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// assert it removed the extra package
 | 
					
						
							|  |  |  | 		const packageCleaned = JSON.parse(readFileSync(packageFilePath, 'utf8')); | 
					
						
							|  |  |  | 		assert(!packageCleaned.dependencies.dotenv, 'dependency was not removed'); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |