diff options
-rw-r--r-- | app/views/layouts/_head.html.haml | 3 | ||||
-rw-r--r-- | app/views/layouts/application.html.haml | 4 | ||||
-rw-r--r-- | app/views/layouts/devise.html.haml | 3 | ||||
-rw-r--r-- | app/views/layouts/devise_empty.html.haml | 3 | ||||
-rw-r--r-- | config/webpack.config.js | 2 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | spec/javascripts/.eslintrc | 15 | ||||
-rw-r--r-- | spec/javascripts/raven/raven_config_spec.js | 70 | ||||
-rw-r--r-- | yarn.lock | 4 |
9 files changed, 86 insertions, 19 deletions
diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index f6d8bb08a64..00de3b506b4 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -28,9 +28,12 @@ = stylesheet_link_tag "application", media: "all" = stylesheet_link_tag "print", media: "print" + = Gon::Base.render_data + = javascript_include_tag(*webpack_asset_paths("runtime")) = javascript_include_tag(*webpack_asset_paths("common")) = javascript_include_tag(*webpack_asset_paths("main")) + = javascript_include_tag(*webpack_asset_paths("raven")) if sentry_enabled? - if content_for?(:page_specific_javascripts) = yield :page_specific_javascripts diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index cfd9481e4b2..4c7f0b57d16 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,12 +2,8 @@ %html{ lang: "en", class: "#{page_class}" } = render "layouts/head" %body{ class: @body_class, data: { page: body_data_page, project: "#{@project.path if @project}", group: "#{@group.path if @group}" } } - = Gon::Base.render_data - = render "layouts/header/default", title: header_title = render 'layouts/page', sidebar: sidebar, nav: nav = yield :scripts_body = render "layouts/init_auto_complete" if @gfm_form - - = javascript_include_tag(*webpack_asset_paths("raven")) if sentry_enabled? diff --git a/app/views/layouts/devise.html.haml b/app/views/layouts/devise.html.haml index 6274f6340ab..52fb46eb8c9 100644 --- a/app/views/layouts/devise.html.haml +++ b/app/views/layouts/devise.html.haml @@ -3,7 +3,6 @@ = render "layouts/head" %body.ui_charcoal.login-page.application.navless{ data: { page: body_data_page } } .page-wrap - = Gon::Base.render_data = render "layouts/header/empty" = render "layouts/broadcast" .container.navless-container @@ -35,5 +34,3 @@ = link_to "Explore", explore_root_path = link_to "Help", help_path = link_to "About GitLab", "https://about.gitlab.com/" - - = javascript_include_tag(*webpack_asset_paths("raven")) if sentry_enabled? diff --git a/app/views/layouts/devise_empty.html.haml b/app/views/layouts/devise_empty.html.haml index 120f7299fc9..ed6731bde95 100644 --- a/app/views/layouts/devise_empty.html.haml +++ b/app/views/layouts/devise_empty.html.haml @@ -2,7 +2,6 @@ %html{ lang: "en" } = render "layouts/head" %body.ui_charcoal.login-page.application.navless - = Gon::Base.render_data = render "layouts/header/empty" = render "layouts/broadcast" .container.navless-container @@ -16,5 +15,3 @@ = link_to "Explore", explore_root_path = link_to "Help", help_path = link_to "About GitLab", "https://about.gitlab.com/" - - = javascript_include_tag(*webpack_asset_paths("raven")) if sentry_enabled? diff --git a/config/webpack.config.js b/config/webpack.config.js index 62118522606..77d703e008a 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -61,7 +61,7 @@ var config = { { test: /\.js$/, exclude: /(node_modules|vendor\/assets)/, - loader: 'babel-loader' + loader: 'babel-loader?plugins=rewire' }, { test: /\.svg$/, diff --git a/package.json b/package.json index 0b24c5b8b04..d05ae8f7658 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ }, "devDependencies": { "babel-plugin-istanbul": "^4.0.0", + "babel-plugin-rewire": "^1.1.0", "eslint": "^3.10.1", "eslint-config-airbnb-base": "^10.0.1", "eslint-import-resolver-webpack": "^0.8.1", diff --git a/spec/javascripts/.eslintrc b/spec/javascripts/.eslintrc index 3d922021978..a3a8bb050c9 100644 --- a/spec/javascripts/.eslintrc +++ b/spec/javascripts/.eslintrc @@ -27,6 +27,19 @@ "jasmine/no-suite-dupes": [1, "branch"], "jasmine/no-spec-dupes": [1, "branch"], "no-console": 0, - "prefer-arrow-callback": 0 + "prefer-arrow-callback": 0, + "no-underscore-dangle": [ + 2, + { + "allow": [ + "__GetDependency__", + "__Rewire__", + "__ResetDependency__", + "__get__", + "__set__", + "__RewireAPI__" + ] + } + ] } } diff --git a/spec/javascripts/raven/raven_config_spec.js b/spec/javascripts/raven/raven_config_spec.js index 3885cfde6bf..b8bb558d22e 100644 --- a/spec/javascripts/raven/raven_config_spec.js +++ b/spec/javascripts/raven/raven_config_spec.js @@ -1,8 +1,7 @@ -import $ from 'jquery'; import Raven from 'raven-js'; -import RavenConfig from '~/raven/raven_config'; +import RavenConfig, { __RewireAPI__ as RavenConfigRewire } from '~/raven/raven_config'; -fdescribe('RavenConfig', () => { +describe('RavenConfig', () => { describe('init', () => { let options; @@ -116,21 +115,78 @@ fdescribe('RavenConfig', () => { }); describe('bindRavenErrors', () => { + let $document; + let $; + beforeEach(() => { + $document = jasmine.createSpyObj('$document', ['on']); + $ = jasmine.createSpy('$').and.returnValue($document); + + RavenConfigRewire.__set__('$', $); + RavenConfig.bindRavenErrors(); }); it('should query for document using jquery', () => { - console.log($, 'or', $.fn); - // expect($).toHaveBeenCalledWith() + expect($).toHaveBeenCalledWith(document); }); it('should call .on', function () { - // expect($document.on).toHaveBeenCalledWith('ajaxError.raven', RavenConfig.handleRavenErrors); + expect($document.on).toHaveBeenCalledWith('ajaxError.raven', RavenConfig.handleRavenErrors); }); }); describe('handleRavenErrors', () => { - beforeEach(() => {}); + let event; + let req; + let config; + let err; + + beforeEach(() => { + event = {}; + req = { status: 'status', responseText: 'responseText', statusText: 'statusText' }; + config = { type: 'type', url: 'url', data: 'data' }; + err = {}; + + spyOn(Raven, 'captureMessage'); + + RavenConfig.handleRavenErrors(event, req, config, err); + }); + + it('should call Raven.captureMessage', () => { + expect(Raven.captureMessage).toHaveBeenCalledWith(err, { + extra: { + type: config.type, + url: config.url, + data: config.data, + status: req.status, + response: req.responseText.substring(0, 100), + error: err, + event, + }, + }); + }); + + describe('if no err is provided', () => { + beforeEach(() => { + Raven.captureMessage.calls.reset(); + + RavenConfig.handleRavenErrors(event, req, config); + }); + + it('should use req.statusText as the error value', () => { + expect(Raven.captureMessage).toHaveBeenCalledWith(req.statusText, { + extra: { + type: config.type, + url: config.url, + data: config.data, + status: req.status, + response: req.responseText.substring(0, 100), + error: req.statusText, + event, + }, + }); + }); + }); }); }); diff --git a/yarn.lock b/yarn.lock index 46f528f0bec..6e9b9bd9cec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -406,6 +406,10 @@ babel-plugin-istanbul@^4.0.0: istanbul-lib-instrument "^1.4.2" test-exclude "^4.0.0" +babel-plugin-rewire@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/babel-plugin-rewire/-/babel-plugin-rewire-1.1.0.tgz#a6b966d9d8c06c03d95dcda2eec4e2521519549b" + babel-plugin-syntax-async-functions@^6.8.0: version "6.13.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" |