You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2017/10/17 23:39:53 UTC
cordova-common git commit: CB-11244 : added unit tests for ConfigFile
Repository: cordova-common
Updated Branches:
refs/heads/master 0e71312d5 -> cd46bd5ee
CB-11244 : added unit tests for ConfigFile
This closes #8
Project: http://git-wip-us.apache.org/repos/asf/cordova-common/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-common/commit/cd46bd5e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-common/tree/cd46bd5e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-common/diff/cd46bd5e
Branch: refs/heads/master
Commit: cd46bd5ee889c8e870fd709458748b3b68ecc72e
Parents: 0e71312
Author: Audrey So <au...@apache.org>
Authored: Mon Oct 16 06:29:31 2017 -0700
Committer: Steve Gill <st...@gmail.com>
Committed: Tue Oct 17 16:39:29 2017 -0700
----------------------------------------------------------------------
spec/ConfigChanges/ConfigFile.spec.js | 79 ++++++++++++++++++++++++++++++
src/ConfigChanges/ConfigFile.js | 5 +-
2 files changed, 83 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-common/blob/cd46bd5e/spec/ConfigChanges/ConfigFile.spec.js
----------------------------------------------------------------------
diff --git a/spec/ConfigChanges/ConfigFile.spec.js b/spec/ConfigChanges/ConfigFile.spec.js
new file mode 100644
index 0000000..3724efe
--- /dev/null
+++ b/spec/ConfigChanges/ConfigFile.spec.js
@@ -0,0 +1,79 @@
+/**
+ 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.
+*/
+
+var rewire = require('rewire');
+var configFile = rewire('../../src/ConfigChanges/ConfigFile');
+var fs = require('fs');
+var path = require('path');
+var projectDir = path.join('project_dir', 'app', 'src', 'main');
+
+describe('ConfigFile tests', function () {
+
+ beforeEach(function () {
+ spyOn(configFile, 'isBinaryPlist').and.callThrough();
+ });
+
+ it('ConfigFile_save/ConfigFile.prototype.save', function () {
+ spyOn(fs, 'writeFileSync');
+ configFile.prototype.save();
+ expect(fs.writeFileSync).toHaveBeenCalled();
+ });
+
+ it('isBinaryPlist should return false if not binary', function () {
+ spyOn(fs, 'readFileSync').and.returnValue('not bplist');
+ expect(configFile.isBinaryPlist('someFile')).toBe(false);
+ });
+ it('isBinaryPlist should return true if binary', function () {
+ spyOn(fs, 'readFileSync').and.returnValue('bplist');
+ expect(configFile.isBinaryPlist('someFile')).toBe(true);
+ });
+
+ it('getIOSProjectname should throw error', function () {
+ expect(function () { configFile.getIOSProjectname('some/project/name'); }).toThrow();
+ });
+
+ it('resolveConfigFilePath should return file path', function () {
+ var filePath = path.join('project_dir', 'file');
+ expect(configFile.resolveConfigFilePath('project_dir', 'platform', 'file')).toBe(filePath);
+ });
+
+ it('resolveConfigFilePath should return file path', function () {
+ var androidManifestPath = path.join(projectDir, 'AndroidManifest.xml');
+ expect(configFile.resolveConfigFilePath('project_dir', 'android', 'AndroidManifest.xml')).toBe(androidManifestPath);
+ });
+
+ it('resolveConfigFilePath should return file path', function () {
+ var configPath = path.join(projectDir, 'res', 'xml', 'config.xml');
+ expect(configFile.resolveConfigFilePath('project_dir', 'android', 'config.xml')).toBe(configPath);
+ });
+
+ it('resolveConfigFilePath should return file path', function () {
+ var stringsPath = path.join(projectDir, 'res', 'values', 'strings.xml');
+ expect(configFile.resolveConfigFilePath('project_dir', 'android', 'strings.xml')).toBe(stringsPath);
+ });
+
+ it('resolveConfigFilePath should return file path', function () {
+ spyOn(configFile, 'getIOSProjectname').and.returnValue('iospath');
+ var configPath = path.join('project_dir', 'iospath', 'config.xml');
+ expect(configFile.resolveConfigFilePath('project_dir', 'ios', 'config.xml')).toBe(configPath);
+ });
+
+ it('resolveConfigFilePath should return file path', function () {
+ var configPath = path.join('project_dir', 'config.xml');
+ expect(configFile.resolveConfigFilePath('project_dir', 'ubuntu', 'config.xml')).toBe(configPath);
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-common/blob/cd46bd5e/src/ConfigChanges/ConfigFile.js
----------------------------------------------------------------------
diff --git a/src/ConfigChanges/ConfigFile.js b/src/ConfigChanges/ConfigFile.js
index eb1a797..c860638 100644
--- a/src/ConfigChanges/ConfigFile.js
+++ b/src/ConfigChanges/ConfigFile.js
@@ -205,7 +205,7 @@ function resolveConfigFilePath (project_dir, platform, file) {
if (platform === 'ubuntu') {
filepath = path.join(project_dir, 'config.xml');
} else if (platform === 'ios') {
- var iospath = getIOSProjectname(project_dir);
+ var iospath = module.exports.getIOSProjectname(project_dir);
filepath = path.join(project_dir, iospath, 'config.xml');
} else {
matches = modules.glob.sync(path.join(project_dir, '**', 'config.xml'));
@@ -247,3 +247,6 @@ function isBinaryPlist (filename) {
}
module.exports = ConfigFile;
+module.exports.isBinaryPlist = isBinaryPlist;
+module.exports.getIOSProjectname = getIOSProjectname;
+module.exports.resolveConfigFilePath = resolveConfigFilePath;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org