From 68d700f0d71abf57f643df9ddbb68cbbbe6cefd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Thu, 11 Apr 2019 02:36:43 +0200 Subject: [PATCH] Fix `cordova config list` command (#421) Fixes #418 --- spec/cli.spec.js | 8 +++----- src/cli.js | 9 +-------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/spec/cli.spec.js b/spec/cli.spec.js index 7e7b62604..abf10e76e 100644 --- a/spec/cli.spec.js +++ b/spec/cli.spec.js @@ -15,7 +15,6 @@ under the License. */ -const fs = require('fs'); const path = require('path'); const rewire = require('rewire'); /* @@ -438,6 +437,7 @@ describe('cordova cli', () => { const cordovaConfig = {}; const confMock = { + all: cordovaConfig, set (key, value) { cordovaConfig[key] = value; }, @@ -503,12 +503,10 @@ describe('cordova cli', () => { }); it('Test #047 : config ls is called', () => { - spyOn(fs, 'readFile').and.callFake((confPath, cb) => { - confHolder = confPath(); - }); + const expectedOutput = JSON.stringify(cordovaConfig, null, 4); return cli(['node', 'cordova', 'config', 'ls']).then(() => { - expect(path.basename(confHolder)).toEqual('cordova-config.json'); + expect(logger.results).toHaveBeenCalledWith(expectedOutput); }); }); diff --git a/src/cli.js b/src/cli.js index 8e07df73e..0d5089d69 100644 --- a/src/cli.js +++ b/src/cli.js @@ -29,7 +29,6 @@ var logger = require('cordova-common').CordovaLogger.get(); var Configstore = require('configstore'); var conf = new Configstore(pkg.name + '-config'); var editor = require('editor'); -var fs = require('fs'); var knownOpts = { 'verbose': Boolean, @@ -149,13 +148,7 @@ module.exports = function (inputArgs) { // If "ls" is called if (isConfigCmd && (inputArgs[3] === 'ls' || inputArgs[3] === 'list')) { - fs.readFile(conf.path, 'utf8', function (err, data) { - if (err) { - logger.error(err); - } else { - logger.log(data); - } - }); + logger.results(JSON.stringify(conf.all, null, 4)); } return Promise.resolve().then(function () {