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 3bb9e64 Implement SettingsJson Class Tests and Update Documentation
(#15)
3bb9e64 is described below
commit 3bb9e64d46a61d7174b0b066f1c24d9b73d2c3d5
Author: Gedas Gardauskas <[email protected]>
AuthorDate: Fri Feb 15 12:17:05 2019 +0900
Implement SettingsJson Class Tests and Update Documentation (#15)
---
DOCUMENTATION.md | 8 +-
.../unit/templates/cordova/lib/prepare.spec.js | 129 +++++++++++++++++++++
2 files changed, 131 insertions(+), 6 deletions(-)
diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md
index 28dafd6..17159c9 100644
--- a/DOCUMENTATION.md
+++ b/DOCUMENTATION.md
@@ -190,13 +190,9 @@ mainWindow = new BrowserWindow({ fullscreen: true });
### DevTools
-> :warning: With the current state of the Cordova Electron platform, the
`--release` and `--debug` flag does not control the visibility of the DevTools.
+The `--release` and `--debug` flags control the visibility of the DevTools.
DevTools are shown by default on **Debug Builds** (`without a flag` or with
`--debug`). If you want to hide the DevTools pass in the `--release` flag when
building or running the application.
-To display the DevTools, uncomment the following line from the main.js process
file.
-
-```
-// mainWindow.webContents.openDevTools();
-```
+_Note: DevTools still can be closed or opened manually._
## Build Configurations
diff --git a/tests/spec/unit/templates/cordova/lib/prepare.spec.js
b/tests/spec/unit/templates/cordova/lib/prepare.spec.js
index 0d8541e..751371f 100644
--- a/tests/spec/unit/templates/cordova/lib/prepare.spec.js
+++ b/tests/spec/unit/templates/cordova/lib/prepare.spec.js
@@ -75,6 +75,135 @@ describe('Testing prepare.js:', () => {
});
});
+ describe('SettingJon class', () => {
+ let SettingJson;
+ let requireSpy;
+ let options;
+
+ beforeEach(() => {
+ SettingJson = prepare.__get__('SettingJson');
+
+ requireSpy = jasmine.createSpy('require').and.returnValue({});
+ prepare.__set__({ require: requireSpy });
+ });
+
+ it('should be called and package equal to false, if settings json does
not exist.', () => {
+ requireSpy = jasmine.createSpy('require').and.returnValue(false);
+ prepare.__set__({ require: requireSpy });
+
+ SettingJson = new SettingJson(locations.www);
+
+ expect(requireSpy).toHaveBeenCalled();
+ expect(SettingJson.package).toEqual(false);
+ });
+
+ it('should be called and package equal to true, if settings json does
exist.', () => {
+ SettingJson = new SettingJson(locations.www);
+
+ expect(requireSpy).toHaveBeenCalled();
+ expect(SettingJson.package).toEqual({});
+ });
+
+ it('should be equal to false, when no flag is set.', () => {
+ // mock options data
+ options = { options: { argv: [] } };
+
+ SettingJson = new
SettingJson(locations.www).configure(options.options);
+
+ expect(requireSpy).toHaveBeenCalled();
+ expect(SettingJson.package.isRelease).toEqual(false);
+ });
+
+ it('should be equal to false, when debug flag is set.', () => {
+ // mock options data
+ options = { options: { debug: true, argv: [] } };
+
+ SettingJson = new
SettingJson(locations.www).configure(options.options);
+
+ expect(requireSpy).toHaveBeenCalled();
+ expect(SettingJson.package.isRelease).toEqual(false);
+ });
+
+ it('should be equal to true, when release flag is set.', () => {
+ // mock options data
+ options = { options: { release: true, argv: [] } };
+
+ SettingJson = new
SettingJson(locations.www).configure(options.options);
+
+ expect(requireSpy).toHaveBeenCalled();
+ expect(SettingJson.package.isRelease).toEqual(true);
+ });
+
+ it('should write provided data, when no flag is set.', () => {
+ let writeFileSyncSpy;
+ writeFileSyncSpy = jasmine.createSpy('writeFileSync');
+ prepare.__set__('fs', { writeFileSync: writeFileSyncSpy });
+
+ options = { options: { argv: [] } };
+
+ SettingJson = new
SettingJson(locations.www).configure(options.options).write();
+
+ expect(writeFileSyncSpy).toHaveBeenCalled();
+
+ const settingsPath = writeFileSyncSpy.calls.argsFor(0)[0];
+
expect(settingsPath).toEqual('/mock/www/cdv-electron-settings.json');
+
+ // get settings json file content and remove white spaces
+ let settingsFile = writeFileSyncSpy.calls.argsFor(0)[1];
+ settingsFile = settingsFile.replace(/\s+/g, '');
+ expect(settingsFile).toEqual('{"isRelease":false}');
+
+ const settingsFormat = writeFileSyncSpy.calls.argsFor(0)[2];
+ expect(settingsFormat).toEqual('utf8');
+ });
+
+ it('should write provided data, when debug flag is set.', () => {
+ let writeFileSyncSpy;
+ writeFileSyncSpy = jasmine.createSpy('writeFileSync');
+ prepare.__set__('fs', { writeFileSync: writeFileSyncSpy });
+
+ options = { options: { debug: true, argv: [] } };
+
+ SettingJson = new
SettingJson(locations.www).configure(options.options).write();
+
+ expect(writeFileSyncSpy).toHaveBeenCalled();
+
+ const settingsPath = writeFileSyncSpy.calls.argsFor(0)[0];
+
expect(settingsPath).toEqual('/mock/www/cdv-electron-settings.json');
+
+ // get settings json file content and remove white spaces
+ let settingsFile = writeFileSyncSpy.calls.argsFor(0)[1];
+ settingsFile = settingsFile.replace(/\s+/g, '');
+ expect(settingsFile).toEqual('{"isRelease":false}');
+
+ const settingsFormat = writeFileSyncSpy.calls.argsFor(0)[2];
+ expect(settingsFormat).toEqual('utf8');
+ });
+
+ it('should write provided data.', () => {
+ let writeFileSyncSpy;
+ writeFileSyncSpy = jasmine.createSpy('writeFileSync');
+ prepare.__set__('fs', { writeFileSync: writeFileSyncSpy });
+
+ options = { options: { release: true, argv: [] } };
+
+ SettingJson = new
SettingJson(locations.www).configure(options.options).write();
+
+ expect(writeFileSyncSpy).toHaveBeenCalled();
+
+ const settingsPath = writeFileSyncSpy.calls.argsFor(0)[0];
+
expect(settingsPath).toEqual('/mock/www/cdv-electron-settings.json');
+
+ // get settings json file content and remove white spaces
+ let settingsFile = writeFileSyncSpy.calls.argsFor(0)[1];
+ settingsFile = settingsFile.replace(/\s+/g, '');
+ expect(settingsFile).toEqual('{"isRelease":true}');
+
+ const settingsFormat = writeFileSyncSpy.calls.argsFor(0)[2];
+ expect(settingsFormat).toEqual('utf8');
+ });
+ });
+
describe('updateIcons method', () => {
it('should detect no defined icons.', () => {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]