Skip to content

Commit

Permalink
Switch to using fs-extra in favour of shelljs
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed May 18, 2018
1 parent 7811258 commit 11f0051
Show file tree
Hide file tree
Showing 53 changed files with 192 additions and 228 deletions.
54 changes: 19 additions & 35 deletions integration-tests/HooksRunner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var cordova = require('../src/cordova/cordova');
var HooksRunner = require('../src/hooks/HooksRunner');
var shell = require('shelljs');
var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var os = require('os');
var Q = require('q');
var child_process = require('child_process');
Expand All @@ -46,12 +46,12 @@ var testPluginFixturePath = path.join(fixtures, 'plugins', 'com.plugin.withhooks
var cordovaUtil = require('../src/cordova/util');

// copy fixture
shell.rm('-rf', project);
shell.mkdir('-p', project);
shell.cp('-R', path.join(fixtures, 'projWithHooks', '*'), project);
fs.removeSync(project);
fs.ensureDirSync(project);
fs.copySync(path.join(fixtures, 'projWithHooks'), project);

shell.mkdir('-p', dotCordova);
shell.cp('-R', path.join(fixtures, 'projWithHooks', '.cordova'), project);
fs.ensureDirSync(dotCordova);
fs.copySync(path.join(fixtures, 'projWithHooks', '.cordova'), dotCordova);

// copy sh/bat scripts
if (ext === 'bat') {
Expand Down Expand Up @@ -104,11 +104,8 @@ describe('HooksRunner', function () {
hooksRunner = new HooksRunner(project);

// Add the testing platform.
cordova.platform('add', [helpers.testPlatform], {'fetch': true}).fail(function (err) {
expect(err).toBeUndefined();
console.error(err);
done();
}).then(function () {
cordova.platform('add', [helpers.testPlatform], {'fetch': true})
.then(function () {
// Add the testing plugin
projectRoot = cordovaUtil.isCordova();

Expand All @@ -121,14 +118,13 @@ describe('HooksRunner', function () {
options = cordovaUtil.preProcessOptions(options);
hookOptions = { projectRoot: project, cordova: options };

cordova.plugin('add', testPluginFixturePath, {'fetch': true}).fail(function (err) {
expect(err && err.stack).toBeUndefined();
done();
}).then(function () {
testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks');
done();
});
});
return cordova.plugin('add', testPluginFixturePath, {'fetch': true});
})
.then(function () {
testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks');
done();
})
.catch(done);
}, 100000);

describe('fire method', function () {
Expand Down Expand Up @@ -653,27 +649,15 @@ describe('HooksRunner', function () {
});

it('Test 024 :should not error if the hook is unrecognized', function (done) {
hooksRunner.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!', hookOptions).fail(function (err) {
expect('Call with unrecognized hook ').toBe('successful.\n' + err);
}).fin(done);
hooksRunner.fire('CLEAN YOUR SHORTS GODDAMNIT LIKE A BIG BOY!', hookOptions)
.catch(done)
.then(done);
});
});

// Cleanup. Must be the last spec. Is there a better place for final cleanup in Jasmine?
it('Test 025 : should not fail during cleanup', function () {
process.chdir(path.join(__dirname, '..')); // Non e2e tests assume CWD is repo root.
if (ext === 'sh') {
shell.rm('-rf', tmpDir);
} else { // Windows:
// For some mysterious reason, both shell.rm and RMDIR /S /Q won't
// delete the dir on Windows, but they do remove the files leaving
// only folders. But the dir is removed just fine by
// shell.rm('-rf', tmpDir) at the top of this file with the next
// invocation of this test. The benefit of RMDIR /S /Q is that it
// doesn't print warnings like shell.rmdir() that look like this:
// rm: could not remove directory (code ENOTEMPTY): C:\Users\...
var cmd = 'RMDIR /S /Q ' + tmpDir;
child_process.exec(cmd);
}
fs.removeSync(tmpDir);
});
});
2 changes: 1 addition & 1 deletion integration-tests/platform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

