[tests][bridge] added source map support / stack trace conversion

This commit is contained in:
Salakar 2018-03-25 22:06:28 +01:00
parent c9b313f23c
commit c8e3be4388
5 changed files with 9 additions and 25 deletions

View File

@ -1,6 +1,6 @@
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
const Mocha = require('mocha'); const Mocha = require('mocha');
const { parse } = require('stacktrace-parser'); const ErrorStack = require('error-stack-parser');
const { SourceMapConsumer } = require('source-map'); const { SourceMapConsumer } = require('source-map');
let bundleFileName = null; let bundleFileName = null;
@ -18,21 +18,21 @@ function frameToStr(parsed) {
line: parsed.lineNumber, line: parsed.lineNumber,
column: parsed.column, column: parsed.column,
}); });
return ` at ${name || parsed.methodName} (${source || return ` at ${name || parsed.functionName || '<anonymous>'} (${source ||
parsed.file}:${line || parsed.lineNumber}:${column || parsed.column})`; parsed.fileName}:${line || parsed.lineNumber}:${column ||
parsed.columnNumber})`;
} }
// override mocha fail so we can replace stack traces // override mocha fail so we can replace stack traces
Runner.prototype.fail = function fail(test, error) { Runner.prototype.fail = function fail(test, error) {
console.dir(error);
const original = error.stack.split('\n'); const original = error.stack.split('\n');
const parsed = parse(error.stack); const parsed = ErrorStack.parse(error);
const newStack = [original[0]]; const newStack = [original[0]];
for (let i = 0; i < parsed.length; i++) { for (let i = 0; i < parsed.length; i++) {
const { file } = parsed[i]; const { fileName } = parsed[i];
if (file === bundleFileName) newStack.push(frameToStr(parsed[i])); if (fileName === bundleFileName) newStack.push(frameToStr(parsed[i]));
else newStack.push(original[i + 1]); else newStack.push(original[i + 1]);
} }

View File

@ -71,7 +71,6 @@ async function getBundle(request) {
parsedUrl.query.inlineSourceMap = true; parsedUrl.query.inlineSourceMap = true;
delete parsedUrl.search; delete parsedUrl.search;
console.log(url.format(parsedUrl));
return downloadBundle(url.format(parsedUrl)); return downloadBundle(url.format(parsedUrl));
} }
@ -82,7 +81,6 @@ module.exports = {
async message(request) { async message(request) {
const { method } = request; const { method } = request;
// console.log(request.method);
switch (method) { switch (method) {
case PREPARE: case PREPARE:
coverage.collect(); coverage.collect();

View File

@ -32,6 +32,7 @@ export default class User {
constructor(auth: Auth, user: NativeUser) { constructor(auth: Auth, user: NativeUser) {
this._auth = auth; this._auth = auth;
this._user = user; this._user = user;
throw new Error('Woops')
} }
/** /**

View File

@ -10851,21 +10851,6 @@
"urix": "0.1.0" "urix": "0.1.0"
} }
}, },
"source-map-support": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.4.tgz",
"integrity": "sha512-PETSPG6BjY1AHs2t64vS2aqAgu6dMIMXJULWFBGbh2Gr8nVLbCFDo6i/RMMvviIQ2h1Z8+5gQhVKSn2je9nmdg==",
"requires": {
"source-map": "0.6.1"
},
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
}
}
},
"source-map-url": { "source-map-url": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz",

View File

@ -21,6 +21,7 @@
"chalk": "^2.3.2", "chalk": "^2.3.2",
"deeps": "^1.4.4", "deeps": "^1.4.4",
"detox": "^7.2.0", "detox": "^7.2.0",
"error-stack-parser": "^2.0.1",
"istanbul-lib-coverage": "^1.2.0", "istanbul-lib-coverage": "^1.2.0",
"mocha": "^4.0.1", "mocha": "^4.0.1",
"react": "^16.2.0", "react": "^16.2.0",
@ -30,7 +31,6 @@
"should-sinon": "0.0.6", "should-sinon": "0.0.6",
"sinon": "^4.4.8", "sinon": "^4.4.8",
"source-map": "^0.7.2", "source-map": "^0.7.2",
"stacktrace-parser": "^0.1.4",
"ws": "^5.1.0" "ws": "^5.1.0"
}, },
"devDependencies": { "devDependencies": {