You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2019/02/25 02:43:26 UTC
[cordova-electron] branch master updated: Asset Install Fix from
Mobilespec Report (#30)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-electron.git
The following commit(s) were added to refs/heads/master by this push:
new 6548e75 Asset Install Fix from Mobilespec Report (#30)
6548e75 is described below
commit 6548e758613101a9e99221f4dba2c6375a0a98b5
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Mon Feb 25 11:43:21 2019 +0900
Asset Install Fix from Mobilespec Report (#30)
* Asset Install Fix from Mobilespec Report
* handler.js cleanup and test refactor
---
bin/templates/cordova/handler.js | 8 +++-----
tests/spec/unit/handler.spec.js | 37 +++++++++++++++++++++++--------------
2 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/bin/templates/cordova/handler.js b/bin/templates/cordova/handler.js
index 7a382df..40ede40 100644
--- a/bin/templates/cordova/handler.js
+++ b/bin/templates/cordova/handler.js
@@ -121,12 +121,10 @@ module.exports = {
install: (asset, plugin_dir, wwwDest) => {
const src = path.join(plugin_dir, asset.src);
const dest = path.join(wwwDest, asset.target);
+ const destDir = path.parse(dest).dir;
- if (fs.statSync(src).isDirectory()) {
- fs.copySync(src + '/*', dest);
- } else {
- fs.copySync(src, dest);
- }
+ if (destDir) fs.ensureDirSync(destDir);
+ fs.copySync(src, dest);
},
uninstall: (asset, wwwDest, plugin_id) => {
fs.removeSync(path.join(wwwDest, asset.target));
diff --git a/tests/spec/unit/handler.spec.js b/tests/spec/unit/handler.spec.js
index 1babd1a..7686bc3 100644
--- a/tests/spec/unit/handler.spec.js
+++ b/tests/spec/unit/handler.spec.js
@@ -330,37 +330,46 @@ describe('Handler export', () => {
const wwwDest = 'dest';
describe('Install', () => {
- it('if src is a directory, should be called with cp, -Rf', () => {
- const asset = { itemType: 'asset', src: 'someSrc/ServiceWorker.js', target: 'ServiceWorker.js' };
+ it('should copySync with a directory path.', () => {
+ const asset = {
+ itemType: 'asset',
+ src: 'someSrc/ServiceWorker.js',
+ target: 'ServiceWorker.js'
+ };
// Spies
- const copySyncSpy = jasmine.createSpy('copySync').and.returnValue('-Rf');
- const fsstatMock = { isDirectory: () => true };
- const statSyncSpy = jasmine.createSpy('statSync').and.returnValue(fsstatMock);
+ const copySyncSpy = jasmine.createSpy('copySync');
+ const ensureDirSyncSpy = jasmine.createSpy('ensureDirSync').and.returnValue(true);
+
handler.__set__('fs', {
copySync: copySyncSpy,
- statSync: statSyncSpy
+ ensureDirSync: ensureDirSyncSpy
});
handler.asset.install(asset, plugin_dir, wwwDest);
+ expect(ensureDirSyncSpy).toHaveBeenCalled();
expect(copySyncSpy).toHaveBeenCalledWith(jasmine.any(String), path.join('dest', asset.target));
});
- it('if src is not a directory, should be called with cp, -f', () => {
- const asset = { itemType: 'asset', src: 'someSrc', target: 'ServiceWorker.js' };
- const cpPath = path.join(plugin_dir, asset.src);
+ it('should call copySync with a file path.', () => {
+ const asset = {
+ itemType: 'asset',
+ src: 'someSrc/ServiceWorker.js',
+ target: 'ServiceWorker.js'
+ };
// Spies
- const copySyncSpy = jasmine.createSpy('copySync').and.returnValue('-f');
- const fsstatMock = { isDirectory: () => false };
- const statSyncSpy = jasmine.createSpy('statSync').and.returnValue(fsstatMock);
+ const copySyncSpy = jasmine.createSpy('copySync');
+ const ensureDirSyncSpy = jasmine.createSpy('ensureDirSync');
+
handler.__set__('fs', {
copySync: copySyncSpy,
- statSync: statSyncSpy
+ ensureDirSync: ensureDirSyncSpy
});
handler.asset.install(asset, plugin_dir, wwwDest);
- expect(copySyncSpy).toHaveBeenCalledWith(cpPath, path.join('dest', asset.target));
+ expect(ensureDirSyncSpy).toHaveBeenCalled();
+ expect(copySyncSpy).toHaveBeenCalledWith(jasmine.any(String), path.join('dest', asset.target));
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org