diff --git a/package.json b/package.json index 6f176708be5007..24829b260106f3 100644 --- a/package.json +++ b/package.json @@ -163,7 +163,6 @@ }, "devDependencies": { "@elastic/eslint-config-kibana": "0.0.3", - "Nonsense": "0.1.2", "angular-mocks": "1.4.7", "auto-release-sinon": "1.0.3", "babel-eslint": "4.1.8", diff --git a/src/ui/public/stack_trace_mapper/set_error_stack.js b/src/ui/public/stack_trace_mapper/set_error_stack.js deleted file mode 100644 index ff6f5b7838455f..00000000000000 --- a/src/ui/public/stack_trace_mapper/set_error_stack.js +++ /dev/null @@ -1,34 +0,0 @@ -import _ from 'lodash'; - -let err = new Error(); -try { setByAssignment(err, 'john'); } catch (e) {} // eslint-disable-line - -// err.stack is not always writeable, so we -// do some detection for support and fallback to a -// shadowing method, which "copies" the error but -// keeps the original as the prototype so that -// the error is still an instance of the same -// classes as the original error -if (err.stack === 'john') module.exports = setByAssignment; -else module.exports = setByShadowing; - -function setByShadowing(err, stack) { - let props = _.mapValues(err, function (val) { - return { - enumerable: true, - value: val - }; - }); - - props.stack = { - enumerable: true, - value: stack - }; - - return Object.create(err, props); -} - -function setByAssignment(err, stack) { - err.stack = stack; - return err; -} diff --git a/src/ui/public/stack_trace_mapper/source_map_reader.js b/src/ui/public/stack_trace_mapper/source_map_reader.js deleted file mode 100644 index 5aeb44496029b3..00000000000000 --- a/src/ui/public/stack_trace_mapper/source_map_reader.js +++ /dev/null @@ -1,15 +0,0 @@ -import _ from 'lodash'; -import { SourceMapConsumer } from 'source-map/lib/source-map-consumer'; -import { parse } from 'url'; - -function SourceMapReader(url, map) { - this.smc = new SourceMapConsumer(map); - this.url = parse(url); - this.re = new RegExp('(^|/)' + _.escapeRegExp(this.url.pathname.slice(1)) + '($|\\?|#)'); -} - -SourceMapReader.prototype.matchUrl = function (stackFileName) { - return this.re.test(stackFileName); -}; - -module.exports = SourceMapReader; diff --git a/src/ui/public/stack_trace_mapper/stack_line_format.js b/src/ui/public/stack_trace_mapper/stack_line_format.js deleted file mode 100644 index 7d4c2ebe476c79..00000000000000 --- a/src/ui/public/stack_trace_mapper/stack_line_format.js +++ /dev/null @@ -1,19 +0,0 @@ -import _ from 'lodash'; - -let opts = [ - /@((?:[!#$&-;=?-\[\]_a-z~]|%[0-9a-f]{2})+\.js)\:(\d+)(?:\:(\d+)|())/ig, - /(?: \(|at )((?:[!#$&-;=?-\[\]_a-z~]|%[0-9a-f]{2})+\.js)\:(\d+)(?:\:(\d+)|())/ig -]; - -let sample; -try { throw new Error('msg'); } catch (e) { sample = e.stack; } - -let format = _.find(opts, function (format) { - return format.test(sample); -}); - -if (!format && window.console && window.console.log) { - window.console.log('unable to pick format with stack trace sample ' + sample); -} - -module.exports = format; diff --git a/src/ui/public/stack_trace_mapper/stack_trace_mapper.js b/src/ui/public/stack_trace_mapper/stack_trace_mapper.js deleted file mode 100644 index 85b4366184333b..00000000000000 --- a/src/ui/public/stack_trace_mapper/stack_trace_mapper.js +++ /dev/null @@ -1,65 +0,0 @@ -import _ from 'lodash'; -import fetch from 'exports?window.fetch!imports?Promise=bluebird!whatwg-fetch'; - -import setErrorStack from './set_error_stack'; -import translateStackLine from './translate_stack_line'; -import stackLineFormat from './stack_line_format'; -import SourceMapReader from './source_map_reader'; -import { resolve } from 'bluebird'; -import $ from 'jquery'; - -function StackTraceMapper() { - this.maps = []; - this.init = _.once(this.init); - this.getMapFor = _.memoize(this.getMapFor); - _.bindAll(this, 'init', 'mapError', 'getMapFor', 'mapLine', 'loadMaps'); -} - -StackTraceMapper.prototype.init = function (mapUrls) { - return this.loadMaps(mapUrls).return(this); -}; - -StackTraceMapper.prototype.mapError = function (err) { - if (!stackLineFormat || !err.stack) return err; - - let stack = err.stack.replace(stackLineFormat, this.mapLine); - return setErrorStack(err, stack); -}; - -StackTraceMapper.prototype.mapLine = function (match, filename, line, col) { - return translateStackLine(this.getMapFor(filename), match, filename, line, col); -}; - -StackTraceMapper.prototype.getMapFor = function (url) { - return _.find(this.maps, function (map) { - return map.matchUrl(url); - }); -}; - -StackTraceMapper.prototype.loadMaps = function (mapUrls) { - mapUrls = _.clone(mapUrls || {}); - - let maps = this.maps; - - $('script[src][src-map]').each(function () { - let $el = $(this); - mapUrls[$el.attr('src')] = $el.attr('src-map'); - }); - - return resolve(_.pairs(mapUrls)) - .map( - _.spread(function (url, mapUrl) { - return fetch(mapUrl) - .then(function (resp) { return resp.json(); }) - .then(function (map) { - maps.push(new SourceMapReader(url, map)); - }); - }) - ); -}; - -StackTraceMapper.getInstance = _.once(function () { - return (new StackTraceMapper()).init(); -}); - -module.exports = StackTraceMapper; diff --git a/src/ui/public/stack_trace_mapper/translate_stack_line.js b/src/ui/public/stack_trace_mapper/translate_stack_line.js deleted file mode 100644 index f19f64cfe6186d..00000000000000 --- a/src/ui/public/stack_trace_mapper/translate_stack_line.js +++ /dev/null @@ -1,41 +0,0 @@ -import _ from 'lodash'; - -module.exports = function (map, match, filename, line, col) { - if (!map) return match; - - let position = { - line: parseFloat(line) || 0, - column: parseFloat(col) || 0 - }; - - let srcPosition = map.smc.originalPositionFor(position); - if (!srcPosition || !srcPosition.source) return match; - - let srcFilename = srcPosition.source; - let srcLine = srcPosition.line; - let srcCol = srcPosition.column; - - if (srcCol === 0 && position.column) { - // TODO: teach sourcemaps correct column - // - // since our bundles are not yet minified we can copy the column - // this won't always be the case - srcCol = position.column; - } - - // fold the components into the original match, so that supporting - // characters (parens, periods, etc) from the format are kept, and so - // we don't accidentally replace the wrong part we use splitting and consumption - let resp = ''; - let remainingResp = match; - let fold = function (replace, replacement) { - let wrappingContent = remainingResp.split(replace); - resp += wrappingContent.shift() + replacement; - remainingResp = wrappingContent.join(replace); - }; - - fold(filename, srcFilename); - fold(line, srcLine); - if (_.isString(col)) fold(col, srcCol); - return resp; -}; diff --git a/src/ui/public/test_harness/test_harness.js b/src/ui/public/test_harness/test_harness.js index 8d0c6cef878783..d51ff14bd250a8 100644 --- a/src/ui/public/test_harness/test_harness.js +++ b/src/ui/public/test_harness/test_harness.js @@ -1,58 +1,23 @@ -/* global mocha */ - // chrome expects to be loaded first, let it get its way import chrome from 'ui/chrome'; -import Nonsense from 'Nonsense'; import sinon from 'sinon'; -import _ from 'lodash'; import Notifier from 'ui/notify/notifier'; - -import StackTraceMapper from 'ui/stack_trace_mapper'; -import { parse } from 'url'; -import $ from 'jquery'; import { setupAutoRelease } from 'auto-release-sinon'; + import './test_harness.less'; import 'ng_mock'; import { setupTestSharding } from './test_sharding'; -/*** the vislib tests have certain style requirements, so lets make sure they are met ***/ -$('body').attr('id', 'test-harness-body'); // so we can make high priority selectors - - -/*** Setup seeded random ***/ -let seedInput = parse(window.location.href, true).query.seed; -let seed = _.add(seedInput, 0) || Date.now(); -Math.random = _.bindKey(new Nonsense(seed), 'frac'); -Math.random.nonsense = new Nonsense(seed); -console.log('Random-ness seed: ' + seed); - // Setup auto releasing stubs and spys setupAutoRelease(sinon, window.afterEach); setupTestSharding(); -/*** manually map error stack traces using the sourcemap ***/ -before(function () { - // before the tests start, load the sourcemap and hook into error generation for the mocha reporter - this.timeout(30000); +// allows test_harness.less to have higher priority selectors +document.body.setAttribute('id', 'test-harness-body'); - let mapper; - let Runner = window.Mocha.Runner; - - Runner.prototype.emit = _.wrap(Runner.prototype.emit, function (emit, event, test, err) { - if (err && mapper) err = mapper.mapError(err); - return emit.call(this, event, test, err); - }); - - return StackTraceMapper.getInstance({ - '/bundles/tests.bundle.js': '/bundles/tests.bundle.js.map' - }).then(function (instance) { - mapper = instance; - }); -}); - - -before(function () { +// prevent accidental ajax requests +before(() => { sinon.useFakeXMLHttpRequest(); }); @@ -63,8 +28,7 @@ beforeEach(function () { } }); - -/*** Kick off mocha, called at the end of test entry files ***/ -exports.bootstrap = function () { +// Kick off mocha, called at the end of test entry files +exports.bootstrap = () => { chrome.setupAngular(); };