Skip to content

Commit

Permalink
Revert "build: remove unnecessary internal-angular karma reporter (a…
Browse files Browse the repository at this point in the history
…ngular#24803)"

This reverts commit ddb792d.
Part of reverting PR angular#24803 on branch `6.0.x`, because that PR is a
follow-up to PR angular#19904, which was only merged into master.
  • Loading branch information
gkalpak committed Jul 10, 2018
1 parent ddb792d commit ecb7756
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
4 changes: 3 additions & 1 deletion karma-js.conf.js
Expand Up @@ -8,6 +8,7 @@

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)
Expand Down Expand Up @@ -95,6 +96,7 @@ module.exports = function(config) {
'karma-sauce-launcher',
'karma-chrome-launcher',
'karma-sourcemap-loader',
internalAngularReporter,
],

preprocessors: {
Expand All @@ -111,7 +113,7 @@ module.exports = function(config) {
'/base/angular/': '/base/',
},

reporters: ['dots'],
reporters: ['internal-angular'],
sauceLabs: {
testName: 'Angular2',
retryLimit: 3,
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/test-saucelabs.sh
Expand Up @@ -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 dots,saucelabs
$(npm bin)/karma start ./karma-js.conf.js --single-run --browsers=${KARMA_JS_BROWSERS} --reporters internal-angular,saucelabs
travisFoldEnd "test.unit.saucelabs"
95 changes: 95 additions & 0 deletions tools/karma/reporter.js
@@ -0,0 +1,95 @@
/**
* @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],
};

0 comments on commit ecb7756

Please sign in to comment.