Skip to content

Commit

Permalink
refactor: unify style of functions declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
lusarz committed Jun 14, 2018
1 parent 5272aa3 commit 0dc8ea4
Show file tree
Hide file tree
Showing 32 changed files with 61 additions and 60 deletions.
6 changes: 3 additions & 3 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var stringify = require('../common/stringify')
var constant = require('./constants')
var util = require('../common/util')

var Karma = function (socket, iframe, opener, navigator, location) {
function Karma (socket, iframe, opener, navigator, location) {
var startEmitted = false
var reloadingContext = false
var self = this
Expand Down Expand Up @@ -47,7 +47,7 @@ var Karma = function (socket, iframe, opener, navigator, location) {
}

var childWindow = null
var navigateContextTo = function (url) {
function navigateContextTo (url) {
if (self.config.useIframe === false) {
// run in new window
if (self.config.runInParent === false) {
Expand Down Expand Up @@ -98,7 +98,7 @@ var Karma = function (socket, iframe, opener, navigator, location) {

this.stringify = stringify

var clearContext = function () {
function clearContext () {
reloadingContext = true

navigateContextTo('about:blank')
Expand Down
6 changes: 3 additions & 3 deletions client/updater.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var VERSION = require('./constants').VERSION

var StatusUpdater = function (socket, titleElement, bannerElement, browsersElement) {
var updateBrowsersInfo = function (browsers) {
function StatusUpdater (socket, titleElement, bannerElement, browsersElement) {
function updateBrowsersInfo (browsers) {
if (!browsersElement) {
return
}
Expand All @@ -14,7 +14,7 @@ var StatusUpdater = function (socket, titleElement, bannerElement, browsersEleme
browsersElement.innerHTML = items.join('\n')
}

var updateBanner = function (status) {
function updateBanner (status) {
return function (param) {
if (!titleElement || !bannerElement) {
return
Expand Down
5 changes: 3 additions & 2 deletions common/stringify.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
var serialize = require('dom-serialize')
var instanceOf = require('./util').instanceOf
var isNode = function (obj) {

function isNode (obj) {
return (obj.tagName || obj.nodeName) && obj.nodeType
}

var stringify = function stringify (obj, depth) {
function stringify (obj, depth) {
if (depth === 0) {
return '...'
}
Expand Down
6 changes: 3 additions & 3 deletions context/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var stringify = require('../common/stringify')

// Define our context Karma constructor
var ContextKarma = function (callParentKarmaMethod) {
function ContextKarma (callParentKarmaMethod) {
// Define local variables
var hasError = false
var self = this
Expand Down Expand Up @@ -30,7 +30,7 @@ var ContextKarma = function (callParentKarmaMethod) {
}

// Define our start handler
var UNIMPLEMENTED_START = function () {
function UNIMPLEMENTED_START () {
this.error('You need to include some adapter that implements __karma__.start method!')
}
// all files loaded, let's start the execution
Expand Down Expand Up @@ -98,7 +98,7 @@ var ContextKarma = function (callParentKarmaMethod) {
}

// If we want to overload our console, then do it
var getConsole = function (currentWindow) {
function getConsole (currentWindow) {
return currentWindow.console || {
log: function () {},
info: function () {},
Expand Down
2 changes: 1 addition & 1 deletion docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ The plugin must provide an express/connect middleware function (details about th

**Example:**
```javascript
var CustomMiddlewareFactory = function (config) {
function CustomMiddlewareFactory (config) {
return function (request, response, /* next */) {
response.writeHead(200)
return response.end("content!")
Expand Down
2 changes: 1 addition & 1 deletion lib/launchers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var BEING_FORCE_KILLED = 6
/**
* Base launcher that any custom launcher extends.
*/
var BaseLauncher = function (id, emitter) {
function BaseLauncher (id, emitter) {
if (this.start) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion lib/launchers/capture_timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var log = require('../logger').create('launcher')
/**
* Kill browser if it does not capture in given `captureTimeout`.
*/
var CaptureTimeoutLauncher = function (timer, captureTimeout) {
function CaptureTimeoutLauncher (timer, captureTimeout) {
if (!captureTimeout) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions lib/launchers/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var path = require('path')
var log = require('../logger').create('launcher')
var env = process.env

var ProcessLauncher = function (spawn, tempDir, timer, processKillTimeout) {
function ProcessLauncher (spawn, tempDir, timer, processKillTimeout) {
var self = this
var onExitCallback
var killTimeout = processKillTimeout || 2000
Expand Down Expand Up @@ -164,7 +164,7 @@ ProcessLauncher.decoratorFactory = function (timer) {
return function (launcher, processKillTimeout) {
var spawn = require('child_process').spawn

var spawnWithoutOutput = function () {
function spawnWithoutOutput () {
var proc = spawn.apply(null, arguments)
proc.stdout.resume()
proc.stderr.resume()
Expand Down
2 changes: 1 addition & 1 deletion lib/launchers/retry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var log = require('../logger').create('launcher')

var RetryLauncher = function (retryLimit) {
function RetryLauncher (retryLimit) {
var self = this

this._retryLimit = retryLimit
Expand Down
6 changes: 3 additions & 3 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var constant = require('./constants')
// to allow for fine grained configuration of log4js. For more information
// see https://github.com/nomiddlename/log4js-node.
// *Array* is also accepted for backwards compatibility.
var setup = function (level, colors, appenders) {
function setup (level, colors, appenders) {
// Turn color on/off on the console appenders with pattern layout
var pattern = colors ? constant.COLOR_PATTERN : constant.NO_COLOR_PATTERN
if (appenders) {
Expand Down Expand Up @@ -69,7 +69,7 @@ var setup = function (level, colors, appenders) {
// to allow for fine grained configuration of log4js. For more information
// see https://github.com/nomiddlename/log4js-node.
// *Array* is also accepted for backwards compatibility.
var setupFromConfig = function (config, appenders) {
function setupFromConfig (config, appenders) {
var useColors = true
var logLevel = constant.LOG_INFO

Expand All @@ -90,7 +90,7 @@ const loggerCache = {}
// If the `name = 'socket.io'` this will create a special wrapper
// to be used as a logger for socket.io.
// * `level`, which defaults to the global level.
var create = function (name, level) {
function create (name, level) {
name = name || 'karma'
var logger
if (loggerCache.hasOwnProperty(name)) {
Expand Down
10 changes: 5 additions & 5 deletions lib/middleware/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _ = require('lodash')

var log = require('../logger').create('middleware:karma')

var urlparse = function (urlStr) {
function urlparse (urlStr) {
var urlObj = url.parse(urlStr, true)
urlObj.query = urlObj.query || {}
return urlObj
Expand All @@ -44,15 +44,15 @@ var FILE_TYPES = [
'module'
]

var filePathToUrlPath = function (filePath, basePath, urlRoot, proxyPath) {
function filePathToUrlPath (filePath, basePath, urlRoot, proxyPath) {
if (filePath.indexOf(basePath) === 0) {
return proxyPath + urlRoot.substr(1) + 'base' + filePath.substr(basePath.length)
}

return proxyPath + urlRoot.substr(1) + 'absolute' + filePath
}

var getXUACompatibleMetaElement = function (url) {
function getXUACompatibleMetaElement (url) {
var tag = ''
var urlObj = urlparse(url)
if (urlObj.query['x-ua-compatible']) {
Expand All @@ -62,7 +62,7 @@ var getXUACompatibleMetaElement = function (url) {
return tag
}

var getXUACompatibleUrl = function (url) {
function getXUACompatibleUrl (url) {
var value = ''
var urlObj = urlparse(url)
if (urlObj.query['x-ua-compatible']) {
Expand All @@ -71,7 +71,7 @@ var getXUACompatibleUrl = function (url) {
return value
}

var createKarmaMiddleware = function (
function createKarmaMiddleware (
filesPromise,
serveStaticFile,
serveFile,
Expand Down
14 changes: 7 additions & 7 deletions lib/middleware/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var _ = require('lodash')

var log = require('../logger').create('proxy')

var parseProxyConfig = function (proxies, config) {
var endsWithSlash = function (str) {
function parseProxyConfig (proxies, config) {
function endsWithSlash (str) {
return str.substr(-1) === '/'
}

Expand Down Expand Up @@ -96,16 +96,16 @@ var parseProxyConfig = function (proxies, config) {
* @param urlRoot The URL root that karma is mounted on
* @return {Function} handler function
*/
var createProxyHandler = function (proxies, urlRoot) {
function createProxyHandler (proxies, urlRoot) {
if (!proxies.length) {
var nullProxy = function createNullProxy (request, response, next) {
const nullProxy = function (request, response, next) {
return next()
}
nullProxy.upgrade = function upgradeNullProxy () {}
return nullProxy
}

var middleware = function createProxy (request, response, next) {
function createProxy (request, response, next) {
var proxyRecord = _.find(proxies, function (p) {
return request.url.indexOf(p.path) === 0
})
Expand All @@ -119,7 +119,7 @@ var createProxyHandler = function (proxies, urlRoot) {
proxyRecord.proxy.web(request, response)
}

middleware.upgrade = function upgradeProxy (request, socket, head) {
createProxy.upgrade = function upgradeProxy (request, socket, head) {
// special-case karma's route to avoid upgrading it
if (request.url.indexOf(urlRoot) === 0) {
log.debug('NOT upgrading proxyWebSocketRequest %s', request.url)
Expand All @@ -140,7 +140,7 @@ var createProxyHandler = function (proxies, urlRoot) {
proxyRecord.proxy.ws(request, socket, head)
}

return middleware
return createProxy
}

exports.create = function (/* config */config, /* config.proxies */proxies) {
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var constant = require('../constants')
var json = require('body-parser').json()

// TODO(vojta): disable when single-run mode
var createRunnerMiddleware = function (emitter, fileList, capturedBrowsers, reporter, executor,
function createRunnerMiddleware (emitter, fileList, capturedBrowsers, reporter, executor,
/* config.protocol */ protocol, /* config.hostname */ hostname, /* config.port */
port, /* config.urlRoot */ urlRoot, config) {
return function (request, response, next) {
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/stopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var log = require('../logger').create('middleware:stopper')

var createStopperMiddleware = function (urlRoot) {
function createStopperMiddleware (urlRoot) {
return function (request, response, next) {
if (request.url !== urlRoot + 'stop') return next()
response.writeHead(200)
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/strip_host.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This to handle requests that uses (normally over proxies) an absoluteURI as request path
*/

var createStripHostMiddleware = function () {
function createStripHostMiddleware () {
return function (request, response, next) {
function stripHostFromUrl (url) {
return url.replace(/^http[s]?:\/\/([a-z\-.:\d]+)\//, '/')
Expand Down
8 changes: 4 additions & 4 deletions lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ var combineLists = require('combine-lists')

var log = require('./logger').create('preprocess')

var sha1 = function (data) {
function sha1 (data) {
var hash = crypto.createHash('sha1')
hash.update(data)
return hash.digest('hex')
}

var createNextProcessor = function (preprocessors, file, done) {
function createNextProcessor (preprocessors, file, done) {
return function nextPreprocessor (error, content) {
// normalize B-C
if (arguments.length === 1 && typeof error === 'string') {
Expand All @@ -37,14 +37,14 @@ var createNextProcessor = function (preprocessors, file, done) {
}
}

var createPreprocessor = function (config, basePath, injector) {
function createPreprocessor (config, basePath, injector) {
var alreadyDisplayedErrors = {}
var instances = {}
var patterns = Object.keys(config)

var emitter = injector.get('emitter')

var instantiatePreprocessor = function (name) {
function instantiatePreprocessor (name) {
if (alreadyDisplayedErrors[name]) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/base_color.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('colors')

var BaseColorReporter = function () {
function BaseColorReporter () {
this.USE_COLORS = true

this.LOG_SINGLE_BROWSER = '%s: ' + '%s'.cyan + '\n'
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/dots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var BaseReporter = require('./base')

var DotsReporter = function (formatError, reportSlow, useColors, browserConsoleLogOptions) {
function DotsReporter (formatError, reportSlow, useColors, browserConsoleLogOptions) {
BaseReporter.call(this, formatError, reportSlow, useColors, browserConsoleLogOptions)

var DOTS_WRAP = 80
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/dots_color.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var DotsReporter = require('./dots')
var BaseColorReporter = require('./base_color')

var DotsColorReporter = function (formatError, reportSlow, useColors, browserConsoleLogOptions) {
function DotsColorReporter (formatError, reportSlow, useColors, browserConsoleLogOptions) {
DotsReporter.call(this, formatError, reportSlow, useColors, browserConsoleLogOptions)
BaseColorReporter.call(this)
this.EXCLUSIVELY_USE_COLORS = true
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/progress.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var BaseReporter = require('./base')

var ProgressReporter = function (formatError, reportSlow, useColors, browserConsoleLogOptions) {
function ProgressReporter (formatError, reportSlow, useColors, browserConsoleLogOptions) {
BaseReporter.call(this, formatError, reportSlow, useColors, browserConsoleLogOptions)

this.EXCLUSIVELY_USE_COLORS = false
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/progress_color.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var ProgressReporter = require('./progress')
var BaseColorReporter = require('./base_color')

var ProgressColorReporter = function (formatError, reportSlow, useColors, browserConsoleLogOptions) {
function ProgressColorReporter (formatError, reportSlow, useColors, browserConsoleLogOptions) {
ProgressReporter.call(this, formatError, reportSlow, useColors, browserConsoleLogOptions)
BaseColorReporter.call(this)
this.EXCLUSIVELY_USE_COLORS = true
Expand Down
4 changes: 2 additions & 2 deletions tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function (grunt) {
var path = require('path')
var cmd = path.join(__dirname, '..', 'bin', 'karma')

var spawnKarma = function (args, callback) {
function spawnKarma (args, callback) {
grunt.log.writeln(['Running', cmd].concat(args).join(' '))
var child
if (process.platform === 'win32') {
Expand All @@ -24,7 +24,7 @@ module.exports = function (grunt) {
child.stderr.pipe(process.stderr)
}

var exec = function (args, failMsg) {
function exec (args, failMsg) {
spawnKarma(args, function (err, result, code) {
if (code) {
console.error(err)
Expand Down
4 changes: 2 additions & 2 deletions test/client/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var MockSocket = require('./mocks').Socket
describe('Karma', function () {
var socket, k, ck, windowNavigator, windowLocation, windowStub, startSpy, iframe, clientWindow

var setTransportTo = function (transportName) {
function setTransportTo (transportName) {
socket._setTransportNameTo(transportName)
socket.emit('connect')
}
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('Karma', function () {
})

it('should remove reference to start even after syntax error', function () {
var ADAPTER_START_FN = function () {}
function ADAPTER_START_FN () {}

ck.start = ADAPTER_START_FN
ck.error('syntax error', '/some/file.js', 11)
Expand Down
Loading

0 comments on commit 0dc8ea4

Please sign in to comment.