Commit 86b4f49c authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Removed rewire and fixed tests

parent 69e49a09
import Raven from 'raven-js';
import $ from 'jquery';
const RavenConfig = {
init(options = {}) {
......@@ -24,11 +23,12 @@ const RavenConfig = {
},
bindRavenErrors() {
$(document).on('ajaxError.raven', this.handleRavenErrors);
window.$(document).on('ajaxError.raven', this.handleRavenErrors);
},
handleRavenErrors(event, req, config, err) {
const error = err || req.statusText;
const responseText = req.responseText || 'Unknown response text';
Raven.captureMessage(error, {
extra: {
......@@ -36,7 +36,7 @@ const RavenConfig = {
url: config.url,
data: config.data,
status: req.status,
response: req.responseText.substring(0, 100),
response: responseText.substring(0, 100),
error,
event,
},
......
......@@ -15,7 +15,6 @@ var DEV_SERVER_HOST = process.env.DEV_SERVER_HOST || 'localhost';
var DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10) || 3808;
var DEV_SERVER_LIVERELOAD = process.env.DEV_SERVER_LIVERELOAD !== 'false';
var WEBPACK_REPORT = process.env.WEBPACK_REPORT;
var rewirePlugin = IS_PRODUCTION ? '?plugins=rewire' : '';
var config = {
context: path.join(ROOT_PATH, 'app/assets/javascripts'),
......@@ -69,7 +68,7 @@ var config = {
{
test: /\.js$/,
exclude: /(node_modules|vendor\/assets)/,
loader: `babel-loader${rewirePlugin}`,
loader: 'babel-loader',
},
{
test: /\.vue$/,
......
......@@ -27,19 +27,6 @@
"jasmine/no-suite-dupes": [1, "branch"],
"jasmine/no-spec-dupes": [1, "branch"],
"no-console": 0,
"prefer-arrow-callback": 0,
"no-underscore-dangle": [
2,
{
"allow": [
"__GetDependency__",
"__Rewire__",
"__ResetDependency__",
"__get__",
"__set__",
"__RewireAPI__"
]
}
]
"prefer-arrow-callback": 0
}
}
import Raven from 'raven-js';
import RavenConfig, { __RewireAPI__ as RavenConfigRewire } from '~/raven/raven_config';
import RavenConfig from '~/raven/raven_config';
describe('RavenConfig', () => {
describe('init', () => {
......@@ -122,13 +122,13 @@ describe('RavenConfig', () => {
$document = jasmine.createSpyObj('$document', ['on']);
$ = jasmine.createSpy('$').and.returnValue($document);
RavenConfigRewire.__set__('$', $);
window.$ = $;
RavenConfig.bindRavenErrors();
});
it('should query for document using jquery', () => {
expect($).toHaveBeenCalledWith(document);
expect(window.$).toHaveBeenCalledWith(document);
});
it('should call .on', function () {
......@@ -188,5 +188,29 @@ describe('RavenConfig', () => {
});
});
});
describe('if no req.responseText is provided', () => {
beforeEach(() => {
req.responseText = undefined;
Raven.captureMessage.calls.reset();
RavenConfig.handleRavenErrors(event, req, config, err);
});
it('should use `Unknown response text` as the response', () => {
expect(Raven.captureMessage).toHaveBeenCalledWith(err, {
extra: {
type: config.type,
url: config.url,
data: config.data,
status: req.status,
response: 'Unknown response text',
error: err,
event,
},
});
});
});
});
});
......@@ -425,10 +425,6 @@ 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"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment