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 cd76586 Adding New Test Specs (#19)
cd76586 is described below
commit cd7658660dca0bbc90e395b95c11009aa4ceafab
Author: エリス <[email protected]>
AuthorDate: Wed Feb 20 15:46:45 2019 +0900
Adding New Test Specs (#19)
- Added Run Test Spec
- Added Clean Test Spec
- Added Update Test Spec
- Added Missing Apache License
---
tests/spec/unit/lib/update.spec.js | 47 ++++++++
.../spec/unit/templates/cordova/lib/clean.spec.js | 133 +++++++++++++++++++++
tests/spec/unit/templates/cordova/lib/run.spec.js | 70 +++++++++++
3 files changed, 250 insertions(+)
diff --git a/tests/spec/unit/lib/update.spec.js
b/tests/spec/unit/lib/update.spec.js
new file mode 100644
index 0000000..2849bcb
--- /dev/null
+++ b/tests/spec/unit/lib/update.spec.js
@@ -0,0 +1,47 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+const rewire = require('rewire');
+const update = rewire('../../../../bin/lib/update');
+
+describe('Update', () => {
+ describe('run export method', () => {
+ it('should reject with an errror that update is not supported.', () =>
{
+ update.run().then(
+ () => {},
+ (error) => {
+ expect(error).toEqual(new Error('Update not supported'));
+ }
+ );
+ });
+ });
+
+ describe('help export method', () => {
+ it('should warn that updating is not support for Electron.', () => {
+ const logSpy = jasmine.createSpy('log');
+ update.__set__('console', {
+ log: logSpy
+ });
+
+ update.help();
+
+ expect(logSpy.calls.argsFor(0)[0]).toContain('WARNING : Electron
does not support updating. Remove and then re-Add the platform to get the
latest.');
+ });
+ });
+});
diff --git a/tests/spec/unit/templates/cordova/lib/clean.spec.js
b/tests/spec/unit/templates/cordova/lib/clean.spec.js
new file mode 100644
index 0000000..b99eab2
--- /dev/null
+++ b/tests/spec/unit/templates/cordova/lib/clean.spec.js
@@ -0,0 +1,133 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+const rewire = require('rewire');
+const clean = rewire('../../../../../../bin/templates/cordova/lib/clean');
+
+describe('Clean', () => {
+ describe('run export method', () => {
+ it('should stop process when requirement check fails.', () => {
+ // get original
+ const _process = clean.__get__('process');
+
+ // create spies
+ const logSpy = jasmine.createSpy('log');
+ const exitSpy = jasmine.createSpy('exit');
+
+ // set spies
+ clean.__set__('console', { error: logSpy });
+ clean.__set__('check_reqs', {
+ run: jasmine.createSpy('run').and.returnValue(false)
+ });
+ clean.__set__('process', { exit: exitSpy });
+
+ // run test
+ clean.run();
+
+ const logArgs = logSpy.calls.argsFor(0)[0];
+ const expectedLog = 'Please make sure you meet the software
requirements in order to clean an electron cordova project';
+
+ expect(logArgs).toContain(expectedLog);
+ expect(exitSpy).toHaveBeenCalledWith(2);
+
+ // Reset
+ clean.__set__('process', _process);
+ });
+
+ it('should not find previous build dir and not attempt to remove.', ()
=> {
+ clean.__set__('check_reqs', {
+ run: jasmine.createSpy('run').and.returnValue(true)
+ });
+
+ const existsSyncSpy =
jasmine.createSpy('existsSync').and.returnValue(false);
+ const removeSyncSpy = jasmine.createSpy('removeSync');
+ clean.__set__('fs', {
+ existsSync: existsSyncSpy,
+ removeSync: removeSyncSpy
+ });
+
+ clean.run();
+
+ expect(existsSyncSpy).toHaveBeenCalled();
+ expect(removeSyncSpy).not.toHaveBeenCalled();
+ });
+
+ it('should find previous build dir and attempt to remove.', () => {
+ clean.__set__('check_reqs', {
+ run: jasmine.createSpy('run').and.returnValue(true)
+ });
+
+ const existsSyncSpy =
jasmine.createSpy('existsSync').and.returnValue(true);
+ const removeSyncSpy = jasmine.createSpy('removeSync');
+ clean.__set__('fs', {
+ existsSync: existsSyncSpy,
+ removeSync: removeSyncSpy
+ });
+
+ clean.run();
+
+ expect(existsSyncSpy).toHaveBeenCalled();
+ expect(removeSyncSpy).toHaveBeenCalled();
+ });
+
+ it('should find previous build dir and fail to remove.', () => {
+ clean.__set__('check_reqs', {
+ run: jasmine.createSpy('run').and.returnValue(true)
+ });
+
+ clean.__set__('fs', {
+ existsSync:
jasmine.createSpy('existsSync').and.returnValue(true),
+ removeSync: () => {
+ throw 'Fake Error';
+ }
+ });
+
+ expect(() => {
+ clean.run();
+ }).toThrow();
+ });
+ });
+
+ describe('cleanProject export method', () => {
+ it('should console out that it will execute run command.', () => {
+ const logSpy = jasmine.createSpy('log');
+ clean.__set__('console', {
+ log: logSpy
+ });
+
+ clean.cleanProject();
+
+ expect(logSpy.calls.argsFor(0)[0]).toContain('lib/clean will soon
only export a `run` command, please update to not call `cleanProject`.');
+ });
+ });
+
+ describe('help export method', () => {
+ it('should console out clean usage.', () => {
+ const logSpy = jasmine.createSpy('log');
+ clean.__set__('console', {
+ log: logSpy
+ });
+
+ clean.help({ binPath: 'foobar' });
+
+ expect(logSpy.calls.argsFor(0)[0]).toContain('Usage');
+ expect(logSpy.calls.argsFor(0)[0]).toContain('foobar');
+ });
+ });
+});
diff --git a/tests/spec/unit/templates/cordova/lib/run.spec.js
b/tests/spec/unit/templates/cordova/lib/run.spec.js
new file mode 100644
index 0000000..ea2fa0a
--- /dev/null
+++ b/tests/spec/unit/templates/cordova/lib/run.spec.js
@@ -0,0 +1,70 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+const rewire = require('rewire');
+const run = rewire('../../../../../../bin/templates/cordova/lib/run');
+
+describe('Run', () => {
+ describe('run export method', () => {
+ it('should spawn electron with main.js.', () => {
+ const _process = run.__get__('process');
+ const spawnSpy = jasmine.createSpy('spawn');
+ const onSpy = jasmine.createSpy('on');
+ const exitSpy = jasmine.createSpy('exit');
+
+ run.__set__('electron', 'electron-require');
+ run.__set__('process', {
+ exit: exitSpy
+ });
+
+ run.__set__('proc', {
+ spawn: spawnSpy.and.returnValue({
+ on: onSpy.and.callThrough()
+ })
+ });
+
+ run.run();
+
+ expect(spawnSpy).toHaveBeenCalledWith('electron-require',
['./platforms/electron/www/main.js']);
+ expect(onSpy).toHaveBeenCalled();
+ expect(exitSpy).not.toHaveBeenCalled();
+
+ // trigger exist as if process was killed
+ onSpy.calls.argsFor(0)[1]();
+ expect(exitSpy).toHaveBeenCalled();
+
+ run.__set__('process', _process);
+ });
+ });
+
+ describe('help export method', () => {
+ it('should console out run usage.', () => {
+ const logSpy = jasmine.createSpy('log');
+ run.__set__('console', {
+ log: logSpy
+ });
+
+ run.help({ binPath: 'foobar' });
+
+ expect(logSpy.calls.argsFor(0)[0]).toContain('Usage');
+ expect(logSpy.calls.argsFor(0)[0]).toContain('foobar');
+ expect(logSpy.calls.argsFor(0)[0]).toContain('nobuild');
+ });
+ });
+});
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]