Skip to content

Commit

Permalink
Add defaultsFromJson tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MilapNaik committed Feb 22, 2024
1 parent 36502e1 commit c058dd6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
52 changes: 51 additions & 1 deletion src/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { util, standardizePath as s } from './util';
import { expect } from 'chai';
import * as fsExtra from 'fs-extra';
import { tempDir } from './testUtils.spec';
import { tempDir, rootDir } from './testUtils.spec';
import * as path from 'path';
import * as dns from 'dns';
import { createSandbox } from 'sinon';
Expand All @@ -14,6 +14,7 @@ describe('util', () => {
});

afterEach(() => {
fsExtra.emptyDirSync(tempDir);
sinon.restore();
});

Expand Down Expand Up @@ -334,4 +335,53 @@ describe('util', () => {
expect(result).to.eql(expectedOutput);
});
});

describe('getOptionsFromJson', () => {
beforeEach(() => {
fsExtra.ensureDirSync(rootDir);
process.chdir(rootDir);
});
it('should fill in missing options from rokudeploy.json', () => {
fsExtra.writeJsonSync(s`${rootDir}/rokudeploy.json`, { password: 'password' });
let options = util.getOptionsFromJson({
rootDir: `${rootDir}`,
host: '1.2.3.4'
});
let expectedOutput = {
rootDir: `${rootDir}`,
host: '1.2.3.4',
password: 'password'
};
expect(options).to.eql(expectedOutput);
});

it('should fill in missing default options from bsconfig.json', () => {
fsExtra.writeJsonSync(s`${rootDir}/bsconfig.json`, { password: 'password' });
let options = util.getOptionsFromJson({
rootDir: `${rootDir}`,
host: '1.2.3.4'
});
let expectedOutput = {
rootDir: `${rootDir}`,
host: '1.2.3.4',
password: 'password'
};
expect(options).to.eql(expectedOutput);

});

it('should not replace default options', () => {
fsExtra.writeJsonSync(s`${rootDir}/rokudeploy.json`, { host: '4.3.2.1' });
let options = util.getOptionsFromJson({
rootDir: `${rootDir}`,
host: '1.2.3.4'
});
let expectedOutput = {
rootDir: `${rootDir}`,
host: '1.2.3.4',
};
expect(options).to.eql(expectedOutput);

});
});
});
5 changes: 3 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,10 @@ export class Util {

for (const fileName of fileNames) {
if (fsExtra.existsSync(fileName)) {
let rokudeployArgs = JSON.parse(fs.readFileSync('rokudeploy.json', 'utf-8'));
const sourcePath = path.join(defaultArgs.rootDir, fileName);
const rokuDeployArgs = JSON.parse(fsExtra.readFileSync(sourcePath, 'utf8'));
// args = Object.assign(rokudeployArgs ?? {}, args);
args = Object.assign(rokudeployArgs, args);
args = Object.assign(rokuDeployArgs, args);
break;
}
}
Expand Down

0 comments on commit c058dd6

Please sign in to comment.