From ddb792da281f8a3d893cac5bec28cd1ebf01d228 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 9 Jul 2018 17:44:55 +0300 Subject: [PATCH] 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 --- karma-js.conf.js | 4 +- scripts/ci/test-saucelabs.sh | 2 +- tools/karma/reporter.js | 95 ------------------------------------ 3 files changed, 2 insertions(+), 99 deletions(-) delete mode 100644 tools/karma/reporter.js diff --git a/karma-js.conf.js b/karma-js.conf.js index a8ab18df3d..96f5642e8b 100644 --- a/karma-js.conf.js +++ b/karma-js.conf.js @@ -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, diff --git a/scripts/ci/test-saucelabs.sh b/scripts/ci/test-saucelabs.sh index f3e1b8bd41..e141d251e8 100755 --- a/scripts/ci/test-saucelabs.sh +++ b/scripts/ci/test-saucelabs.sh @@ -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" diff --git a/tools/karma/reporter.js b/tools/karma/reporter.js deleted file mode 100644 index ca0693509a..0000000000 --- a/tools/karma/reporter.js +++ /dev/null @@ -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], -};