mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
trim down test harness, remove StackTraceMapper
This commit is contained in:
parent
908da97953
commit
ae4ddedaf3
7 changed files with 7 additions and 218 deletions
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
|
@ -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;
|
||||
};
|
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue