From 104a24a902d0500f4d8061ea3aebc06a94586ac6 Mon Sep 17 00:00:00 2001 From: Maksim Ryzhikov Date: Fri, 24 Apr 2015 01:26:52 +0300 Subject: [PATCH] chore: support wallabyjs for karma tests --- lib/launchers/capture_timeout.js | 2 ++ lib/middleware/karma.js | 3 ++ lib/middleware/proxy.js | 7 +++-- lib/middleware/runner.js | 3 ++ lib/middleware/source_files.js | 2 ++ lib/web-server.js | 2 ++ wallaby.js | 49 ++++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 wallaby.js diff --git a/lib/launchers/capture_timeout.js b/lib/launchers/capture_timeout.js index 197259483..49ff97fba 100644 --- a/lib/launchers/capture_timeout.js +++ b/lib/launchers/capture_timeout.js @@ -40,4 +40,6 @@ CaptureTimeoutLauncher.decoratorFactory = function(timer, }; }; +CaptureTimeoutLauncher.decoratorFactory.$inject = ['timer', 'config.captureTimeout']; + module.exports = CaptureTimeoutLauncher; diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 3d3cf4a0c..246502888 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -165,6 +165,9 @@ var createKarmaMiddleware = function(filesPromise, serveStaticFile, }; }; +createKarmaMiddleware.$inject = ['filesPromise', 'serveStaticFile', + 'config.basePath', 'config.urlRoot', 'config.client']; + // PUBLIC API exports.create = createKarmaMiddleware; diff --git a/lib/middleware/proxy.js b/lib/middleware/proxy.js index e439c525f..7d53ac648 100644 --- a/lib/middleware/proxy.js +++ b/lib/middleware/proxy.js @@ -122,8 +122,11 @@ var createProxyHandler = function(proxy, proxyConfig, proxyValidateSSL, urlRoot, return middleware; }; -exports.create = function(/* config */ config, /* config.proxies */ proxies, +var createProxyHandlerFactory = function(/* config */ config, /* config.proxies */ proxies, /* config.proxyValidateSSL */ validateSSL) { - return createProxyHandler(new httpProxy.RoutingProxy({changeOrigin: true}), + return createProxyHandler(new httpProxy.RoutingProxy({changeOrigin: true}), proxies, validateSSL, config.urlRoot, config); }; +createProxyHandlerFactory.$inject = ['config', 'config.proxies', 'config.proxyValidateSSL']; + +exports.create = createProxyHandlerFactory; diff --git a/lib/middleware/runner.js b/lib/middleware/runner.js index a318ce90d..b056bcc9c 100644 --- a/lib/middleware/runner.js +++ b/lib/middleware/runner.js @@ -87,6 +87,9 @@ var createRunnerMiddleware = function(emitter, fileList, capturedBrowsers, repor }; }; +createRunnerMiddleware.$inject = ['emitter', 'fileList', 'capturedBrowsers', 'reporter', 'executor', + 'config.hostname', 'config.port', 'config.urlRoot', 'config']; + // PUBLIC API exports.create = createRunnerMiddleware; diff --git a/lib/middleware/source_files.js b/lib/middleware/source_files.js index 7b46fdd9b..e20f4d16f 100644 --- a/lib/middleware/source_files.js +++ b/lib/middleware/source_files.js @@ -56,6 +56,8 @@ var createSourceFilesMiddleware = function(filesPromise, serveFile, }; }; +createSourceFilesMiddleware.$inject = ['filesPromise', 'serveFile', 'config.basePath']; + // PUBLIC API exports.create = createSourceFilesMiddleware; diff --git a/lib/web-server.js b/lib/web-server.js index 60ec64456..0d1f395de 100644 --- a/lib/web-server.js +++ b/lib/web-server.js @@ -25,6 +25,8 @@ var createCustomHandler = function(customFileHandlers, /* config.basePath */ bas }; }; +createCustomHandler.$inject = ['customFileHandlers', 'config.basePath']; + var createWebServer = function(injector, emitter) { var serveStaticFile = common.createServeFile(fs, path.normalize(__dirname + '/../static')); diff --git a/wallaby.js b/wallaby.js new file mode 100644 index 000000000..209ff7f68 --- /dev/null +++ b/wallaby.js @@ -0,0 +1,49 @@ +module.exports = function () { + return { + files: [ + { + pattern: 'package.json', + instrument: false + }, + { + pattern: 'config.tpl.js', + instrument: false + }, + 'lib/**/*.js', + 'test/unit/**/*.js', + 'test/unit/mocha-globals.coffee' + ], + + tests: [ + 'test/unit/**/*.spec.coffee' + ], + + bootstrap: function (w) { + var path = require('path'); + var mocha = w.testFramework; + + mocha.suite.on('pre-require', function () { + + // always passing wallaby.js globals to mocks.loadFile + var mocks = require('mocks'); + var loadFile = mocks.loadFile; + mocks.loadFile = function (filePath, mocks, globals, mockNested) { + mocks = mocks || {}; + globals = globals || {}; + globals.$_$wp = global.$_$wp; + globals.$_$w = global.$_$w; + globals.$_$wf = global.$_$wf; + globals.$_$tracer = global.$_$tracer; + return loadFile(filePath, mocks, globals, mockNested); + }; + + // loading mocha-globals for each run + require(path.join(process.cwd(), 'test/unit/mocha-globals')); + }); + }, + + env: { + type: 'node' + } + }; +}; \ No newline at end of file