var helpers = require('../spec/helpers');
var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var shell = require('shelljs');
var superspawn = require('cordova-common').superspawn;
var config = require('../src/cordova/config');
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/plugman_fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
var rewire = require('rewire');
var fetch = rewire('../src/plugman/fetch');
var fs = require('fs');
var fs = require('fs-extra');
var os = require('os');
var path = require('path');
var shell = require('shelljs');
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/plugman_uninstall.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var common = require('../spec/common');
var platforms = require('../src/platforms/platforms');
var xmlHelpers = require('cordova-common').xmlHelpers;
var et = require('elementtree');
var fs = require('fs');
var fs = require('fs-extra');
var path = require('path');
var shell = require('shelljs');
var Q = require('q');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
},
"dependencies": {
"aliasify": "^2.1.0",
"cordova-common": "^2.2.0",
"cordova-common": "github:dpogue/cordova-common#fs-extra",
"cordova-create": "^1.1.0",
"cordova-fetch": "^1.3.0",
"cordova-js": "^4.2.2",
"cordova-serve": "^2.0.0",
"dep-graph": "1.1.0",
"detect-indent": "^5.0.0",
"elementtree": "^0.1.7",
"fs-extra": "^6.0.1",
"glob": "^7.1.2",
"init-package-json": "^1.2.0",
"nopt": "4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/metadata/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
under the License.
*/

var fs = require('fs');
var fs = require('fs-extra');
var Parser = require('../../../src/cordova/metadata/parser');
var ParserHelper = require('../../../src/cordova/metadata/parserhelper/ParserHelper');

Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/metadata/parserhelper/preferences.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var events = require('cordova-common').events;
var preferences = require('../../../../src/cordova/metadata/parserhelper/preferences');
var ConfigParser = require('cordova-common').ConfigParser;
Expand Down
5 changes: 2 additions & 3 deletions spec/cordova/platform/addHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
/* eslint-env jasmine */

var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var Q = require('q');
var shell = require('shelljs');
var events = require('cordova-common').events;
var rewire = require('rewire');
var platform_addHelper = rewire('../../../src/cordova/platform/addHelper');
Expand Down Expand Up @@ -64,7 +63,7 @@ describe('cordova/platform/addHelper', function () {
prepare_mock = jasmine.createSpy('prepare mock').and.returnValue(Q());
prepare_mock.preparePlatforms = jasmine.createSpy('preparePlatforms mock').and.returnValue(Q());
prepare_revert_mock = platform_addHelper.__set__('prepare', prepare_mock);
spyOn(shell, 'mkdir');
spyOn(fs, 'ensureDirSync');
spyOn(fs, 'existsSync').and.returnValue(false);
spyOn(fs, 'readFileSync');
spyOn(fs, 'writeFileSync');
Expand Down
6 changes: 3 additions & 3 deletions spec/cordova/platform/check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ http://www.apache.org/licenses/LICENSE-2.0
*/

var Q = require('q');
var shell = require('shelljs');
var fs = require('fs-extra');
var events = require('cordova-common').events;
var superspawn = require('cordova-common').superspawn;
var rewire = require('rewire');
Expand All @@ -30,7 +30,7 @@ describe('cordova/platform/check', function () {
beforeEach(function () {
spyOn(events, 'emit');
spyOn(superspawn, 'spawn').and.callThrough();
spyOn(shell, 'rm');
spyOn(fs, 'removeSync');
spyOn(cordova_util, 'listPlatforms');
});

Expand All @@ -39,7 +39,7 @@ describe('cordova/platform/check', function () {
platform_check(hooks_mock, projectRoot).then(function () {
expect(events.emit).toHaveBeenCalledWith('results', jasmine.stringMatching(/No platforms can be updated/));
expect(superspawn.spawn).toHaveBeenCalledWith('npm', ['--loglevel=silent', '--json', 'outdated', 'cordova-lib'], jasmine.any(Object));
expect(shell.rm).toHaveBeenCalledWith('-rf', jasmine.any(String));
expect(fs.removeSync).toHaveBeenCalledWith(jasmine.any(String));
}).fail(function (err) {
fail('unexpected failure handler invoked!');
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/platform/getPlatformDetailsFromDir.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var Q = require('q');
var rewire = require('rewire');
var cordova_util = require('../../../src/cordova/util');
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/platform/remove.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var Q = require('q');
var events = require('cordova-common').events;
var rewire = require('rewire');
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/plugin/add.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var add = rewire('../../../src/cordova/plugin/add');
var plugman = require('../../../src/plugman/plugman');
var cordova_util = require('../../../src/cordova/util');
var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var config = require('../../../src/cordova/config');
var events = require('cordova-common').events;
var plugin_util = require('../../../src/cordova/plugin/util');
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/plugin/remove.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var cordova_util = require('../../../src/cordova/util');
var metadata = require('../../../src/plugman/util/metadata');
var events = require('cordova-common').events;
var plugman = require('../../../src/plugman/plugman');
var fs = require('fs');
var fs = require('fs-extra');
var prepare = require('../../../src/cordova/prepare');
var plugin_util = require('../../../src/cordova/plugin/util');
var config = require('../../../src/cordova/config');
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/plugin/save.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* globals fail */

var rewire = require('rewire');
var fs = require('fs');
var fs = require('fs-extra');
var save = rewire('../../../src/cordova/plugin/save');
var cordova_util = require('../../../src/cordova/util');
var semver = require('semver');
Expand Down
6 changes: 3 additions & 3 deletions spec/cordova/plugin/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

var rewire = require('rewire');
var plugin_util = rewire('../../../src/cordova/plugin/util');
var shell = require('shelljs');
var fs = require('fs-extra');
var events = require('cordova-common').events;

describe('cordova/plugin/util', function () {
Expand All @@ -29,7 +29,7 @@ describe('cordova/plugin/util', function () {
var cfg_parser_revert_mock;
var cfg_parser_mock = function () {};
beforeEach(function () {
spyOn(shell, 'rm');
spyOn(fs, 'removeSync');
spyOn(events, 'emit');
cfg_parser_mock.prototype = jasmine.createSpyObj('config parser protytpe mock', ['getPlugin']);
cfg_parser_revert_mock = plugin_util.__set__('ConfigParser', cfg_parser_mock);
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('cordova/plugin/util', function () {
plugin_info_mock.prototype.getPreferences.and.returnValue({key: 'FCM_VERSION', value: undefined});
var opts = { cli_variables: {} };
expect(function () { plugin_util.mergeVariables(plugin_info_mock.prototype, cfg_parser_mock.prototype, opts); }).toThrow();
expect(shell.rm).toHaveBeenCalledWith('-rf', undefined);
expect(fs.removeSync).toHaveBeenCalledWith(undefined);
expect(events.emit).toHaveBeenCalledWith('verbose', 'Removing undefined because mandatory plugin variables were missing.');
});
});
Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/plugin_parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
/* eslint-env jasmine */
var path = require('path');
var fs = require('fs');
var fs = require('fs-extra');
var Plugin_parser = require('../../src/cordova/plugin_parser');
var xml = path.join(__dirname, 'fixtures', 'plugins', 'test', 'plugin.xml');

Expand Down
2 changes: 1 addition & 1 deletion spec/cordova/serve.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var cordova = require('../../src/cordova/cordova');
var console = require('console');
var path = require('path');
var shell = require('shelljs');
var fs = require('fs');
var fs = require('fs-extra');
var Q = require('q');
var tempDir;
var http = require('http');
Expand Down
Loading

0 comments on commit 11f0051

Please sign in to comment.