mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
chore: use source and current local vars, + docs
This commit is contained in:
@@ -7,8 +7,15 @@ const assert = require('assert');
|
|||||||
const pkgInstall = require('../src/cli/package-install');
|
const pkgInstall = require('../src/cli/package-install');
|
||||||
|
|
||||||
describe('Package install lib', () => {
|
describe('Package install lib', () => {
|
||||||
|
/**
|
||||||
|
* Important:
|
||||||
|
* - The tests here have a beforeEach() run prior to each test, it resets
|
||||||
|
* package.json and install/package.json back to identical states.
|
||||||
|
* - Update `source` and `current` for testing.
|
||||||
|
*/
|
||||||
describe('updatePackageFile()', () => {
|
describe('updatePackageFile()', () => {
|
||||||
let source;
|
let source;
|
||||||
|
let current;
|
||||||
const sourcePackagePath = path.resolve(__dirname, '../install/package.json');
|
const sourcePackagePath = path.resolve(__dirname, '../install/package.json');
|
||||||
const packageFilePath = path.resolve(__dirname, '../package.json');
|
const packageFilePath = path.resolve(__dirname, '../package.json');
|
||||||
|
|
||||||
@@ -23,6 +30,7 @@ describe('Package install lib', () => {
|
|||||||
await fs.copyFile(path.resolve(__dirname, '../install/package.json.bak'), sourcePackagePath);
|
await fs.copyFile(path.resolve(__dirname, '../install/package.json.bak'), sourcePackagePath);
|
||||||
await fs.copyFile(path.resolve(__dirname, '../package.json.bak'), packageFilePath);
|
await fs.copyFile(path.resolve(__dirname, '../package.json.bak'), packageFilePath);
|
||||||
source = JSON.parse(await fs.readFile(sourcePackagePath));
|
source = JSON.parse(await fs.readFile(sourcePackagePath));
|
||||||
|
current = JSON.parse(await fs.readFile(packageFilePath));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove non-`nodebb-` modules not specified in `install/package.json`', async () => {
|
it('should remove non-`nodebb-` modules not specified in `install/package.json`', async () => {
|
||||||
@@ -65,9 +73,8 @@ describe('Package install lib', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should deep merge nested objects', async () => {
|
it('should deep merge nested objects', async () => {
|
||||||
source.scripts.postinstall = 'echo "I am a silly bean";';
|
current.scripts.postinstall = 'echo "I am a silly bean";';
|
||||||
await fs.writeFile(packageFilePath, JSON.stringify(source, null, 4));
|
await fs.writeFile(packageFilePath, JSON.stringify(current, null, 4));
|
||||||
delete source.scripts.postinstall;
|
|
||||||
source.scripts.preinstall = 'echo "What are you?";';
|
source.scripts.preinstall = 'echo "What are you?";';
|
||||||
await fs.writeFile(sourcePackagePath, JSON.stringify(source, null, 4));
|
await fs.writeFile(sourcePackagePath, JSON.stringify(source, null, 4));
|
||||||
source.scripts.postinstall = 'echo "I am a silly bean";';
|
source.scripts.postinstall = 'echo "I am a silly bean";';
|
||||||
|
|||||||
Reference in New Issue
Block a user