blob: 7aa280fd8cba19fe0162c1add185ecad1d549187 [file] [log] [blame]
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
plugins {
id "com.github.node-gradle.node" version "5.0.0"
}
description = 'Kotlin-test integration tests for JS'
apply plugin: 'kotlin-platform-js'
configurations {
nodeModules {
extendsFrom api
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, KotlinUsages.KOTLIN_RUNTIME))
attribute(KotlinPlatformType.attribute, KotlinPlatformType.js)
attribute(KotlinJsCompilerAttribute.jsCompilerAttribute, KotlinJsCompilerAttribute.legacy)
}
}
[compileClasspath, testCompileClasspath, testRuntimeClasspath].forEach {
it.attributes {
attribute(org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute.jsCompilerAttribute, org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute.legacy)
}
}
}
dependencies {
api project(':kotlin-test:kotlin-test-js')
}
// package.json contains direct links to the builddir
buildDir = "$projectDir/build"
["compileKotlin2Js", "compileTestKotlin2Js"].forEach {
tasks.named(it).configure {
kotlinOptions {
moduleKind = "commonjs"
freeCompilerArgs += "-Xforce-deprecated-legacy-compiler-usage"
}
}
}
tasks.register("populateNodeModules", Copy) {
dependsOn(compileKotlin2Js)
dependsOn(configurations.nodeModules)
from compileKotlin2Js.destinationDirectory
duplicatesStrategy = DuplicatesStrategy.EXCLUDE // temporary until stdlib mpp migration is completed
from {
configurations.nodeModules.collect {
// WORKAROUND: Some JS IR jars were absent and caused this task to fail.
// They don't contain .js thus we can skip them.
if (it.exists()) {
zipTree(it.absolutePath).matching { include '*.js' }
}
}
}
into "${buildDir}/node_modules"
}
node {
version = RepoDependencies.getNodejsVersion(project)
download = true
}
def createFrameworkTest(def name) {
return tasks.register("test$name", NpmTask) {
dependsOn(compileTestKotlin2Js, populateNodeModules, npmInstall)
def testName = name
def lowerName = name.toLowerCase()
def tcOutput = project.file("$buildDir/tc-${lowerName}.log")
def stdOutput = "$buildDir/test-${lowerName}.log"
def errOutput = "$buildDir/test-${lowerName}.err.log"
def exitCodeFile = project.file("$buildDir/test-${lowerName}.exit-code")
inputs.files(sourceSets.test.output)
inputs.dir("${buildDir}/node_modules")
outputs.files(tcOutput, stdOutput, errOutput, exitCodeFile)
args = ['run', "test-$lowerName"]
group = 'verification'
execOverrides {
it.ignoreExitValue = true
it.standardOutput = new FileOutputStream(stdOutput)
it.errorOutput = new FileOutputStream(errOutput)
}
def ignoreTestFailures = rootProject.ignoreTestFailures
doLast {
println tcOutput.text
if (exitCodeFile.text != "0" && !ignoreTestFailures) {
throw new GradleException("$testName integration test failed")
}
}
}
}
tasks.check {
['Jest', 'Jasmine', 'Mocha', 'Qunit', 'Tape'].each {
dependsOn createFrameworkTest(it)
}
}