build: remove unnecessary `internal-angular` karma reporter (#24803)

The reporter was added in 87d56acda, with the purpose of fixing
source-map paths (which was apparently needed back then). Things have
moved around a lot since then and the custom reporter doesn't seem to be
necessary any more. By removing the reporter, we have one less thing to
worry about while upgrading karma; plus we get improvements in built-in
reporters for free.

Output with the custom reporter:
```
at someMethod (packages/core/.../some-file.ts:13:37)
```

Output with the built-in reporter:
```
at someMethod (packages/core/.../some-file.ts:13.37 <- dist/all/@angular/core/.../some-file.js:1:337)
```

PR Close #24803
This commit is contained in:
George Kalpakas 2018-07-09 17:44:55 +03:00 committed by Miško Hevery
parent 89203c96ad
commit ddb792da28
3 changed files with 2 additions and 99 deletions

View File

@ -8,7 +8,6 @@
const browserProvidersConf = require('./browser-providers.conf');
const {generateSeed} = require('./tools/jasmine-seed-generator');
const internalAngularReporter = require('./tools/karma/reporter');
// Karma configuration
// Generated on Thu Sep 25 2014 11:52:02 GMT-0700 (PDT)
@ -96,7 +95,6 @@ module.exports = function(config) {
'karma-sauce-launcher',
'karma-chrome-launcher',
'karma-sourcemap-loader',
internalAngularReporter,
],
preprocessors: {
@ -113,7 +111,7 @@ module.exports = function(config) {
'/base/angular/': '/base/',
},
reporters: ['internal-angular'],
reporters: ['dots'],
sauceLabs: {
testName: 'Angular2',
retryLimit: 3,

View File

@ -10,5 +10,5 @@ source ${thisDir}/_travis-fold.sh
travisFoldStart "test.unit.saucelabs"
./scripts/sauce/sauce_connect_block.sh
SAUCE_ACCESS_KEY=`echo $SAUCE_ACCESS_KEY | rev`
$(npm bin)/karma start ./karma-js.conf.js --single-run --browsers=${KARMA_JS_BROWSERS} --reporters internal-angular,saucelabs
$(npm bin)/karma start ./karma-js.conf.js --single-run --browsers=${KARMA_JS_BROWSERS} --reporters dots,saucelabs
travisFoldEnd "test.unit.saucelabs"

View File

@ -1,95 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
'use strict';
const DotsColorReporter = require('karma/lib/reporters/dots_color');
const {SourceMapConsumer} = require('source-map');
const {resolve} = require('url');
// Based on `karma/lib/reporter.js` (v2.0.4):
// https://github.com/karma-runner/karma/blob/v2.0.4/lib/reporter.js
function createErrorFormatter(config, emitter, SourceMapConsumer) {
const basePath = config.basePath;
const urlRoot = (config.urlRoot === '/') ? '' : (config.urlRoot || '');
const urlRegexp = new RegExp(
'(?:https?:\\/\\/' + config.hostname + '(?:\\:' + config.port + ')?' +
')?\\/?' + urlRoot + '\\/?' +
'(base/|absolute)' + // prefix, including slash for base/ to create relative paths.
'((?:[A-z]\\:)?[^\\?\\s\\:]*)' + // path
'(\\?\\w*)?' + // sha
'(\\:(\\d+))?' + // line
'(\\:(\\d+))?' + // column
'',
'g');
const sourceMapConsumerCache = new WeakMap();
let lastServedFiles = [];
// Helpers
const findFile = path => lastServedFiles.find(f => f.path === path);
const formatPathMapping = (path, line, column) =>
path + (line ? `:${line}` : '') + (column ? `:${column}` : '');
const isString = input => typeof input === 'string';
const getSourceMapConsumer = sourceMap => {
if (!sourceMapConsumerCache.has(sourceMap)) {
sourceMapConsumerCache.set(sourceMap, new SourceMapConsumer(sourceMap));
}
return sourceMapConsumerCache.get(sourceMap);
};
emitter.on('file_list_modified', files => lastServedFiles = files.served);
return (input, indentation) => {
if (!isString(indentation)) indentation = '';
if (!input) input = '';
if (isString(input.message)) input = input.message;
if (!isString(input)) input = JSON.stringify(input, null, indentation);
let msg = input.replace(urlRegexp, (_, prefix, path, __, ___, line, ____, column) => {
const normalizedPath = (prefix === 'base/') ? `${basePath}/${path}` : path;
const file = findFile(normalizedPath);
if (file && file.sourceMap && line) {
line = +line;
column = +column || 0;
const bias =
column ? SourceMapConsumer.GREATEST_LOWER_BOUND : SourceMapConsumer.LEAST_UPPER_BOUND;
try {
const original =
getSourceMapConsumer(file.sourceMap).originalPositionFor({line, column, bias});
return formatPathMapping(
`${resolve(path, original.source)}`, original.line, original.column);
} catch (e) {
console.warn(`SourceMap position not found for trace: ${input}`);
}
}
return formatPathMapping(path, line, column) || prefix;
});
// Indent every line.
if (indentation) {
msg = indentation + msg.replace(/\n/g, `\n${indentation}`);
}
return config.formatError ? config.formatError(msg) : `${msg}\n`;
};
}
InternalAngularReporter.$inject = ['config', 'emitter'];
function InternalAngularReporter(config, emitter) {
var formatter = createErrorFormatter(config, emitter, SourceMapConsumer);
DotsColorReporter.call(this, formatter, false, config.colors, config.browserConsoleLogOptions);
}
module.exports = {
'reporter:internal-angular': ['type', InternalAngularReporter],
};