diff --git a/.eslintrc.yml b/.eslintrc.yml index f6aae321cc..760eceb0b3 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,10 +1,27 @@ -root: true -extends: semistandard -rules: - indent: - - error - - 4 - camelcase: off - padded-blocks: off - operator-linebreak: off - no-throw-literal: off +# 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. + +extends: '@cordova/eslint-config/node' + +overrides: + - files: [spec/**/*.js] + extends: '@cordova/eslint-config/node-tests' + rules: + prefer-promise-reject-errors: off + + - files: [cordova-js-src/**/*.js] + extends: '@cordova/eslint-config/browser' \ No newline at end of file diff --git a/bin/create b/bin/create index 0ec93f62c5..65f239cbbc 100755 --- a/bin/create +++ b/bin/create @@ -23,12 +23,12 @@ var ConfigParser = require('cordova-common').ConfigParser; var Api = require('./templates/cordova/Api'); var argv = require('nopt')({ - 'help': Boolean, - 'cli': Boolean, - 'shared': Boolean, - 'link': Boolean, + help: Boolean, + cli: Boolean, + shared: Boolean, + link: Boolean, 'activity-name': [String, undefined] -}, { 'd': '--verbose' }); +}, { d: '--verbose' }); if (argv.help || argv.argv.remain.length === 0) { console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create')) + ' [] [--activity-name ] [--link]'); diff --git a/bin/lib/create.js b/bin/lib/create.js index c9670348de..3f234f9f87 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -140,7 +140,7 @@ function copyScripts (projectPath) { // Copy in the new ones. fs.copySync(srcScriptsDir, destScriptsDir); - let nodeModulesDir = path.join(ROOT, 'node_modules'); + const nodeModulesDir = path.join(ROOT, 'node_modules'); if (fs.existsSync(nodeModulesDir)) fs.copySync(nodeModulesDir, path.join(destScriptsDir, 'node_modules')); fs.copySync(path.join(bin, 'check_reqs'), path.join(destScriptsDir, 'check_reqs')); @@ -156,7 +156,7 @@ function copyScripts (projectPath) { // `require` path for the two libraries. if there's a better way to share // modules across both the repo and generated projects, we should make sure // to remove/update this. - let templatesCordovaRegex = /templates\/cordova\//; + const templatesCordovaRegex = /templates\/cordova\//; utils.replaceFileContents(android_sdk_version, templatesCordovaRegex, ''); utils.replaceFileContents(check_reqs, templatesCordovaRegex, ''); } @@ -218,7 +218,6 @@ function validateProjectName (project_name) { * @return {Promise} Directory where application has been created */ exports.create = function (project_path, config, options, events) { - options = options || {}; // Set default values for path, package and name @@ -229,8 +228,8 @@ exports.create = function (project_path, config, options, events) { } var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project'; - var project_name = config.name() ? - config.name().replace(/[^\w.]/g, '_') : 'CordovaExample'; + var project_name = config.name() + ? config.name().replace(/[^\w.]/g, '_') : 'CordovaExample'; var safe_activity_name = config.android_activityName() || options.activityName || 'MainActivity'; var target_api = check_reqs.get_target(); @@ -312,7 +311,6 @@ function generateDoneMessage (type, link) { // Returns a promise. exports.update = function (projectPath, options, events) { - var errorString = 'An in-place platform update is not supported. \n' + 'The `platforms` folder is always treated as a build artifact in the CLI workflow.\n' + diff --git a/bin/templates/cordova/build b/bin/templates/cordova/build index d703547695..b4e160ebe3 100755 --- a/bin/templates/cordova/build +++ b/bin/templates/cordova/build @@ -31,13 +31,13 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(args[2]) >= 0) { // Do some basic argument parsing var buildOpts = nopt({ - 'verbose': Boolean, - 'silent': Boolean, - 'debug': Boolean, - 'release': Boolean, - 'nobuild': Boolean, - 'buildConfig': path -}, { 'd': '--verbose' }); + verbose: Boolean, + silent: Boolean, + debug: Boolean, + release: Boolean, + nobuild: Boolean, + buildConfig: path +}, { d: '--verbose' }); // Make buildOptions compatible with PlatformApi build method spec buildOpts.argv = buildOpts.argv.original; diff --git a/bin/templates/cordova/clean b/bin/templates/cordova/clean index 9db5847080..5173d14b27 100755 --- a/bin/templates/cordova/clean +++ b/bin/templates/cordova/clean @@ -32,9 +32,9 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= // Do some basic argument parsing var opts = nopt({ - 'verbose': Boolean, - 'silent': Boolean -}, { 'd': '--verbose' }); + verbose: Boolean, + silent: Boolean +}, { d: '--verbose' }); // Make buildOptions compatible with PlatformApi clean method spec opts.argv = opts.argv.original; diff --git a/bin/templates/cordova/lib/android_sdk.js b/bin/templates/cordova/lib/android_sdk.js index 9074847ca1..c18b0ed996 100755 --- a/bin/templates/cordova/lib/android_sdk.js +++ b/bin/templates/cordova/lib/android_sdk.js @@ -52,13 +52,13 @@ module.exports.print_newest_available_sdk_target = function () { module.exports.version_string_to_api_level = { '4.0': 14, '4.0.3': 15, - '4.1': 16, - '4.2': 17, - '4.3': 18, - '4.4': 19, + 4.1: 16, + 4.2: 17, + 4.3: 18, + 4.4: 19, '4.4W': 20, '5.0': 21, - '5.1': 22, + 5.1: 22, '6.0': 23, '7.0': 24, '7.1.1': 25, diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js index 1196634976..15258f84d0 100644 --- a/bin/templates/cordova/lib/build.js +++ b/bin/templates/cordova/lib/build.js @@ -113,7 +113,7 @@ function parseOpts (options, resolvedTarget, projectRoot) { let shouldWarn = false; const signingKeys = ['keystore', 'alias', 'storePassword', 'password', 'keystoreType']; - for (let key in packageArgs) { + for (const key in packageArgs) { if (!shouldWarn && signingKeys.indexOf(key) > -1) { // If we enter this condition, we have a key used for signing a build, // but we are missing some required signing properties diff --git a/bin/templates/cordova/lib/builders/ProjectBuilder.js b/bin/templates/cordova/lib/builders/ProjectBuilder.js index 79ae8152b8..28e3a28139 100644 --- a/bin/templates/cordova/lib/builders/ProjectBuilder.js +++ b/bin/templates/cordova/lib/builders/ProjectBuilder.js @@ -82,7 +82,7 @@ function findOutputFilesHelper (dir, build_type, arch, extension) { if (files.length === 0) return files; // Assume arch-specific build if newest apk has -x86 or -arm. - let archSpecific = !!/-x86|-arm/.exec(path.basename(files[0])); + const archSpecific = !!/-x86|-arm/.exec(path.basename(files[0])); // And show only arch-specific ones (or non-arch-specific) files = files.filter(p => !!/-x86|-arm/.exec(path.basename(p)) === archSpecific); diff --git a/bin/templates/cordova/lib/check_reqs.js b/bin/templates/cordova/lib/check_reqs.js index b139b3d011..519db89540 100644 --- a/bin/templates/cordova/lib/check_reqs.js +++ b/bin/templates/cordova/lib/check_reqs.js @@ -31,7 +31,7 @@ var android_sdk = require('./android_sdk'); const { createEditor } = require('properties-parser'); function forgivingWhichSync (cmd) { - let whichResult = which.sync(cmd, { nothrow: true }); + const whichResult = which.sync(cmd, { nothrow: true }); // On null, returns empty string to maintain backwards compatibility // realpathSync follows symlinks @@ -39,11 +39,11 @@ function forgivingWhichSync (cmd) { } function getJDKDirectory (directory) { - let p = path.resolve(directory, 'java'); + const p = path.resolve(directory, 'java'); if (fs.existsSync(p)) { - let directories = fs.readdirSync(p); + const directories = fs.readdirSync(p); for (let i = 0; i < directories.length; i++) { - let dir = directories[i]; + const dir = directories[i]; if (/^(jdk)+./.test(dir)) { return path.resolve(directory, 'java', dir); } @@ -119,7 +119,6 @@ module.exports.get_gradle_wrapper = function () { var program_dir; // OK, This hack only works on Windows, not on Mac OS or Linux. We will be deleting this eventually! if (module.exports.isWindows()) { - var result = execa.sync(path.join(__dirname, 'getASPath.bat')); // console.log('result.stdout =' + result.stdout.toString()); // console.log('result.stderr =' + result.stderr.toString()); @@ -431,7 +430,6 @@ var Requirement = function (id, name, version, installed) { * @return Promise Array of requirements. Due to implementation, promise is always fulfilled. */ module.exports.check_all = function () { - var requirements = [ new Requirement('java', 'Java JDK'), new Requirement('androidSdk', 'Android SDK'), diff --git a/bin/templates/cordova/lib/config/GradlePropertiesParser.js b/bin/templates/cordova/lib/config/GradlePropertiesParser.js index 53a96386ed..14302d374c 100644 --- a/bin/templates/cordova/lib/config/GradlePropertiesParser.js +++ b/bin/templates/cordova/lib/config/GradlePropertiesParser.js @@ -17,10 +17,10 @@ under the License. */ -let fs = require('fs'); -let path = require('path'); -let propertiesParser = require('properties-parser'); -let events = require('cordova-common').events; +const fs = require('fs'); +const path = require('path'); +const propertiesParser = require('properties-parser'); +const events = require('cordova-common').events; class GradlePropertiesParser { /** @@ -82,7 +82,7 @@ class GradlePropertiesParser { _configureProperties (properties) { // Iterate though the properties and set only if missing. Object.keys(properties).forEach(key => { - let value = this.gradleFile.get(key); + const value = this.gradleFile.get(key); if (!value) { // Handles the case of adding missing defaults or new properties that are missing. diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js index 3c339c29f9..81525bae0c 100644 --- a/bin/templates/cordova/lib/emulator.js +++ b/bin/templates/cordova/lib/emulator.js @@ -43,7 +43,7 @@ const CHECK_BOOTED_INTERVAL = 3 * ONE_SECOND; // in milliseconds const EXEC_KILL_SIGNAL = 'SIGKILL'; function forgivingWhichSync (cmd) { - let whichResult = which.sync(cmd, { nothrow: true }); + const whichResult = which.sync(cmd, { nothrow: true }); // On null, returns empty string to maintain backwards compatibility // realpathSync follows symlinks @@ -104,7 +104,6 @@ module.exports.list_images_using_avdmanager = function () { if (response[i].match(/Name:\s/)) { emulator_list.push(response[i].split('Name: ')[1].replace('\r', ''); } */ - } return emulator_list; }); @@ -147,7 +146,6 @@ module.exports.list_images_using_android = function () { if (response[i].match(/Name:\s/)) { emulator_list.push(response[i].split('Name: ')[1].replace('\r', ''); } */ - } return emulator_list; }); @@ -429,7 +427,6 @@ module.exports.resolveTarget = function (target) { * Returns a promise. */ module.exports.install = function (givenTarget, buildResults) { - var target; // We need to find the proper path to the Android Manifest const manifestPath = path.join(__dirname, '..', '..', 'app', 'src', 'main', 'AndroidManifest.xml'); @@ -453,7 +450,6 @@ module.exports.install = function (givenTarget, buildResults) { // This promise is always resolved, even if 'adb uninstall' fails to uninstall app // or the app doesn't installed at all, so no error catching needed. return Promise.resolve().then(function () { - var apk_path = build.findBestApkForArchitecture(buildResults, target.arch); var execOptions = { cwd: os.tmpdir(), @@ -512,7 +508,6 @@ module.exports.install = function (givenTarget, buildResults) { }); // unlock screen }).then(function () { - events.emit('verbose', 'Unlocking screen...'); return Adb.shell(target.target, 'input keyevent 82'); }).then(function () { diff --git a/bin/templates/cordova/lib/pluginHandlers.js b/bin/templates/cordova/lib/pluginHandlers.js index d0de51385d..99e4bac72e 100644 --- a/bin/templates/cordova/lib/pluginHandlers.js +++ b/bin/templates/cordova/lib/pluginHandlers.js @@ -65,7 +65,7 @@ var handlers = { removeFile(path.resolve(project.projectDir, dest)); } }, - 'framework': { + framework: { install: function (obj, plugin, project, options) { var src = obj.src; if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id)); diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js index f8cc54c856..07d4d14051 100644 --- a/bin/templates/cordova/lib/prepare.js +++ b/bin/templates/cordova/lib/prepare.js @@ -29,7 +29,7 @@ var FileUpdater = require('cordova-common').FileUpdater; var PlatformJson = require('cordova-common').PlatformJson; var PlatformMunger = require('cordova-common').ConfigChanges.PlatformMunger; var PluginInfoProvider = require('cordova-common').PluginInfoProvider; -let utils = require('./utils'); +const utils = require('./utils'); const GradlePropertiesParser = require('./config/GradlePropertiesParser'); @@ -49,7 +49,7 @@ module.exports.prepare = function (cordovaProject, options) { const isGradlePluginKotlinEnabled = this._config.getPreference('GradlePluginKotlinEnabled', 'android'); const gradlePluginKotlinCodeStyle = this._config.getPreference('GradlePluginKotlinCodeStyle', 'android'); - let gradlePropertiesUserConfig = {}; + const gradlePropertiesUserConfig = {}; if (minSdkVersion) gradlePropertiesUserConfig.cdvMinSdkVersion = minSdkVersion; if (maxSdkVersion) gradlePropertiesUserConfig.cdvMaxSdkVersion = maxSdkVersion; if (targetSdkVersion) gradlePropertiesUserConfig.cdvTargetSdkVersion = targetSdkVersion; @@ -63,7 +63,7 @@ module.exports.prepare = function (cordovaProject, options) { gradlePropertiesUserConfig['android.enableJetifier'] = androidXEnabled; } - let gradlePropertiesParser = new GradlePropertiesParser(this.locations.root); + const gradlePropertiesParser = new GradlePropertiesParser(this.locations.root); gradlePropertiesParser.configure(gradlePropertiesUserConfig); // Update own www dir with project's www assets and plugins' assets and js-files @@ -222,9 +222,9 @@ function updateProjectAccordingTo (platformConfig, locations) { .write(); // Java file paths shouldn't be hard coded - let javaDirectory = path.join(locations.javaSrc, manifestId.replace(/\./g, '/')); - let javaPattern = /\.java$/; - let java_files = utils.scanDirectory(javaDirectory, javaPattern, true).filter(function (f) { + const javaDirectory = path.join(locations.javaSrc, manifestId.replace(/\./g, '/')); + const javaPattern = /\.java$/; + const java_files = utils.scanDirectory(javaDirectory, javaPattern, true).filter(function (f) { return utils.grep(f, /extends\s+CordovaActivity/g) !== null; }); @@ -234,7 +234,7 @@ function updateProjectAccordingTo (platformConfig, locations) { events.emit('log', 'Multiple candidate Java files that extend CordovaActivity found. Guessing at the first one, ' + java_files[0]); } - let destFile = java_files[0]; + const destFile = java_files[0]; // var destFile = path.join(locations.root, 'app', 'src', 'main', 'java', androidPkgName.replace(/\./g, '/'), path.basename(java_files[0])); // fs.ensureDirSync(path.dirname(destFile)); @@ -245,9 +245,9 @@ function updateProjectAccordingTo (platformConfig, locations) { utils.replaceFileContents(destFile, /package [\w.]*;/, 'package ' + androidPkgName + ';'); events.emit('verbose', 'Wrote out Android package name "' + androidPkgName + '" to ' + destFile); - var removeOrigPkg = checkReqs.isWindows() || checkReqs.isDarwin() ? - manifestId.toUpperCase() !== androidPkgName.toUpperCase() : - manifestId !== androidPkgName; + var removeOrigPkg = checkReqs.isWindows() || checkReqs.isDarwin() + ? manifestId.toUpperCase() !== androidPkgName.toUpperCase() + : manifestId !== androidPkgName; if (removeOrigPkg) { // If package was name changed we need to remove old java with main activity @@ -351,7 +351,7 @@ function cleanSplashes (projectRoot, projectConfig, platformResourcesDir) { } function updateIcons (cordovaProject, platformResourcesDir) { - let icons = cordovaProject.projectConfig.getIcons('android'); + const icons = cordovaProject.projectConfig.getIcons('android'); // Skip if there are no app defined icons in config.xml if (icons.length === 0) { @@ -361,14 +361,14 @@ function updateIcons (cordovaProject, platformResourcesDir) { // 1. loop icons determin if there is an error in the setup. // 2. during initial loop, also setup for legacy support. - let errorMissingAttributes = []; - let errorLegacyIconNeeded = []; + const errorMissingAttributes = []; + const errorLegacyIconNeeded = []; let hasAdaptive = false; icons.forEach((icon, key) => { if ( - (icon.background && !icon.foreground) - || (!icon.background && icon.foreground) - || (!icon.background && !icon.foreground && !icon.src) + (icon.background && !icon.foreground) || + (!icon.background && icon.foreground) || + (!icon.background && !icon.foreground && !icon.src) ) { errorMissingAttributes.push(icon.density ? icon.density : 'size=' + (icon.height || icon.width)); } @@ -377,10 +377,10 @@ function updateIcons (cordovaProject, platformResourcesDir) { hasAdaptive = true; if ( - !icon.src - && ( - icon.foreground.startsWith('@color') - || path.extname(path.basename(icon.foreground)) === '.xml' + !icon.src && + ( + icon.foreground.startsWith('@color') || + path.extname(path.basename(icon.foreground)) === '.xml' ) ) { errorLegacyIconNeeded.push(icon.density ? icon.density : 'size=' + (icon.height || icon.width)); @@ -390,7 +390,7 @@ function updateIcons (cordovaProject, platformResourcesDir) { } }); - let errorMessage = []; + const errorMessage = []; if (errorMissingAttributes.length > 0) { errorMessage.push('One of the following attributes are set but missing the other for the density type: ' + errorMissingAttributes.join(', ') + '. Please ensure that all require attributes are defined.'); } @@ -413,7 +413,7 @@ function updateIcons (cordovaProject, platformResourcesDir) { mapImageResources(cordovaProject.root, platformResourcesDir, 'mipmap', 'ic_launcher.xml') ); - let preparedIcons = prepareIcons(icons); + const preparedIcons = prepareIcons(icons); if (hasAdaptive) { resourceMap = updateIconResourceForAdaptive(preparedIcons, resourceMap, platformResourcesDir); @@ -426,8 +426,8 @@ function updateIcons (cordovaProject, platformResourcesDir) { } function updateIconResourceForAdaptive (preparedIcons, resourceMap, platformResourcesDir) { - let android_icons = preparedIcons.android_icons; - let default_icon = preparedIcons.default_icon; + const android_icons = preparedIcons.android_icons; + const default_icon = preparedIcons.default_icon; // The source paths for icons and splashes are relative to // project's config.xml location, so we use it as base path. @@ -436,7 +436,7 @@ function updateIconResourceForAdaptive (preparedIcons, resourceMap, platformReso let targetPathBackground; let targetPathForeground; - for (let density in android_icons) { + for (const density in android_icons) { let backgroundVal = '@mipmap/ic_launcher_background'; let foregroundVal = '@mipmap/ic_launcher_foreground'; @@ -476,7 +476,7 @@ function updateIconResourceForAdaptive (preparedIcons, resourceMap, platformReso `; - let launcherXmlPath = path.join(platformResourcesDir, 'mipmap-' + density + '-v26', 'ic_launcher.xml'); + const launcherXmlPath = path.join(platformResourcesDir, 'mipmap-' + density + '-v26', 'ic_launcher.xml'); // Remove the XML from the resourceMap so the file does not get removed. delete resourceMap[launcherXmlPath]; @@ -520,8 +520,8 @@ function updateIconResourceForAdaptive (preparedIcons, resourceMap, platformReso } function updateIconResourceForLegacy (preparedIcons, resourceMap, platformResourcesDir) { - let android_icons = preparedIcons.android_icons; - let default_icon = preparedIcons.default_icon; + const android_icons = preparedIcons.android_icons; + const default_icon = preparedIcons.default_icon; // The source paths for icons and splashes are relative to // project's config.xml location, so we use it as base path. @@ -550,7 +550,7 @@ function prepareIcons (icons) { 192: 'xxxhdpi' }; - let android_icons = {}; + const android_icons = {}; let default_icon; // find the best matching icon for a given density or size @@ -580,8 +580,8 @@ function prepareIcons (icons) { if (!size && !icon.density) { if (default_icon) { - let found = {}; - let favor = {}; + const found = {}; + const favor = {}; // populating found icon. if (icon.background && icon.foreground) { @@ -624,7 +624,7 @@ function cleanIcons (projectRoot, projectConfig, platformResourcesDir) { return; } - let resourceMap = Object.assign( + const resourceMap = Object.assign( {}, mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher.png'), mapImageResources(projectRoot, platformResourcesDir, 'mipmap', 'ic_launcher_foreground.png'), @@ -644,10 +644,10 @@ function cleanIcons (projectRoot, projectConfig, platformResourcesDir) { * Gets a map containing resources of a specified name from all drawable folders in a directory. */ function mapImageResources (rootDir, subDir, type, resourceName) { - let pathMap = {}; - let pattern = new RegExp(type + '+-.+'); + const pathMap = {}; + const pattern = new RegExp(type + '+-.+'); utils.scanDirectory(path.join(rootDir, subDir), pattern).forEach(function (drawableFolder) { - let imagePath = path.join(subDir, path.basename(drawableFolder), resourceName); + const imagePath = path.join(subDir, path.basename(drawableFolder), resourceName); pathMap[imagePath] = null; }); return pathMap; diff --git a/bin/templates/cordova/lib/retry.js b/bin/templates/cordova/lib/retry.js index b2b9a44961..e619b3d8a9 100644 --- a/bin/templates/cordova/lib/retry.js +++ b/bin/templates/cordova/lib/retry.js @@ -34,7 +34,6 @@ var events = require('cordova-common').events; * @returns {Promise} */ module.exports.retryPromise = function (attemptsLeft, promiseFunction) { - // NOTE: // get all trailing arguments, by skipping the first two (attemptsLeft and // promiseFunction) because they shouldn't get passed to promiseFunction diff --git a/bin/templates/cordova/lib/utils.js b/bin/templates/cordova/lib/utils.js index 5772e36a92..760eda604f 100644 --- a/bin/templates/cordova/lib/utils.js +++ b/bin/templates/cordova/lib/utils.js @@ -49,9 +49,9 @@ exports.replaceFileContents = function (file, searchRegex, replacementString) { * @returns string|null */ exports.grep = function (file, regex) { - let contents = fs.readFileSync(file).toString().replace(/\\r/g, '').split('\n'); + const contents = fs.readFileSync(file).toString().replace(/\\r/g, '').split('\n'); for (let i = 0; i < contents.length; i++) { - let line = contents[i]; + const line = contents[i]; if (regex.test(line)) { return line; } @@ -71,12 +71,12 @@ exports.scanDirectory = function (directory, regex, recursive) { let output = []; if (fs.existsSync(directory)) { - let items = fs.readdirSync(directory); + const items = fs.readdirSync(directory); for (let i = 0; i < items.length; i++) { - let item = items[i]; - let itemPath = path.join(directory, item); - let stats = fs.statSync(itemPath); + const item = items[i]; + const itemPath = path.join(directory, item); + const stats = fs.statSync(itemPath); if (regex.test(itemPath)) { output.push(itemPath); diff --git a/bin/templates/cordova/run b/bin/templates/cordova/run index a3d6f536b5..2e7efe2694 100755 --- a/bin/templates/cordova/run +++ b/bin/templates/cordova/run @@ -30,17 +30,17 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= // Do some basic argument parsing var runOpts = nopt({ - 'verbose': Boolean, - 'silent': Boolean, - 'debug': Boolean, - 'release': Boolean, - 'nobuild': Boolean, - 'buildConfig': path, - 'archs': String, - 'device': Boolean, - 'emulator': Boolean, - 'target': String -}, { 'd': '--verbose' }); + verbose: Boolean, + silent: Boolean, + debug: Boolean, + release: Boolean, + nobuild: Boolean, + buildConfig: path, + archs: String, + device: Boolean, + emulator: Boolean, + target: String +}, { d: '--verbose' }); // Make runOptions compatible with PlatformApi run method spec runOpts.argv = runOpts.argv.remain; diff --git a/bin/update b/bin/update index 86490d5094..f5a5de1a79 100755 --- a/bin/update +++ b/bin/update @@ -21,10 +21,10 @@ var path = require('path'); var Api = require('./templates/cordova/Api'); var args = require('nopt')({ - 'link': Boolean, - 'shared': Boolean, - 'help': Boolean -}, { 'd': '--verbose' }); + link: Boolean, + shared: Boolean, + help: Boolean +}, { d: '--verbose' }); if (args.help || args.argv.remain.length === 0) { console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' [--link]'); diff --git a/cordova-js-src/.eslintrc.yml b/cordova-js-src/.eslintrc.yml deleted file mode 100644 index e3d49d8a0a..0000000000 --- a/cordova-js-src/.eslintrc.yml +++ /dev/null @@ -1,4 +0,0 @@ -env: - node: false - commonjs: true - browser: true diff --git a/package.json b/package.json index 6aa8e966f6..77d4f28d57 100644 --- a/package.json +++ b/package.json @@ -19,12 +19,12 @@ "apache" ], "scripts": { - "test": "npm run eslint && npm run cover && npm run java-unit-tests", + "test": "npm run lint && npm run cover && npm run java-unit-tests", "unit-tests": "jasmine --config=spec/unit/jasmine.json", "cover": "nyc jasmine --config=spec/coverage.json", "e2e-tests": "jasmine --config=spec/e2e/jasmine.json", "java-unit-tests": "node test/run_java_unit_tests.js", - "eslint": "eslint . \"bin/**/!(*.*|gitignore)\"", + "lint": "eslint . \"bin/**/!(*.*|gitignore)\"", "clean-tests": "node bin/clean_test.js" }, "author": "Apache Software Foundation", @@ -40,13 +40,7 @@ "which": "^1.3.1" }, "devDependencies": { - "eslint": "^5.12.0", - "eslint-config-semistandard": "^13.0.0", - "eslint-config-standard": "^12.0.0", - "eslint-plugin-import": "^2.14.0", - "eslint-plugin-node": "^8.0.1", - "eslint-plugin-promise": "^4.0.1", - "eslint-plugin-standard": "^4.0.0", + "@cordova/eslint-config": "^2.0.0", "jasmine": "^3.5.0", "jasmine-spec-reporter": "^4.2.1", "nyc": "^14.1.1", diff --git a/spec/.eslintrc.yml b/spec/.eslintrc.yml deleted file mode 100644 index 77cb525cea..0000000000 --- a/spec/.eslintrc.yml +++ /dev/null @@ -1,4 +0,0 @@ -env: - jasmine: true -rules: - prefer-promise-reject-errors: off diff --git a/spec/e2e/helpers/projectActions.js b/spec/e2e/helpers/projectActions.js index 63aab73bd6..b51395551f 100644 --- a/spec/e2e/helpers/projectActions.js +++ b/spec/e2e/helpers/projectActions.js @@ -18,7 +18,7 @@ */ var PluginInfoProvider = require('cordova-common').PluginInfoProvider; -let fs = require('fs-extra'); +const fs = require('fs-extra'); var cp = require('child_process'); var path = require('path'); var util = require('util'); @@ -77,7 +77,6 @@ module.exports.updateProject = function (projectid, platformpath, callback) { } callback(error); }); - }; /** diff --git a/spec/unit/Adb.spec.js b/spec/unit/Adb.spec.js index 593470bc11..ac681e4827 100644 --- a/spec/unit/Adb.spec.js +++ b/spec/unit/Adb.spec.js @@ -225,5 +225,4 @@ emulator-5554\tdevice ); }); }); - }); diff --git a/spec/unit/AndroidManifest.spec.js b/spec/unit/AndroidManifest.spec.js index aa083455ae..12e08e36c2 100644 --- a/spec/unit/AndroidManifest.spec.js +++ b/spec/unit/AndroidManifest.spec.js @@ -238,5 +238,4 @@ describe('AndroidManifest', () => { expect(fsSpy.writeFileSync).toHaveBeenCalledWith(jasmine.any(String), newXml, 'utf-8'); }); }); - }); diff --git a/spec/unit/android_sdk.spec.js b/spec/unit/android_sdk.spec.js index e5e0c322d2..6cf77c2101 100644 --- a/spec/unit/android_sdk.spec.js +++ b/spec/unit/android_sdk.spec.js @@ -71,7 +71,7 @@ describe('android_sdk', () => { execaSpy.and.returnValue(Promise.resolve({ stdout: testTargets })); return android_sdk.list_targets_with_android().then(list => { - [ 'Google Inc.:Google APIs:23', + ['Google Inc.:Google APIs:23', 'Google Inc.:Google APIs:22', 'Google Inc.:Google APIs:21', 'android-25', @@ -81,7 +81,7 @@ describe('android_sdk', () => { 'android-MNC', 'android-22', 'android-21', - 'android-20' ].forEach((target) => expect(list).toContain(target)); + 'android-20'].forEach((target) => expect(list).toContain(target)); }); }); }); diff --git a/spec/unit/config/GradlePropertiesParser.spec.js b/spec/unit/config/GradlePropertiesParser.spec.js index 0ce2df8b57..4c05da2b73 100644 --- a/spec/unit/config/GradlePropertiesParser.spec.js +++ b/spec/unit/config/GradlePropertiesParser.spec.js @@ -18,7 +18,7 @@ */ const rewire = require('rewire'); -let GradlePropertiesParser = rewire('../../../bin/templates/cordova/lib/config/GradlePropertiesParser'); +const GradlePropertiesParser = rewire('../../../bin/templates/cordova/lib/config/GradlePropertiesParser'); describe('Gradle Builder', () => { describe('_initializeEditor method', () => { @@ -91,8 +91,8 @@ describe('Gradle Builder', () => { }); it('should detect missing default property and sets the property.', () => { - let setSpy = jasmine.createSpy('set'); - let getSpy = jasmine.createSpy('get').and.returnValue(false); + const setSpy = jasmine.createSpy('set'); + const getSpy = jasmine.createSpy('get').and.returnValue(false); parser.gradleFile = { set: setSpy, @@ -107,8 +107,8 @@ describe('Gradle Builder', () => { }); it('should not detect missing defaults and call set.', () => { - let setSpy = jasmine.createSpy('set'); - let getSpy = jasmine.createSpy('get').and.returnValue(true); + const setSpy = jasmine.createSpy('set'); + const getSpy = jasmine.createSpy('get').and.returnValue(true); parser.gradleFile = { set: setSpy, @@ -122,8 +122,8 @@ describe('Gradle Builder', () => { }); it('should detect default with changed value to match default and set.', () => { - let setSpy = jasmine.createSpy('set'); - let getSpy = jasmine.createSpy('get').and.returnValue('-Xmx512m'); + const setSpy = jasmine.createSpy('set'); + const getSpy = jasmine.createSpy('get').and.returnValue('-Xmx512m'); parser.gradleFile = { set: setSpy, @@ -138,8 +138,8 @@ describe('Gradle Builder', () => { }); it('should detect default with changed value different from default and set.', () => { - let setSpy = jasmine.createSpy('set'); - let getSpy = jasmine.createSpy('get').and.returnValue('-Xmx2048m'); + const setSpy = jasmine.createSpy('set'); + const getSpy = jasmine.createSpy('get').and.returnValue('-Xmx2048m'); parser.gradleFile = { set: setSpy, diff --git a/spec/unit/create.spec.js b/spec/unit/create.spec.js index ec2c869a96..82ace72a52 100644 --- a/spec/unit/create.spec.js +++ b/spec/unit/create.spec.js @@ -224,7 +224,6 @@ describe('create', function () { }, err => { expect(err).toBe(fakeError); }); - }); }); diff --git a/spec/unit/emulator.spec.js b/spec/unit/emulator.spec.js index 8ee203fb54..86cb3ed660 100644 --- a/spec/unit/emulator.spec.js +++ b/spec/unit/emulator.spec.js @@ -37,7 +37,7 @@ describe('emulator', () => { it('should properly parse details of SDK Tools 25.3.1 `avdmanager` output', () => { const avdList = fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.3-avdmanager_list_avd.txt'), 'utf-8'); - let execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: avdList })); + const execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: avdList })); emu.__set__('execa', execaSpy); return emu.list_images_using_avdmanager().then(list => { @@ -52,7 +52,7 @@ describe('emulator', () => { describe('list_images_using_android', () => { it('should invoke `android` with the `list avd` command and _not_ the `list avds` command, as the plural form is not supported in some Android SDK Tools versions', () => { - let execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: '' })); + const execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: '' })); emu.__set__('execa', execaSpy); emu.list_images_using_android(); @@ -62,7 +62,7 @@ describe('emulator', () => { it('should properly parse details of SDK Tools pre-25.3.1 `android list avd` output', () => { const avdList = fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.2-android_list_avd.txt'), 'utf-8'); - let execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: avdList })); + const execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: avdList })); emu.__set__('execa', execaSpy); return emu.list_images_using_android().then(list => { diff --git a/spec/unit/pluginHandlers/common.spec.js b/spec/unit/pluginHandlers/common.spec.js index ead1bb9826..3a8f74e8a0 100644 --- a/spec/unit/pluginHandlers/common.spec.js +++ b/spec/unit/pluginHandlers/common.spec.js @@ -35,7 +35,6 @@ var deleteJava = common.__get__('deleteJava'); var copyNewFile = common.__get__('copyNewFile'); describe('common platform handler', function () { - describe('copyFile', function () { it('Test#001 : should throw if source path not found', function () { fs.removeSync(src); diff --git a/spec/unit/pluginHandlers/handlers.spec.js b/spec/unit/pluginHandlers/handlers.spec.js index ee41424f85..e5aa3ed3e7 100644 --- a/spec/unit/pluginHandlers/handlers.spec.js +++ b/spec/unit/pluginHandlers/handlers.spec.js @@ -177,7 +177,6 @@ describe('android project handler', function () { }); describe('of elements', function () { - var someString = jasmine.any(String); var copyNewFileOrig = common.__get__('copyNewFile'); @@ -280,9 +279,8 @@ describe('android project handler', function () { }); describe('uninstallation', function () { - var deleteJavaOrig = common.__get__('deleteJava'); - let originalRemoveSync = fs.removeSync; + const originalRemoveSync = fs.removeSync; var deleteJavaSpy = jasmine.createSpy('deleteJava'); var dummyProject; let removeSyncSpy; @@ -387,7 +385,6 @@ describe('android project handler', function () { }); describe('of elements', function () { - var someString = jasmine.any(String); beforeEach(function () { diff --git a/spec/unit/prepare.spec.js b/spec/unit/prepare.spec.js index 55008c1aa9..da6fcca288 100644 --- a/spec/unit/prepare.spec.js +++ b/spec/unit/prepare.spec.js @@ -29,7 +29,7 @@ const PATH_RESOURCE = path.join('platforms', 'android', 'app', 'src', 'main', 'r * @param {String} target specific resource item */ function createResourceMap (target) { - let resources = {}; + const resources = {}; [ 'mipmap-ldpi', @@ -152,8 +152,8 @@ describe('updateIcons method', function () { expect(emitSpy).toHaveBeenCalled(); // The emit message was. - let actual = emitSpy.calls.argsFor(0)[1]; - let expected = 'This app does not have launcher icons defined'; + const actual = emitSpy.calls.argsFor(0)[1]; + const expected = 'This app does not have launcher icons defined'; expect(actual).toEqual(expected); }); @@ -340,11 +340,11 @@ describe('updateIcons method', function () { }; // Creating Spies - let resourceMap = createResourceMap(); - let phaseOneModification = {}; + const resourceMap = createResourceMap(); + const phaseOneModification = {}; phaseOneModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_foreground.png')] = 'res/icon/android/mdpi-foreground.png'; phaseOneModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_background.png')] = 'res/icon/android/mdpi-background.png'; - let phaseOneUpdatedIconsForAdaptive = Object.assign({}, resourceMap, phaseOneModification); + const phaseOneUpdatedIconsForAdaptive = Object.assign({}, resourceMap, phaseOneModification); updateIconResourceForAdaptiveSpy = jasmine.createSpy('updateIconResourceForAdaptiveSpy'); prepare.__set__('updateIconResourceForAdaptive', function (preparedIcons, resourceMap, platformResourcesDir) { @@ -352,10 +352,10 @@ describe('updateIcons method', function () { return phaseOneUpdatedIconsForAdaptive; }); - let phaseTwoModification = {}; + const phaseTwoModification = {}; phaseTwoModification[path.join(PATH_RESOURCE, 'mipmap-mdpi', 'ic_launcher.png')] = 'res/icon/android/mdpi-foreground.png'; phaseTwoModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_background.png')] = 'res/icon/android/mdpi-background.png'; - let phaseTwoUpdatedIconsForLegacy = Object.assign({}, phaseOneUpdatedIconsForAdaptive, phaseTwoModification); + const phaseTwoUpdatedIconsForLegacy = Object.assign({}, phaseOneUpdatedIconsForAdaptive, phaseTwoModification); updateIconResourceForLegacySpy = jasmine.createSpy('updateIconResourceForLegacySpy'); prepare.__set__('updateIconResourceForLegacy', function (preparedIcons, resourceMap, platformResourcesDir) { @@ -369,8 +369,8 @@ describe('updateIcons method', function () { expect(emitSpy).toHaveBeenCalled(); // The emit message was. - let actual = emitSpy.calls.argsFor(0)[1]; - let expected = 'Updating icons at ' + PATH_RESOURCE; + const actual = emitSpy.calls.argsFor(0)[1]; + const expected = 'Updating icons at ' + PATH_RESOURCE; expect(actual).toEqual(expected); // Expected to be called. @@ -378,8 +378,8 @@ describe('updateIcons method', function () { expect(updateIconResourceForAdaptiveSpy).toHaveBeenCalled(); expect(updateIconResourceForLegacySpy).toHaveBeenCalled(); - let actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; - let expectedResourceMap = phaseTwoUpdatedIconsForLegacy; + const actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; + const expectedResourceMap = phaseTwoUpdatedIconsForLegacy; expect(actualResourceMap).toEqual(expectedResourceMap); }); @@ -397,11 +397,11 @@ describe('updateIcons method', function () { }; // Creating Spies - let resourceMap = createResourceMap(); - let phaseOneModification = {}; + const resourceMap = createResourceMap(); + const phaseOneModification = {}; phaseOneModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_foreground.png')] = 'res/icon/android/mdpi-foreground.png'; phaseOneModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_background.png')] = 'res/icon/android/mdpi-background.png'; - let phaseOneUpdatedIconsForAdaptive = Object.assign({}, resourceMap, phaseOneModification); + const phaseOneUpdatedIconsForAdaptive = Object.assign({}, resourceMap, phaseOneModification); updateIconResourceForAdaptiveSpy = jasmine.createSpy('updateIconResourceForAdaptiveSpy'); prepare.__set__('updateIconResourceForAdaptive', function (preparedIcons, resourceMap, platformResourcesDir) { @@ -409,10 +409,10 @@ describe('updateIcons method', function () { return phaseOneUpdatedIconsForAdaptive; }); - let phaseTwoModification = {}; + const phaseTwoModification = {}; phaseTwoModification[path.join(PATH_RESOURCE, 'mipmap-mdpi', 'ic_launcher.png')] = 'res/icon/android/mdpi-foreground.png'; phaseTwoModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_background.png')] = 'res/icon/android/mdpi-background.png'; - let phaseTwoUpdatedIconsForLegacy = Object.assign({}, phaseOneUpdatedIconsForAdaptive, phaseTwoModification); + const phaseTwoUpdatedIconsForLegacy = Object.assign({}, phaseOneUpdatedIconsForAdaptive, phaseTwoModification); updateIconResourceForLegacySpy = jasmine.createSpy('updateIconResourceForLegacySpy'); prepare.__set__('updateIconResourceForLegacy', function (preparedIcons, resourceMap, platformResourcesDir) { @@ -426,8 +426,8 @@ describe('updateIcons method', function () { expect(emitSpy).toHaveBeenCalled(); // The emit message was. - let actual = emitSpy.calls.argsFor(0)[1]; - let expected = 'Updating icons at ' + PATH_RESOURCE; + const actual = emitSpy.calls.argsFor(0)[1]; + const expected = 'Updating icons at ' + PATH_RESOURCE; expect(actual).toEqual(expected); // Expected to be called. @@ -435,8 +435,8 @@ describe('updateIcons method', function () { expect(updateIconResourceForAdaptiveSpy).toHaveBeenCalled(); expect(updateIconResourceForLegacySpy).toHaveBeenCalled(); - let actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; - let expectedResourceMap = phaseTwoUpdatedIconsForLegacy; + const actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; + const expectedResourceMap = phaseTwoUpdatedIconsForLegacy; expect(actualResourceMap).toEqual(expectedResourceMap); }); @@ -452,7 +452,7 @@ describe('updateIcons method', function () { }; // Creating Spies - let phaseOneUpdatedIconsForAdaptive = createResourceMap(); + const phaseOneUpdatedIconsForAdaptive = createResourceMap(); updateIconResourceForAdaptiveSpy = jasmine.createSpy('updateIconResourceForAdaptiveSpy'); prepare.__set__('updateIconResourceForAdaptive', function (preparedIcons, resourceMap, platformResourcesDir) { @@ -460,9 +460,9 @@ describe('updateIcons method', function () { return phaseOneUpdatedIconsForAdaptive; }); - let phaseTwoModification = {}; + const phaseTwoModification = {}; phaseTwoModification[path.join(PATH_RESOURCE, 'mipmap-mdpi', 'ic_launcher.png')] = 'res/icon/android/mdpi-icon.png'; - let phaseTwoUpdatedIconsForLegacy = Object.assign({}, phaseOneUpdatedIconsForAdaptive, phaseTwoModification); + const phaseTwoUpdatedIconsForLegacy = Object.assign({}, phaseOneUpdatedIconsForAdaptive, phaseTwoModification); updateIconResourceForLegacySpy = jasmine.createSpy('updateIconResourceForLegacySpy'); prepare.__set__('updateIconResourceForLegacy', function (preparedIcons, resourceMap, platformResourcesDir) { @@ -476,8 +476,8 @@ describe('updateIcons method', function () { expect(emitSpy).toHaveBeenCalled(); // The emit message was. - let actual = emitSpy.calls.argsFor(0)[1]; - let expected = 'Updating icons at ' + PATH_RESOURCE; + const actual = emitSpy.calls.argsFor(0)[1]; + const expected = 'Updating icons at ' + PATH_RESOURCE; expect(actual).toEqual(expected); // Expected to be called. @@ -485,8 +485,8 @@ describe('updateIcons method', function () { expect(updateIconResourceForAdaptiveSpy).not.toHaveBeenCalled(); expect(updateIconResourceForLegacySpy).toHaveBeenCalled(); - let actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; - let expectedResourceMap = phaseTwoUpdatedIconsForLegacy; + const actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; + const expectedResourceMap = phaseTwoUpdatedIconsForLegacy; expect(actualResourceMap).toEqual(expectedResourceMap); }); }); @@ -510,50 +510,48 @@ describe('prepareIcons method', function () { it('Test#001 : should emit extra default icon found for adaptive use case.', function () { // mock data. - let ldpi = mockGetIconItem({ + const ldpi = mockGetIconItem({ density: 'ldpi', background: 'res/icon/android/ldpi-background.png', foreground: 'res/icon/android/ldpi-foreground.png' }); - let mdpi = mockGetIconItem({ + const mdpi = mockGetIconItem({ density: 'mdpi', background: 'res/icon/android/mdpi-background.png', foreground: 'res/icon/android/mdpi-foreground.png' }); - let icons = [ldpi, mdpi]; - let actual = prepareIcons(icons); - let expected = { + const icons = [ldpi, mdpi]; + const actual = prepareIcons(icons); + const expected = { android_icons: { ldpi, mdpi }, default_icon: undefined }; expect(expected).toEqual(actual); - }); it('Test#002 : should emit extra default icon found for legacy use case.', function () { // mock data. - let ldpi = mockGetIconItem({ + const ldpi = mockGetIconItem({ src: 'res/icon/android/ldpi-icon.png', density: 'ldpi' }); - let mdpi = mockGetIconItem({ + const mdpi = mockGetIconItem({ src: 'res/icon/android/mdpi-icon.png', density: 'mdpi' }); - let icons = [ldpi, mdpi]; - let actual = prepareIcons(icons); - let expected = { + const icons = [ldpi, mdpi]; + const actual = prepareIcons(icons); + const expected = { android_icons: { ldpi, mdpi }, default_icon: undefined }; expect(expected).toEqual(actual); - }); }); @@ -596,13 +594,12 @@ describe('updateIconResourceForLegacy method', function () { const updateIconResourceForLegacy = prepare.__get__('updateIconResourceForLegacy'); // Run Test - let expectedModification = {}; + const expectedModification = {}; expectedModification[path.join(PATH_RESOURCE, 'mipmap-mdpi', 'ic_launcher.png')] = 'res/icon/android/mdpi-icon.png'; - let expected = Object.assign({}, resourceMap, expectedModification); - let actual = updateIconResourceForLegacy(preparedIcons, resourceMap, platformResourcesDir); + const expected = Object.assign({}, resourceMap, expectedModification); + const actual = updateIconResourceForLegacy(preparedIcons, resourceMap, platformResourcesDir); expect(actual).toEqual(expected); - }); }); @@ -646,15 +643,14 @@ describe('updateIconResourceForAdaptive method', function () { const updateIconResourceForAdaptive = prepare.__get__('updateIconResourceForAdaptive'); // Run Test - let expectedModification = {}; + const expectedModification = {}; expectedModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_background.png')] = 'res/icon/android/mdpi-background.png'; expectedModification[path.join(PATH_RESOURCE, 'mipmap-mdpi-v26', 'ic_launcher_foreground.png')] = 'res/icon/android/mdpi-foreground.png'; - let expected = Object.assign({}, resourceMap, expectedModification); - let actual = updateIconResourceForAdaptive(preparedIcons, resourceMap, platformResourcesDir); + const expected = Object.assign({}, resourceMap, expectedModification); + const actual = updateIconResourceForAdaptive(preparedIcons, resourceMap, platformResourcesDir); expect(actual).toEqual(expected); - }); }); @@ -679,36 +675,36 @@ describe('cleanIcons method', function () { it('Test#001 : should detect that the app does not have defined icons.', function () { // Mock - let icons = []; - let projectRoot = '/mock'; - let projectConfig = { + const icons = []; + const projectRoot = '/mock'; + const projectConfig = { getIcons: function () { return icons; }, path: '/mock/config.xml', cdvNamespacePrefix: 'cdv' }; - let platformResourcesDir = PATH_RESOURCE; + const platformResourcesDir = PATH_RESOURCE; const cleanIcons = prepare.__get__('cleanIcons'); cleanIcons(projectRoot, projectConfig, platformResourcesDir); - let actualEmitMessage = emitSpy.calls.argsFor(0)[1]; + const actualEmitMessage = emitSpy.calls.argsFor(0)[1]; expect(actualEmitMessage).toContain('This app does not have launcher icons defined'); }); it('Test#002 : Should clean paths for adaptive icons.', function () { // Mock - let icons = [mockGetIconItem({ + const icons = [mockGetIconItem({ density: 'mdpi', background: 'res/icon/android/mdpi-background.png', foreground: 'res/icon/android/mdpi-foreground.png' })]; - let projectRoot = '/mock'; - let projectConfig = { + const projectRoot = '/mock'; + const projectConfig = { getIcons: function () { return icons; }, path: '/mock/config.xml', cdvNamespacePrefix: 'cdv' }; - let platformResourcesDir = PATH_RESOURCE; + const platformResourcesDir = PATH_RESOURCE; var expectedResourceMapBackground = createResourceMap('ic_launcher_background.png'); @@ -722,24 +718,24 @@ describe('cleanIcons method', function () { const cleanIcons = prepare.__get__('cleanIcons'); cleanIcons(projectRoot, projectConfig, platformResourcesDir); - let actualResourceMapBackground = updatePathsSpy.calls.argsFor(0)[0]; + const actualResourceMapBackground = updatePathsSpy.calls.argsFor(0)[0]; expect(actualResourceMapBackground).toEqual(expectedResourceMapBackground); }); it('Test#003 : Should clean paths for legacy icons.', function () { // Mock - let icons = [mockGetIconItem({ + const icons = [mockGetIconItem({ src: 'res/icon/android/mdpi.png', density: 'mdpi' })]; - let projectRoot = '/mock'; - let projectConfig = { + const projectRoot = '/mock'; + const projectConfig = { getIcons: function () { return icons; }, path: '/mock/config.xml', cdvNamespacePrefix: 'cdv' }; - let platformResourcesDir = PATH_RESOURCE; + const platformResourcesDir = PATH_RESOURCE; var expectedResourceMap = createResourceMap(); @@ -751,7 +747,7 @@ describe('cleanIcons method', function () { const cleanIcons = prepare.__get__('cleanIcons'); cleanIcons(projectRoot, projectConfig, platformResourcesDir); - let actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; + const actualResourceMap = updatePathsSpy.calls.argsFor(0)[0]; expect(actualResourceMap).toEqual(expectedResourceMap); }); });