diff --git a/src/util.spec.ts b/src/util.spec.ts index b30032e..74c490e 100644 --- a/src/util.spec.ts +++ b/src/util.spec.ts @@ -451,7 +451,7 @@ describe('util', () => { }); }); - describe.only('getOptionsFromJson', () => { + describe('getOptionsFromJson', () => { beforeEach(() => { fsExtra.ensureDirSync(rootDir); process.chdir(rootDir); @@ -465,24 +465,16 @@ describe('util', () => { }); }); - it(`can't find file`, () => { - fsExtra.writeJsonSync(s`${rootDir}/rokudeployed.json`, { host: '1.2.3.4' }); - expect( - util.getOptionsFromJson({ cwd: rootDir }) - ).to.eql(undefined); - - }); - it(`loads cwd from process`, () => { try { + fsExtra.writeJsonSync(s`${process.cwd()}/rokudeploy.json`, { host: '1.2.3.4' }); expect( - mainSceneEntries, - `Should only be one files entry for 'components/MainScene.brs'` - ).to.be.lengthOf(1); - expect(s`${mainSceneEntries[0].src}`).to.eql(s`${thisRootDir}/../.tmp/MainScene.brs`); + util.getOptionsFromJson() + ).to.eql({ + host: '1.2.3.4' + }); } finally { - //clean up - await fsExtra.remove(s`${thisRootDir}/../`); + fsExtra.removeSync(s`${process.cwd()}/rokudeploy.json`); } }); diff --git a/src/util.ts b/src/util.ts index 2895b06..56df6d3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -449,23 +449,25 @@ export class Util { const cwd = options?.cwd ?? process.cwd(); const configPath = path.join(cwd, 'rokudeploy.json'); - let configFileText = fsExtra.readFileSync(configPath).toString(); - let parseErrors = [] as ParseError[]; - fileOptions = parseJsonc(configFileText, parseErrors, { - allowEmptyContent: true, - allowTrailingComma: true, - disallowComments: false - }); - if (parseErrors.length > 0) { - throw new Error(`Error parsing "${path.resolve(configPath)}": ` + JSON.stringify( - parseErrors.map(x => { - return { - message: printParseErrorCode(x.error), - offset: x.offset, - length: x.length - }; - }) - )); + if (fsExtra.existsSync(configPath)) { + let configFileText = fsExtra.readFileSync(configPath).toString(); + let parseErrors = [] as ParseError[]; + fileOptions = parseJsonc(configFileText, parseErrors, { + allowEmptyContent: true, + allowTrailingComma: true, + disallowComments: false + }); + if (parseErrors.length > 0) { + throw new Error(`Error parsing "${path.resolve(configPath)}": ` + JSON.stringify( + parseErrors.map(x => { + return { + message: printParseErrorCode(x.error), + offset: x.offset, + length: x.length + }; + }) + )); + } } return fileOptions; }