From 022ce59a7ab9258116d7389065a220d188410728 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 9 Jun 2015 22:34:54 +0200 Subject: [PATCH] refactor: Cleanup and move to standard JS. --- .eslintrc | 3 + .jscs.json | 117 ---------------------------------- Gruntfile.coffee | 101 ------------------------------ README.md | 20 +++--- gruntfile.js | 54 ++++++++++++++++ index.js | 128 +++++++++++++++++++++----------------- package.json | 35 ++++++----- test/launcher.spec.coffee | 6 +- 8 files changed, 159 insertions(+), 305 deletions(-) create mode 100644 .eslintrc delete mode 100644 .jscs.json delete mode 100644 Gruntfile.coffee create mode 100644 gruntfile.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..7d03cee --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "standard" +} \ No newline at end of file diff --git a/.jscs.json b/.jscs.json deleted file mode 100644 index f223181..0000000 --- a/.jscs.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "return", - "try", - "catch" - ], - "disallowSpaceAfterKeywords": [], - "requireParenthesesAroundIIFE": true, - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "disallowSpacesInFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "disallowSpacesInFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "requireBlocksOnNewline": true, - "disallowEmptyBlocks": true, - "disallowSpacesInsideObjectBrackets": true, - "disallowSpacesInsideArrayBrackets": true, - "disallowSpaceAfterObjectKeys": true, - "requireCommaBeforeLineBreak": true, - "disallowLeftStickedOperators": [ - "?", - "+", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==", - ">", - ">=", - "<", - "<=" - ], - "requireRightStickedOperators": ["!"], - "disallowRightStickedOperators": [ - "?", - "+", - "/", - "*", - ":", - "=", - "==", - "===", - "!=", - "!==", - ">", - ">=", - "<", - "<=" - ], - "requireLeftStickedOperators": [","], - "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], - "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], - "requireSpaceBeforeBinaryOperators": [ - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==" - ], - "requireSpaceAfterBinaryOperators": [ - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==" - ], - "requireCamelCaseOrUpperCaseIdentifiers": true, - "disallowKeywords": ["with"], - "disallowMultipleLineStrings": true, - "validateLineBreaks": "LF", - "validateQuoteMarks": { - "mark": "'", - "escape": true - }, - "disallowMixedSpacesAndTabs": true, - "disallowTrailingWhitespace": true, - "disallowKeywordsOnNewLine": ["else"], - "requireLineFeedAtFileEnd": true, - "maximumLineLength": 100, - "requireCapitalizedConstructors": true, - "requireDotNotation": true, - "disallowSpacesInsideParentheses" : true - - -} diff --git a/Gruntfile.coffee b/Gruntfile.coffee deleted file mode 100644 index 58721bc..0000000 --- a/Gruntfile.coffee +++ /dev/null @@ -1,101 +0,0 @@ -JSHINT_NODE = - node: true, - strict: false - -module.exports = (grunt) -> - - allSrc = ['index.js'] - allTests = ['test/mocha-globals.coffee', 'test/*.spec.coffee'] - all = [].concat(allSrc).concat(allTests).concat(['Gruntfile.coffee']) - - # Project configuration. - grunt.initConfig - pkgFile: 'package.json' - - 'npm-contributors': - options: - commitMessage: 'chore: update contributors' - - bump: - options: - commitMessage: 'chore: release v%VERSION%' - pushTo: 'upstream' - - 'auto-release': - options: - checkTravisBuild: false - - # JSHint options - # http://www.jshint.com/options/ - jshint: - default: - files: - src: allSrc - options: JSHINT_NODE - - options: - quotmark: 'single' - bitwise: true - freeze: true - indent: 2 - camelcase: true - strict: true - trailing: true - curly: true - eqeqeq: true - immed: true - latedef: true - newcap: true - noempty: true - unused: true - noarg: true - sub: true - undef: true - maxdepth: 4 - maxstatements: 100 - maxcomplexity: 100 - maxlen: 100 - globals: {} - - jscs: - default: files: src: allSrc - options: - config: '.jscs.json' - - simplemocha: - options: - ui: 'bdd' - reporter: 'dot' - unit: - src: allTests - - watch: - files: all - tasks:['default'] - - # CoffeeLint options - # http://www.coffeelint.org/#options - coffeelint: - unittests: files: src: ['Gruntfile.coffee', 'test/**/*.coffee'] - options: - max_line_length: - value: 100 - - grunt.loadNpmTasks 'grunt-contrib-watch' - grunt.loadNpmTasks 'grunt-npm' - grunt.loadNpmTasks 'grunt-bump' - grunt.loadNpmTasks 'grunt-auto-release' - grunt.loadNpmTasks 'grunt-contrib-jshint' - grunt.loadNpmTasks 'grunt-jscs-checker' - grunt.loadNpmTasks 'grunt-simple-mocha' - grunt.loadNpmTasks 'grunt-coffeelint' - - grunt.registerTask 'release', 'Bump the version and publish to NPM.', (type) -> - grunt.task.run [ - 'npm-contributors', - "bump:#{type||'patch'}", - 'npm-publish' - ] - grunt.registerTask 'test', ['simplemocha'] - grunt.registerTask 'default', ['lint', 'test'] - grunt.registerTask 'lint', ['jshint', 'jscs', 'coffeelint'] diff --git a/README.md b/README.md index 4528e90..91f566f 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,16 @@ -# karma-ie-launcher [![Build Status](https://travis-ci.org/karma-runner/karma-ie-launcher.svg?branch=master)](http://travis-ci.org/karma-runner/karma-ie-launcher) +# karma-ie-launcher + +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/karma-runner/karma-ie-launcher) + [![npm version](https://img.shields.io/npm/v/karma-ie-launcher.svg?style=flat-square)](https://www.npmjs.com/package/karma-ie-launcher) [![npm downloads](https://img.shields.io/npm/dm/karma-ie-launcher.svg?style=flat-square)](https://www.npmjs.com/package/karma-ie-launcher) + +[![Build Status](https://img.shields.io/travis/karma-runner/karma-ie-launcher/master.svg?style=flat-square)](https://travis-ci.org/karma-runner/karma-ie-launcher) [![Dependency Status](https://img.shields.io/david/karma-runner/karma-ie-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-ie-launcher) [![devDependency Status](https://img.shields.io/david/dev/karma-runner/karma-ie-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-ie-launcher#info=devDependencies) > Launcher for Internet Explorer. ## Installation -The easiest way is to keep `karma-ie-launcher` as a devDependency in your `package.json`. -```json -{ - "devDependencies": { - "karma": "~0.10", - "karma-ie-launcher": "~0.1" - } -} -``` +The easiest way is to keep `karma-ie-launcher` as a devDependency, by running -You can simply do it by: ```bash npm install karma-ie-launcher --save-dev ``` @@ -76,4 +72,4 @@ For more information on Karma see the [homepage]. [homepage]: http://karma-runner.github.com [Specifying legacy document modes]: http://msdn.microsoft.com/en-us/library/ie/jj676915(v=vs.85).aspx -[IE Command-Line Options]: https://msdn.microsoft.com/en-us/library/hh826025(v=vs.85).aspx \ No newline at end of file +[IE Command-Line Options]: https://msdn.microsoft.com/en-us/library/hh826025(v=vs.85).aspx diff --git a/gruntfile.js b/gruntfile.js new file mode 100644 index 0000000..daeb6a7 --- /dev/null +++ b/gruntfile.js @@ -0,0 +1,54 @@ +module.exports = function (grunt) { + grunt.initConfig({ + pkgFile: 'package.json', + simplemocha: { + options: { + ui: 'bdd', + reporter: 'dot' + }, + unit: { + src: [ + 'test/mocha-globals.coffee', + 'test/*.spec.coffee' + ] + } + }, + 'npm-contributors': { + options: { + commitMessage: 'chore: update contributors' + } + }, + bump: { + options: { + commitMessage: 'chore: release v%VERSION%', + pushTo: 'upstream', + commitFiles: [ + 'package.json', + 'CHANGELOG.md' + ] + } + }, + eslint: { + target: [ + 'index.js', + 'gruntfile.js', + 'karma.conf.js' + ] + } + }) + + require('load-grunt-tasks')(grunt) + + grunt.registerTask('test', ['simplemocha']) + grunt.registerTask('default', ['eslint', 'test']) + + grunt.registerTask('release', 'Bump the version and publish to NPM.', function (type) { + grunt.task.run([ + 'npm-contributors', + 'bump-only:' + (type || 'patch'), + 'changelog', + 'bump-commit', + 'npm-publish' + ]) + }) +} diff --git a/index.js b/index.js index 1d8ab56..ccfcaac 100644 --- a/index.js +++ b/index.js @@ -1,30 +1,42 @@ -var fs = require('fs'); -var urlparse = require('url').parse; -var urlformat = require('url').format; -var exec = require('child_process').exec; - -var processName = 'iexplore.exe'; - -function getInternetExplorerExe() { - var suffix = '\\Internet Explorer\\' + processName, - prefixes = [process.env['' + 'PROGRAMW6432'], // '' + ' trick to keep jscs happy - process.env['' + 'PROGRAMFILES(X86)'], - process.env['' + 'PROGRAMFILES']], - prefix, i; - - for (i = 0; i < prefixes.length; i++) { - prefix = prefixes[i]; - if (prefix && fs.existsSync(prefix + suffix)) { - return prefix + suffix; - } - } +// Karme IE Launcher +// ================= + +// Dependencies +// ------------ + +var fs = require('fs') +var urlparse = require('url').parse +var urlformat = require('url').format +var exec = require('child_process').exec +var _ = require('lodash') + +// Constants +// --------- + +var PROCESS_NAME = 'iexplore.exe' + +// Find the ie executable +function getInternetExplorerExe () { + var suffix = '\\Internet Explorer\\' + PROCESS_NAME + var locations = _.map(_.compact([ + process.env['PROGRAMW6432'], + process.env['PROGRAMFILES(X86)'], + process.env['PROGRAMFILES'] + ]), function (prefix) { + return prefix + suffix + }) + + return _.find(locations, function (location) { + return fs.existsSync(location) + }) } -var IEBrowser = function(baseBrowserDecorator, logger, args) { - baseBrowserDecorator(this); +// Constructor +function IEBrowser (baseBrowserDecorator, logger, args) { + baseBrowserDecorator(this) - var log = logger.create('launcher'); - var flags = args.flags || []; + var log = logger.create('launcher') + var flags = args.flags || [] // Handle x-ua-compatible option: // @@ -39,9 +51,9 @@ var IEBrowser = function(baseBrowserDecorator, logger, args) { // This is done by passing the option on the url, in response the Karma server will // set the following meta in the page. // - function handleXUaCompatible(args, urlObj) { + function handleXUaCompatible (args, urlObj) { if (args['x-ua-compatible']) { - urlObj.query['x-ua-compatible'] = args['x-ua-compatible']; + urlObj.query['x-ua-compatible'] = args['x-ua-compatible'] } } @@ -54,50 +66,50 @@ var IEBrowser = function(baseBrowserDecorator, logger, args) { // // This function kills any iexplore.exe process who's command line args match 'SCODEF:pid'. // On IE11 this will kill the extra process. On older versions, no process will be found. - function killExtraIEProcess(pid, cb) { - - var scodef = 'SCODEF:' + pid; + function killExtraIEProcess (pid, cb) { + var scodef = 'SCODEF:' + pid - //wmic.exe : http://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx + // wmic.exe : http://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx var wmic = 'wmic.exe Path win32_Process ' + - 'where "Name=\'' + processName + '\' and ' + - 'CommandLine Like \'%' + scodef + '%\'" call Terminate'; + 'where "Name=\'' + PROCESS_NAME + "' and " + + "CommandLine Like '%" + scodef + '%\'" call Terminate' - exec(wmic, function(err) { + exec(wmic, function (err) { if (err) { - log.error('Killing extra IE process failed. ' + err); + log.error('Killing extra IE process failed. ' + err) } else { - log.debug('Killed extra IE process ' + pid); + log.debug('Killed extra IE process ' + pid) } - cb(); - }); + cb() + }) } - this._getOptions = function(url) { - var urlObj = urlparse(url, true); + this._getOptions = function (url) { + var urlObj = urlparse(url, true) - handleXUaCompatible(args, urlObj); + handleXUaCompatible(args, urlObj) - delete urlObj.search; //url.format does not want search attribute - url = urlformat(urlObj); + // url.format does not want search attribute + delete urlObj.search + url = urlformat(urlObj) - return flags.concat(url); - }; + return flags.concat(url) + } - var baseOnProcessExit = this._onProcessExit; - this._onProcessExit = function(code, errorOutput) { - var pid = this._process.pid; - killExtraIEProcess(pid, function() { + var baseOnProcessExit = this._onProcessExit + this._onProcessExit = function (code, errorOutput) { + var pid = this._process.pid + killExtraIEProcess(pid, function () { if (baseOnProcessExit) { - baseOnProcessExit(code, errorOutput); + baseOnProcessExit(code, errorOutput) } - }); - }; + }) + } // this is to expose the function for unit testing - this._getInternetExplorerExe = getInternetExplorerExe; -}; + this._getInternetExplorerExe = getInternetExplorerExe +} IEBrowser.prototype = { name: 'IE', @@ -105,11 +117,13 @@ IEBrowser.prototype = { win32: getInternetExplorerExe() }, ENV_CMD: 'IE_BIN' -}; +} -IEBrowser.$inject = ['baseBrowserDecorator', 'logger', 'args']; +IEBrowser.$inject = ['baseBrowserDecorator', 'logger', 'args'] + +// Publish di module +// ----------------- -// PUBLISH DI MODULE module.exports = { 'launcher:IE': ['type', IEBrowser] -}; +} diff --git a/package.json b/package.json index d6eb0b5..5912a79 100644 --- a/package.json +++ b/package.json @@ -16,27 +16,32 @@ "ie" ], "author": "Vojta Jina ", - "dependencies": {}, + "dependencies": { + "lodash": "^3.9.3" + }, "peerDependencies": { "karma": ">=0.9" }, "license": "MIT", "devDependencies": { - "grunt": "~0.4.1", - "grunt-simple-mocha": "~0.4.0", - "grunt-bump": "~0.0.7", - "grunt-npm": "~0.0.2", - "grunt-auto-release": "~0.0.2", - "grunt-contrib-jshint": "~0.7.2", - "grunt-jscs-checker": "~0.4.0", + "chai": "^2.3.0", + "di": "^0.0.1", + "eslint": "^0.22.1", + "eslint-config-standard": "^2.0.1", + "eslint-plugin-react": "^2.5.0", + "grunt": "^0.4.1", + "grunt-auto-release": "^0.0.2", + "grunt-bump": "^0.3.1", + "grunt-contrib-watch": "^0.6.1", + "grunt-conventional-changelog": "^1.2.2", + "grunt-eslint": "^14.0.0", + "grunt-npm": "^0.0.2", + "grunt-simple-mocha": "^0.4.0", + "karma": "^0.12.0", + "load-grunt-tasks": "^3.2.0", "mocks": "0.0.11", - "sinon": "~1.7.3", - "chai": "~1.7.2", - "sinon-chai": "~2.4.0", - "grunt-coffeelint": "~0.0.6", - "karma": "~0.12.0", - "di": "~0.0.1", - "grunt-contrib-watch" : "~0.6.1" + "sinon": "^1.14.1", + "sinon-chai": "^2.8.0" }, "contributors": [ "sylvain-hamel ", diff --git a/test/launcher.spec.coffee b/test/launcher.spec.coffee index e7550c8..810e197 100644 --- a/test/launcher.spec.coffee +++ b/test/launcher.spec.coffee @@ -87,9 +87,9 @@ describe 'launcher', -> fsMock = null beforeEach -> - process.env['' + 'PROGRAMW6432'] = '\\fake\\PROGRAMW6432' - process.env['' + 'PROGRAMFILES(X86)'] = '\\fake\\PROGRAMFILES(X86)' - process.env['' + 'PROGRAMFILES'] = '\\fake\\PROGRAMFILES' + process.env['PROGRAMW6432'] = '\\fake\\PROGRAMW6432' + process.env['PROGRAMFILES(X86)'] = '\\fake\\PROGRAMFILES(X86)' + process.env['PROGRAMFILES'] = '\\fake\\PROGRAMFILES' fsMock = mocks.fs.create 'folder1':