Files
NodeBB/test/package-install.js
Barış Soner Uşaklı d27c9696e3 feat: add node 16 (#9847)
* feat: add node 16

* fix: check errors in fork

* test: add use-spawn

* test: another test

* Revert "test: another test"

This reverts commit 606efe26fe.

* test: another test

* fix: lint

* fix: remove spawn-wrap

* test: comment out plugin installs

* fix: lint

* test: uncomment all tests except npm i

* fix: lint

* test: bring back tests

* test: remove leftover override
2021-11-04 00:09:14 -04:00

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;
});
});