Files
NodeBB/test/package-install.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
const { execSync } = require('child_process');
const path = require('path');
2022-02-04 13:24:57 -05:00
const { readFile } = require('fs').promises;
2021-02-04 00:06:15 -07:00
const assert = require('assert');
2021-02-04 00:01:39 -07:00
describe('Package install', () => {
2022-02-04 13:24:57 -05:00
it('should remove non-`nodebb-` modules not specified in `install/package.json`', async () => {
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
2022-02-04 13:24:57 -05:00
const packageWithExtras = JSON.parse(await readFile(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
2022-02-04 13:24:57 -05:00
const packageCleaned = JSON.parse(await readFile(packageFilePath, 'utf8'));
assert(!packageCleaned.dependencies.dotenv, 'dependency was not removed');
process.env.NODE_ENV = oldValue;
});
2022-02-04 13:24:57 -05:00
// it('should ')
});