JS: add support of JS module kind to Gradle task. Add tests of support of module kind to Maven tests

This commit is contained in:
Alexey Andreev
2016-08-23 11:35:36 +03:00
parent d08d8af407
commit 996c1b6f87
12 changed files with 197 additions and 10 deletions
@@ -61,6 +61,15 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
}
}
@Test
fun testModuleKind() {
val project = Project("kotlin2JsModuleKind", "2.10")
project.build("runRhino") {
assertSuccessful()
}
}
@Test
fun testNoOutputFileFails() {
val project = Project("kotlin2JsNoOutputFileProject", "2.10")
@@ -0,0 +1,9 @@
var amdModules = {};
function define(moduleName, dependencies, body) {
var resolvedDependencies = [];
for (var i = 0; i < dependencies.length; ++i) {
resolvedDependencies.push(amdModules[dependencies[i]]);
}
amdModules[moduleName] = body.apply(body, resolvedDependencies);
}
define.amd = {};
@@ -0,0 +1,61 @@
buildscript {
repositories {
mavenCentral()
maven {
url "file://" + pathToKotlinPlugin
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1-SNAPSHOT"
}
}
apply plugin: "kotlin2js"
apply plugin: 'java'
def outDir = "${buildDir}/kotlin2js/main/"
compileKotlin2Js.kotlinOptions.moduleKind = "amd"
compileKotlin2Js.kotlinOptions.outputFile = outDir + "app.js"
repositories {
maven {
url "file://" + pathToKotlinPlugin
}
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-js-library:1.1-SNAPSHOT"
compile "org.mozilla:rhino:1.7.7.1"
}
task runRhino(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
workingDir = "${buildDir}/kotlin2js/main/"
main = 'org.mozilla.javascript.tools.shell.Main'
args = ["-opt", "-1", "-f", "amd.js", "-f", "kotlin.js", "-f", "app.js", "-f", "check.js"]
}
build.doLast {
configurations.compile.each { File file ->
copy {
includeEmptyDirs = false
from zipTree(file.absolutePath)
into "${buildDir}/kotlin2js/main/"
include { fileTreeElement ->
def path = fileTreeElement.path
path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
}
}
}
copy {
from "."
include "amd.js"
include "check.js"
into "${buildDir}/kotlin2js/main/"
}
}
runRhino.dependsOn build
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
define("check", ["app"], function(app) {
if (app.foo.bar() != "OK") {
throw new Error("Unexpected result");
}
});
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package foo
fun bar() = "OK"