[Gradle, JS] Disable optimization in webpack for karma tests
^KT-56192 fixed
This commit is contained in:
committed by
Space Team
parent
9d911247fa
commit
42ded7be09
+1
-1
@@ -322,7 +322,7 @@
|
|||||||
/libraries/tools/kotlin-serialization-unshaded/ "Kotlin Build Tools"
|
/libraries/tools/kotlin-serialization-unshaded/ "Kotlin Build Tools"
|
||||||
/libraries/tools/kotlin-stdlib-docs/ A.Qurbonzoda Vsevolod.Tolstopyato Ilya.Gorbunov
|
/libraries/tools/kotlin-stdlib-docs/ A.Qurbonzoda Vsevolod.Tolstopyato Ilya.Gorbunov
|
||||||
/libraries/tools/kotlin-stdlib-gen/ A.Qurbonzoda Vsevolod.Tolstopyato Ilya.Gorbunov
|
/libraries/tools/kotlin-stdlib-gen/ A.Qurbonzoda Vsevolod.Tolstopyato Ilya.Gorbunov
|
||||||
/libraries/tools/kotlin-test-js-runner/ A.Qurbonzoda Vsevolod.Tolstopyato Ilya.Gorbunov
|
/libraries/tools/kotlin-test-js-runner/ "Kotlin JS"
|
||||||
/libraries/tools/kotlin-tooling-core/ "Kotlin Build Tools" "Kotlin Multiplatform"
|
/libraries/tools/kotlin-tooling-core/ "Kotlin Build Tools" "Kotlin Multiplatform"
|
||||||
/libraries/tools/kotlin-tooling-metadata/ "Kotlin Build Tools" "Kotlin Multiplatform"
|
/libraries/tools/kotlin-tooling-metadata/ "Kotlin Build Tools" "Kotlin Multiplatform"
|
||||||
/libraries/tools/kotlinp/ "Kotlin JVM"
|
/libraries/tools/kotlinp/ "Kotlin JVM"
|
||||||
|
|||||||
+4
@@ -80,6 +80,10 @@ class KotlinKarma(
|
|||||||
|
|
||||||
val webpackConfig = KotlinWebpackConfig(
|
val webpackConfig = KotlinWebpackConfig(
|
||||||
configDirectory = project.projectDir.resolve("webpack.config.d"),
|
configDirectory = project.projectDir.resolve("webpack.config.d"),
|
||||||
|
optimization = KotlinWebpackConfig.Optimization(
|
||||||
|
runtimeChunk = false,
|
||||||
|
splitChunks = false
|
||||||
|
),
|
||||||
sourceMaps = true,
|
sourceMaps = true,
|
||||||
devtool = null,
|
devtool = null,
|
||||||
export = false,
|
export = false,
|
||||||
|
|||||||
+20
@@ -61,6 +61,7 @@ data class KotlinWebpackConfig(
|
|||||||
var devtool: String? = WebpackDevtool.EVAL_SOURCE_MAP,
|
var devtool: String? = WebpackDevtool.EVAL_SOURCE_MAP,
|
||||||
@Input
|
@Input
|
||||||
var showProgress: Boolean = false,
|
var showProgress: Boolean = false,
|
||||||
|
var optimization: Optimization? = null,
|
||||||
@Input
|
@Input
|
||||||
var sourceMaps: Boolean = false,
|
var sourceMaps: Boolean = false,
|
||||||
@Input
|
@Input
|
||||||
@@ -166,6 +167,12 @@ data class KotlinWebpackConfig(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
data class Optimization(
|
||||||
|
var runtimeChunk: Any,
|
||||||
|
var splitChunks: Any
|
||||||
|
) : Serializable
|
||||||
|
|
||||||
fun save(configFile: File) {
|
fun save(configFile: File) {
|
||||||
configFile.writer().use {
|
configFile.writer().use {
|
||||||
appendTo(it)
|
appendTo(it)
|
||||||
@@ -196,6 +203,7 @@ data class KotlinWebpackConfig(
|
|||||||
appendEntry()
|
appendEntry()
|
||||||
appendResolveModules()
|
appendResolveModules()
|
||||||
appendSourceMaps()
|
appendSourceMaps()
|
||||||
|
appendOptimization()
|
||||||
appendDevServer()
|
appendDevServer()
|
||||||
appendProgressReporter()
|
appendProgressReporter()
|
||||||
rules.forEach { rule ->
|
rules.forEach { rule ->
|
||||||
@@ -302,6 +310,18 @@ data class KotlinWebpackConfig(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Appendable.appendOptimization() {
|
||||||
|
if (optimization == null) return
|
||||||
|
|
||||||
|
//language=JavaScript 1.8
|
||||||
|
appendLine(
|
||||||
|
"""
|
||||||
|
// optimization
|
||||||
|
config.optimization = config.optimization || ${json(optimization!!)};
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun Appendable.appendEntry() {
|
private fun Appendable.appendEntry() {
|
||||||
if (
|
if (
|
||||||
entry == null
|
entry == null
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import {
|
|||||||
} from "./src/teamcity-format";
|
} from "./src/teamcity-format";
|
||||||
|
|
||||||
const resolve = require('path').resolve;
|
const resolve = require('path').resolve;
|
||||||
|
const SourceMapConsumer = require('source-map').SourceMapConsumer
|
||||||
|
const _ = require('lodash')
|
||||||
|
const PathUtils = require('karma/lib/utils/path-utils')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From karma
|
* From karma
|
||||||
@@ -19,27 +22,26 @@ const resolve = require('path').resolve;
|
|||||||
*/
|
*/
|
||||||
// This ErrorFormatter is copied from standard karma's,
|
// This ErrorFormatter is copied from standard karma's,
|
||||||
// but without warning in case of failed original location finding
|
// but without warning in case of failed original location finding
|
||||||
function createFormatError(config, emitter) {
|
function createErrorFormatter(config, emitter, SourceMapConsumer) {
|
||||||
const basePath = config.basePath;
|
const basePath = config.basePath
|
||||||
const urlRoot = config.urlRoot === '/' ? '' : (config.urlRoot || '');
|
const urlRoot = config.urlRoot === '/' ? '' : (config.urlRoot || '')
|
||||||
let lastServedFiles = [];
|
let lastServedFiles = []
|
||||||
|
|
||||||
emitter.on('file_list_modified', (files) => {
|
emitter.on('file_list_modified', (files) => {
|
||||||
lastServedFiles = files.served
|
lastServedFiles = files.served
|
||||||
});
|
})
|
||||||
|
|
||||||
const URL_REGEXP = new RegExp('(?:https?:\\/\\/' +
|
const URL_REGEXP = new RegExp('(?:https?:\\/\\/' +
|
||||||
config.hostname + '(?:\\:' + config.port + ')?' + ')?\\/?' +
|
config.hostname + '(?:\\:' + config.port + ')?' + ')?\\/?' +
|
||||||
urlRoot + '\\/?' +
|
urlRoot + '\\/?' +
|
||||||
'(base/|absolute)' + // prefix, including slash for base/ to create relative paths.
|
'(base/|absolute)' + // prefix, including slash for base/ to create relative paths.
|
||||||
'((?:[A-z]\\:)?[^\\?\\s\\:]*)' + // path
|
'((?:[A-z]\\:)?[^\\?\\s\\:]*)' + // path
|
||||||
'(\\?\\w*)?' + // sha
|
'(\\?\\w*)?' + // sha
|
||||||
'(\\:(\\d+))?' + // line
|
'(\\:(\\d+))?' + // line
|
||||||
'(\\:(\\d+))?' + // column
|
'(\\:(\\d+))?' + // column
|
||||||
'', 'g');
|
'', 'g')
|
||||||
|
|
||||||
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
const cache = new WeakMap()
|
||||||
|
|
||||||
const cache = new WeakMap();
|
|
||||||
|
|
||||||
function getSourceMapConsumer(sourceMap) {
|
function getSourceMapConsumer(sourceMap) {
|
||||||
if (!cache.has(sourceMap)) {
|
if (!cache.has(sourceMap)) {
|
||||||
@@ -48,34 +50,58 @@ function createFormatError(config, emitter) {
|
|||||||
return cache.get(sourceMap)
|
return cache.get(sourceMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
const PathUtils = require('karma/lib/utils/path-utils.js');
|
return function (input, indentation) {
|
||||||
|
indentation = _.isString(indentation) ? indentation : ''
|
||||||
|
if (_.isError(input)) {
|
||||||
|
input = input.message
|
||||||
|
} else if (_.isEmpty(input)) {
|
||||||
|
input = ''
|
||||||
|
} else if (!_.isString(input)) {
|
||||||
|
input = JSON.stringify(input, null, indentation)
|
||||||
|
}
|
||||||
|
|
||||||
return function (input) {
|
let msg = input.replace(URL_REGEXP, function (stackTracePath, prefix, path, __, ___, line, ____, column) {
|
||||||
let msg = input.replace(URL_REGEXP, function (_, prefix, path, __, ___, line, ____, column) {
|
const normalizedPath = prefix === 'base/' ? `${basePath}/${path}` : path
|
||||||
const normalizedPath = prefix === 'base/' ? `${basePath}/${path}` : path;
|
const file = lastServedFiles.find((file) => file.path === normalizedPath)
|
||||||
const file = lastServedFiles.find((file) => file.path === normalizedPath);
|
|
||||||
|
|
||||||
if (file && file.sourceMap && line) {
|
if (file && file.sourceMap && line) {
|
||||||
line = +line;
|
line = +line
|
||||||
column = +column;
|
column = +column
|
||||||
const bias = column ? SourceMapConsumer.GREATEST_LOWER_BOUND : SourceMapConsumer.LEAST_UPPER_BOUND;
|
|
||||||
|
// When no column is given and we default to 0, it doesn't make sense to only search for smaller
|
||||||
|
// or equal columns in the sourcemap, let's search for equal or greater columns.
|
||||||
|
const bias = column ? SourceMapConsumer.GREATEST_LOWER_BOUND : SourceMapConsumer.LEAST_UPPER_BOUND
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const original = getSourceMapConsumer(file.sourceMap).originalPositionFor({line, column: (column || 0), bias});
|
const zeroBasedColumn = Math.max(0, (column || 1) - 1)
|
||||||
|
const original = getSourceMapConsumer(file.sourceMap).originalPositionFor({line, column: zeroBasedColumn, bias})
|
||||||
|
|
||||||
return `${PathUtils.formatPathMapping(resolve(path, original.source), original.line,
|
// If there is no original position/source for the current stack trace path, then
|
||||||
original.column)} <- ${PathUtils.formatPathMapping(path, line, column)}`
|
// we return early with the formatted generated position. This handles the case of
|
||||||
}
|
// generated code which does not map to anything, see Case 1 of the source-map spec.
|
||||||
catch (e) {
|
// https://sourcemaps.info/spec.html.
|
||||||
|
if (original.source === null) {
|
||||||
|
return PathUtils.formatPathMapping(path, line, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Source maps often only have a local file name, resolve to turn into a full path if
|
||||||
|
// the path is not absolute yet.
|
||||||
|
const oneBasedOriginalColumn = original.column == null ? original.column : original.column + 1
|
||||||
|
return `${PathUtils.formatPathMapping(resolve(path, original.source), original.line, oneBasedOriginalColumn)} <- ${PathUtils.formatPathMapping(path, line, column)}`
|
||||||
|
} catch (e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PathUtils.formatPathMapping(path, line, column) || prefix
|
return PathUtils.formatPathMapping(path, line, column) || prefix
|
||||||
});
|
})
|
||||||
|
|
||||||
return msg + '\n'
|
if (indentation) {
|
||||||
};
|
msg = indentation + msg.replace(/\n/g, '\n' + indentation)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.formatError ? config.formatError(msg) : msg + '\n'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +131,7 @@ const KarmaKotlinReporter = function (baseReporterDecorator, config, emitter) {
|
|||||||
baseReporterDecorator(this)
|
baseReporterDecorator(this)
|
||||||
const self = this
|
const self = this
|
||||||
|
|
||||||
const formatError = createFormatError(config, emitter)
|
const formatError = createErrorFormatter(config, emitter, SourceMapConsumer)
|
||||||
|
|
||||||
const END_KOTLIN_TEST = "'--END_KOTLIN_TEST--"
|
const END_KOTLIN_TEST = "'--END_KOTLIN_TEST--"
|
||||||
|
|
||||||
@@ -178,9 +204,9 @@ const KarmaKotlinReporter = function (baseReporterDecorator, config, emitter) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
log.push(formatMessage(TEST_FAILED, testName, "FAILED",
|
log.push(formatMessage(TEST_FAILED, testName, "FAILED",
|
||||||
result.log
|
result.log
|
||||||
.map(log => formatError(log))
|
.map(log => formatError(log))
|
||||||
.join('\n\n')
|
.join('\n\n')
|
||||||
));
|
));
|
||||||
|
|
||||||
log.push(formatMessage(TEST_END, testName, result.time))
|
log.push(formatMessage(TEST_END, testName, result.time))
|
||||||
@@ -207,7 +233,7 @@ const KarmaKotlinReporter = function (baseReporterDecorator, config, emitter) {
|
|||||||
self.write(formatMessage(BLOCK_CLOSED, 'JavaScript Unit Tests'))
|
self.write(formatMessage(BLOCK_CLOSED, 'JavaScript Unit Tests'))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.checkBrowserResult = function(browser) {
|
this.checkBrowserResult = function (browser) {
|
||||||
if (!this.browserResults[browser.id]) {
|
if (!this.browserResults[browser.id]) {
|
||||||
initializeBrowser(browser)
|
initializeBrowser(browser)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const {absolutify} = require("webpack/lib/util/identifier");
|
|||||||
// https://github.com/webpack/webpack/issues/12951
|
// https://github.com/webpack/webpack/issues/12951
|
||||||
class PatchSourceMapSourcePlugin {
|
class PatchSourceMapSourcePlugin {
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.beforeRun.tap("PathcSourceMapSourcePlugin", compiler => {
|
compiler.hooks.beforeRun.tap("PatchSourceMapSourcePlugin", compiler => {
|
||||||
const original = SourceMapSource.prototype._ensureSourceMapObject;
|
const original = SourceMapSource.prototype._ensureSourceMapObject;
|
||||||
|
|
||||||
SourceMapSource.prototype._ensureSourceMapObject = function () {
|
SourceMapSource.prototype._ensureSourceMapObject = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user