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 1ccca7d test (node-12.16.x): fix failures caused by shebang and
rewire lint (#141)
1ccca7d is described below
commit 1ccca7d96c4b36b7f0baf5a919648573bfc56724
Author: エリス <[email protected]>
AuthorDate: Fri Feb 21 09:52:26 2020 +0900
test (node-12.16.x): fix failures caused by shebang and rewire lint (#141)
---
bin/lib/create.js | 2 --
bin/templates/cordova/Api.js | 16 +++++++++++++++-
bin/templates/cordova/version | 15 ++-------------
tests/spec/unit/Api.spec.js | 37 +++++++++++++++++++++++++++++++++----
4 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 3b95999..1e52de5 100644
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -1,5 +1,3 @@
-#!/usr/bin/env node
-
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js
index b705f08..bf5dc64 100644
--- a/bin/templates/cordova/Api.js
+++ b/bin/templates/cordova/Api.js
@@ -82,7 +82,7 @@ class Api {
locations: this.locations,
root: this.root,
name: this.platform,
- version: require('./version'),
+ version: Api.version(),
projectConfig: this.config
};
}
@@ -342,6 +342,20 @@ class Api {
requirements () {
return require('./lib/check_reqs').run();
}
+
+ static version () {
+ let platformPkg = null;
+
+ try {
+ // coming from user project
+ platformPkg =
require(require.resolve('cordova-electron/package.json'));
+ } catch (e) {
+ // coming from repo test & coho
+ platformPkg = require('../../../package.json');
+ }
+
+ return platformPkg.version;
+ }
}
// @todo create projectInstance and fulfill promise with it.
Api.updatePlatform = () => Promise.resolve();
diff --git a/bin/templates/cordova/version b/bin/templates/cordova/version
index 259e202..bbb52c6 100755
--- a/bin/templates/cordova/version
+++ b/bin/templates/cordova/version
@@ -19,16 +19,5 @@
under the License.
*/
-let VERSION = 'version undefined';
-
-try {
- const platformPkgPath = require.resolve('cordova-electron/package.json');
- const platformPkg = require(platformPkgPath) || null;
- VERSION = platformPkg.version || VERSION;
-} catch (e) {
- // Do nothing.
-}
-
-module.exports.version = VERSION;
-
-if (!module.parent) console.log(VERSION);
+const Api = require('./Api');
+console.log(Api.version());
diff --git a/tests/spec/unit/Api.spec.js b/tests/spec/unit/Api.spec.js
index 7a148d0..2aae8fe 100644
--- a/tests/spec/unit/Api.spec.js
+++ b/tests/spec/unit/Api.spec.js
@@ -99,8 +99,7 @@ describe('Api class', () => {
describe('getPlatformInfo method', () => {
it('should return object containing platform information', () => {
- // Mocking require that is called to get version.
- Api.__set__('require', () => '1.0.0');
+ spyOn(Api, 'version').and.returnValue('1.0.0');
expect(api.getPlatformInfo()).toEqual({
locations: mockExpectedLocations,
@@ -109,8 +108,6 @@ describe('Api class', () => {
version: '1.0.0',
projectConfig: undefined
});
-
- Api.__set__('require', apiRequire);
});
});
@@ -456,4 +453,36 @@ describe('Api prototype methods', () => {
expect(() => Api.createPlatform(tmpDir)).toThrowError();
});
});
+
+ describe('version method', () => {
+ it('should get version from cordova-electron package.', () => {
+ const dummyRequire = path => {
+
expect(path).toEqual('cordova-elecrtron-resolved-package-path');
+ return { version: '1.0.0' };
+ };
+
+ dummyRequire.resolve = path => {
+ return 'cordova-elecrtron-resolved-package-path';
+ };
+
+ Api.__set__('require', dummyRequire);
+
+ expect(Api.version()).toEqual('1.0.0');
+ });
+
+ it('should get version from package.json.', () => {
+ const dummyRequire = path => {
+ expect(path).toEqual('../../../package.json');
+ return { version: '1.0.0' };
+ };
+
+ dummyRequire.resolve = path => {
+ throw Error('random error');
+ };
+
+ Api.__set__('require', dummyRequire);
+
+ expect(Api.version()).toEqual('1.0.0');
+ });
+ });
});
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]