[Gradle, JS] Fix module.exports for adapter and modulization

- semicolon should be before Function expression, because in JS Standard there is no terminated semicolons
- If use output.libraryExport for Webpack, entry files for karma should export something

#KT-34554 fixed
#KT-34555 fixed
This commit is contained in:
Ilya Goncharov
2019-10-23 14:46:53 +03:00
parent 5e2b594638
commit 0c911f4359
3 changed files with 10 additions and 8 deletions
@@ -165,12 +165,13 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
//language=ES6 //language=ES6
it.appendln( it.appendln(
""" """
(function() { // noinspection JSUnnecessarySemicolon
;(function(config) {
const webpack = require('webpack'); const webpack = require('webpack');
config.plugins.push(new webpack.SourceMapDevToolPlugin({ config.plugins.push(new webpack.SourceMapDevToolPlugin({
moduleFilenameTemplate: "[absolute-resource-path]" moduleFilenameTemplate: "[absolute-resource-path]"
})) }))
})(); })(config);
""".trimIndent() """.trimIndent()
) )
@@ -244,16 +245,16 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) : KotlinJsTestF
private fun createAdapterJs() { private fun createAdapterJs() {
configurators.add { configurators.add {
val npmProject = compilation.npmProject val npmProject = compilation.npmProject
val files = it.nodeModulesToLoad.map { npmProject.require(it) } val file = it.nodeModulesToLoad
.map { npmProject.require(it) }
.single()
val adapterJs = npmProject.dir.resolve("adapter-browser.js") val adapterJs = npmProject.dir.resolve("adapter-browser.js")
adapterJs.printWriter().use { writer -> adapterJs.printWriter().use { writer ->
val karmaRunner = npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js") val karmaRunner = npmProject.require("kotlin-test-js-runner/kotlin-test-karma-runner.js")
writer.println("require(${karmaRunner.jsQuoted()})") writer.println("require(${karmaRunner.jsQuoted()})")
files.forEach { file -> writer.println("module.exports = require(${file.jsQuoted()})")
writer.println("require(${file.jsQuoted()})")
}
} }
config.files.add(adapterJs.canonicalPath) config.files.add(adapterJs.canonicalPath)
@@ -98,7 +98,7 @@ class KotlinMocha(override val compilation: KotlinJsCompilation) : KotlinJsTestF
val adapter = npmProject.require("kotlin-test-js-runner/kotlin-test-nodejs-runner.js") val adapter = npmProject.require("kotlin-test-js-runner/kotlin-test-nodejs-runner.js")
writer.println("require(${adapter.jsQuoted()})") writer.println("require(${adapter.jsQuoted()})")
writer.println("require(${file.jsQuoted()})") writer.println("module.exports = require(${file.jsQuoted()})")
} }
} }
@@ -227,7 +227,8 @@ data class KotlinWebpackConfig(
appendln( appendln(
""" """
// Report progress to console // Report progress to console
(function(config) { // noinspection JSUnnecessarySemicolon
;(function(config) {
const webpack = require('webpack'); const webpack = require('webpack');
const handler = (percentage, message, ...args) => { const handler = (percentage, message, ...args) => {
let p = percentage * 100; let p = percentage * 100;