You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/test/package-install.js

33 lines
1.1 KiB
JavaScript

'use strict';
const { execSync } = require('child_process');
const path = require('path');
const { readFileSync } = require('fs');
const assert = require('assert');
describe('Package install', () => {
it('should remove non-`nodebb-` modules not specified in `install/package.json`', () => {
const oldValue = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
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');
// 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');
process.env.NODE_ENV = oldValue;
});
});