Skip to content
Permalink
Browse files
refactor: transform var to let/const (#137)
  • Loading branch information
erisu committed Mar 15, 2020
1 parent f128980 commit 1cdf107f860078625094ff80566ccecf8e5d2e46
Show file tree
Hide file tree
Showing 14 changed files with 429 additions and 429 deletions.
@@ -16,23 +16,23 @@
specific language governing permissions and limitations
under the License.
*/
var path = require('path');
var ActionStack = require('../src/ActionStack');
var android_one_project = path.join(__dirname, '..', 'projects', 'android_one');
const path = require('path');
const ActionStack = require('../src/ActionStack');
const android_one_project = path.join(__dirname, '..', 'projects', 'android_one');

describe('action-stack', function () {
var stack;
let stack;
beforeEach(function () {
stack = new ActionStack();
});
describe('processing of actions', function () {
it('Test 001 : should process actions one at a time until all are done', function () {
var first_spy = jasmine.createSpy();
var first_args = [1];
var second_spy = jasmine.createSpy();
var second_args = [2];
var third_spy = jasmine.createSpy();
var third_args = [3];
const first_spy = jasmine.createSpy();
const first_args = [1];
const second_spy = jasmine.createSpy();
const second_args = [2];
const third_spy = jasmine.createSpy();
const third_args = [3];
stack.push(stack.createAction(first_spy, first_args, function () {}, []));
stack.push(stack.createAction(second_spy, second_args, function () {}, []));
stack.push(stack.createAction(third_spy, third_args, function () {}, []));
@@ -43,17 +43,17 @@ describe('action-stack', function () {
});
it('Test 002 : should revert processed actions if an exception occurs', function () {
spyOn(console, 'log');
var first_spy = jasmine.createSpy();
var first_args = [1];
var first_reverter = jasmine.createSpy();
var first_reverter_args = [true];
var process_err = new Error('process_err');
var second_spy = jasmine.createSpy().and.callFake(function () {
const first_spy = jasmine.createSpy();
const first_args = [1];
const first_reverter = jasmine.createSpy();
const first_reverter_args = [true];
const process_err = new Error('process_err');
const second_spy = jasmine.createSpy().and.callFake(function () {
throw process_err;
});
var second_args = [2];
var third_spy = jasmine.createSpy();
var third_args = [3];
const second_args = [2];
const third_spy = jasmine.createSpy();
const third_args = [3];
stack.push(stack.createAction(first_spy, first_args, first_reverter, first_reverter_args));
stack.push(stack.createAction(second_spy, second_args, function () {}, []));
stack.push(stack.createAction(third_spy, third_args, function () {}, []));

Large diffs are not rendered by default.

@@ -15,9 +15,9 @@
under the License.
*/

var rewire = require('rewire');
var fs = require('fs-extra');
var path = require('path');
const rewire = require('rewire');
const fs = require('fs-extra');
const path = require('path');
const readChunk = require('read-chunk');

describe('ConfigFile tests', function () {
@@ -59,46 +59,46 @@ describe('ConfigFile tests', function () {
const projectDir = path.join('project_dir', 'app', 'src', 'main');

it('should return file path', function () {
var filePath = path.join('project_dir', 'file');
const filePath = path.join('project_dir', 'file');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'platform', 'file')).toBe(filePath);
});

it('should return AndroidManifest.xml file path', function () {
var androidManifestPath = path.join(projectDir, 'AndroidManifest.xml');
const androidManifestPath = path.join(projectDir, 'AndroidManifest.xml');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', 'AndroidManifest.xml')).toBe(androidManifestPath);
});

it('should return android config.xml file path', function () {
var configPath = path.join(projectDir, 'res', 'xml', 'config.xml');
const configPath = path.join(projectDir, 'res', 'xml', 'config.xml');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', 'config.xml')).toBe(configPath);
});

it('should return android strings.xml file path', function () {
var stringsPath = path.join(projectDir, 'res', 'values', 'strings.xml');
const stringsPath = path.join(projectDir, 'res', 'values', 'strings.xml');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', 'strings.xml')).toBe(stringsPath);
});

it('should return ios config.xml file path', function () {
spyOn(ConfigFile, 'getIOSProjectname').and.returnValue('iospath');
var configPath = path.join('project_dir', 'iospath', 'config.xml');
const configPath = path.join('project_dir', 'iospath', 'config.xml');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'ios', 'config.xml')).toBe(configPath);
});

it('should return osx config.xml file path', function () {
spyOn(ConfigFile, 'getIOSProjectname').and.returnValue('osxpath');
var configPath = path.join('project_dir', 'osxpath', 'config.xml');
const configPath = path.join('project_dir', 'osxpath', 'config.xml');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'osx', 'config.xml')).toBe(configPath);
});

it('should return android resource file path when path is normalized', function () {
var file = path.join('res', 'xml');
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
const file = path.join('res', 'xml');
const configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
});

it('should return android resource file path when path is not normalized', function () {
var file = 'res/xml';
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
const file = 'res/xml';
const configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(ConfigFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
});

@@ -17,19 +17,19 @@
under the License.
*/

var path = require('path');
var fs = require('fs-extra');
var ConfigParser = require('../../src/ConfigParser/ConfigParser');
var xml = path.join(__dirname, '../fixtures/test-config.xml');
var xml_contents = fs.readFileSync(xml, 'utf-8');
const path = require('path');
const fs = require('fs-extra');
const ConfigParser = require('../../src/ConfigParser/ConfigParser');
const xml = path.join(__dirname, '../fixtures/test-config.xml');
const xml_contents = fs.readFileSync(xml, 'utf-8');

describe('config.xml parser', function () {
beforeEach(function () {
spyOn(fs, 'readFileSync').and.returnValue(xml_contents);
});

it('Test 001 : should create an instance based on an xml file', function () {
var cfg;
let cfg;
expect(function () {
cfg = new ConfigParser(xml);
}).not.toThrow();
@@ -38,7 +38,7 @@ describe('config.xml parser', function () {
});

describe('methods', function () {
var cfg;
let cfg;
beforeEach(function () {
cfg = new ConfigParser(xml);
});
@@ -156,7 +156,7 @@ describe('config.xml parser', function () {
});
describe('plugin', function () {
it('Test 018 : should read plugin id list', function () {
var expectedList = [
const expectedList = [
'org.apache.cordova.pluginwithvars',
'org.apache.cordova.pluginwithurl',
'org.apache.cordova.pluginwithversion',
@@ -166,44 +166,44 @@ describe('config.xml parser', function () {
'org.apache.cordova.legacyfeatureurl',
'org.apache.cordova.legacyfeatureversionandurl'
];
var list = cfg.getPluginIdList();
const list = cfg.getPluginIdList();
expect(list.length).toEqual(expectedList.length);
expectedList.forEach(function (plugin) {
expect(list).toContain(plugin);
});
});
it('Test 019 : should read plugin given id', function () {
var plugin = cfg.getPlugin('org.apache.cordova.justaplugin');
const plugin = cfg.getPlugin('org.apache.cordova.justaplugin');
expect(plugin).toBeDefined();
expect(plugin.name).toEqual('org.apache.cordova.justaplugin');
expect(plugin.variables).toBeDefined();
});
it('Test 020 : should not read plugin given undefined id', function () {
var plugin = cfg.getPlugin('org.apache.cordova.undefinedplugin');
const plugin = cfg.getPlugin('org.apache.cordova.undefinedplugin');
expect(plugin).not.toBeDefined();
});
it('Test 021 : should read plugin with src and store it in spec field', function () {
var plugin = cfg.getPlugin('org.apache.cordova.pluginwithurl');
const plugin = cfg.getPlugin('org.apache.cordova.pluginwithurl');
expect(plugin.spec).toEqual('http://cordova.apache.org/pluginwithurl');
});
it('Test 022 : should read plugin with version and store it in spec field', function () {
var plugin = cfg.getPlugin('org.apache.cordova.pluginwithversion');
const plugin = cfg.getPlugin('org.apache.cordova.pluginwithversion');
expect(plugin.spec).toEqual('1.1.1');
});
it('Test 023 : should read plugin with source and version and store source in spec field', function () {
var plugin = cfg.getPlugin('org.apache.cordova.pluginwithurlandversion');
const plugin = cfg.getPlugin('org.apache.cordova.pluginwithurlandversion');
expect(plugin.spec).toEqual('http://cordova.apache.org/pluginwithurlandversion');
});
it('Test 024 : should read plugin variables', function () {
var plugin = cfg.getPlugin('org.apache.cordova.pluginwithvars');
const plugin = cfg.getPlugin('org.apache.cordova.pluginwithvars');
expect(plugin.variables).toBeDefined();
expect(plugin.variables.var).toBeDefined();
expect(plugin.variables.var).toEqual('varvalue');
});
it('Test 025 : should allow adding a new plugin', function () {
cfg.addPlugin({ name: 'myplugin' });
var plugins = cfg.doc.findall('plugin');
var pluginNames = plugins.map(function (plugin) {
const plugins = cfg.doc.findall('plugin');
const pluginNames = plugins.map(function (plugin) {
return plugin.attrib.name;
});
expect(pluginNames).toContain('myplugin');
@@ -212,80 +212,80 @@ describe('config.xml parser', function () {
cfg.addPlugin({ name: 'aplugin' }, [{ name: 'paraname', value: 'paravalue' }]);
// Additional check for new parameters syntax
cfg.addPlugin({ name: 'bplugin' }, { paraname: 'paravalue' });
var plugins = cfg.doc.findall('plugin')
const plugins = cfg.doc.findall('plugin')
.filter(function (plugin) {
return plugin.attrib.name === 'aplugin' || plugin.attrib.name === 'bplugin';
});
expect(plugins.length).toBe(2);
plugins.forEach(function (plugin) {
var variables = plugin.findall('variable');
const variables = plugin.findall('variable');
expect(variables[0].attrib.name).toEqual('paraname');
expect(variables[0].attrib.value).toEqual('paravalue');
});
});
it('Test 027 : should be able to read legacy feature entries with a version', function () {
var plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureversion');
const plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureversion');
expect(plugin).toBeDefined();
expect(plugin.name).toEqual('org.apache.cordova.legacyfeatureversion');
expect(plugin.spec).toEqual('1.2.3');
expect(plugin.variables).toBeDefined();
expect(plugin.variables.aVar).toEqual('aValue');
});
it('Test 028 : should be able to read legacy feature entries with a url', function () {
var plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureurl');
const plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureurl');
expect(plugin).toBeDefined();
expect(plugin.name).toEqual('org.apache.cordova.legacyfeatureurl');
expect(plugin.spec).toEqual('http://cordova.apache.org/legacyfeatureurl');
});
it('Test 029 : should be able to read legacy feature entries with a version and a url', function () {
var plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureversionandurl');
const plugin = cfg.getPlugin('org.apache.cordova.legacyfeatureversionandurl');
expect(plugin).toBeDefined();
expect(plugin.name).toEqual('org.apache.cordova.legacyfeatureversionandurl');
expect(plugin.spec).toEqual('http://cordova.apache.org/legacyfeatureversionandurl');
});
it('Test 030 : it should remove given plugin', function () {
cfg.removePlugin('org.apache.cordova.justaplugin');
var plugins = cfg.doc.findall('plugin');
var pluginNames = plugins.map(function (plugin) {
const plugins = cfg.doc.findall('plugin');
const pluginNames = plugins.map(function (plugin) {
return plugin.attrib.name;
});
expect(pluginNames).not.toContain('org.apache.cordova.justaplugin');
});
it('Test 031 : it should remove given legacy feature id', function () {
cfg.removePlugin('org.apache.cordova.legacyplugin');
var plugins = cfg.doc.findall('feature');
var pluginNames = plugins.map(function (plugin) {
const plugins = cfg.doc.findall('feature');
const pluginNames = plugins.map(function (plugin) {
return plugin.attrib.name;
});
expect(pluginNames).not.toContain('org.apache.cordova.legacyplugin');
});
it('Test 032 : it should read <access> tag entries', function () {
var accesses = cfg.getAccesses();
const accesses = cfg.getAccesses();
expect(accesses.length).not.toEqual(0);
});
it('Test 033 : it should read <allow-navigation> tag entries', function () {
var navigations = cfg.getAllowNavigations();
const navigations = cfg.getAllowNavigations();
expect(navigations.length).not.toEqual(0);
});
it('Test 034 : it should read <allow-intent> tag entries', function () {
var intents = cfg.getAllowIntents();
const intents = cfg.getAllowIntents();
expect(intents.length).not.toEqual(0);
});
it('Test 035: it should read <edit-config> tag entries', function () {
var editConfigs = cfg.getEditConfigs('android');
const editConfigs = cfg.getEditConfigs('android');
expect(editConfigs.length).not.toEqual(0);
});
it('Test 036: it should read <config-file> tag entries', function () {
var configFiles = cfg.getConfigFiles('android');
const configFiles = cfg.getConfigFiles('android');
expect(configFiles.length).not.toEqual(0);
});
});
describe('static resources', function () {
var hasPlatformPropertyDefined = function (e) { return !!e.platform; };
var hasSrcPropertyDefined = function (e) { return !!e.src; };
var hasTargetPropertyDefined = function (e) { return !!e.target; };
var hasDensityPropertyDefined = function (e) { return !!e.density; };
var hasPlatformPropertyUndefined = function (e) { return !e.platform; };
const hasPlatformPropertyDefined = function (e) { return !!e.platform; };
const hasSrcPropertyDefined = function (e) { return !!e.src; };
const hasTargetPropertyDefined = function (e) { return !!e.target; };
const hasDensityPropertyDefined = function (e) { return !!e.density; };
const hasPlatformPropertyUndefined = function (e) { return !e.platform; };

it('Test 035 : should fetch shared resources if platform parameter is not specified', function () {
expect(cfg.getStaticResources(null, 'icon').length).toBe(2);
@@ -331,9 +331,9 @@ describe('config.xml parser', function () {
});

describe('file resources', function () {
var hasSrcPropertyDefined = function (e) { return !!e.src; };
var hasTargetPropertyDefined = function (e) { return !!e.target; };
var hasArchPropertyDefined = function (e) { return !!e.arch; };
const hasSrcPropertyDefined = function (e) { return !!e.src; };
const hasTargetPropertyDefined = function (e) { return !!e.target; };
const hasArchPropertyDefined = function (e) { return !!e.arch; };

it('should fetch platform-specific resources', function () {
expect(cfg.getFileResources('android').length).toBe(2);

0 comments on commit 1cdf107

Please sign in to comment.