[Gradle, JS] Add test on not updating Node.JS if it was downloaded

^KT-47845 fixed
This commit is contained in:
Ilya Goncharov
2021-08-05 15:51:02 +03:00
committed by Space
parent b8330deefa
commit bfcd954dd3
3 changed files with 36 additions and 0 deletions
@@ -978,4 +978,16 @@ class GeneralKotlin2JsGradlePluginIT : BaseGradleIT() {
assertNoWarnings()
}
}
@Test
fun testNodeJsAndYarnDownload() = with(transformProjectWithPluginsDsl("cleanTask")) {
build("checkDownloadedFolder") {
assertSuccessful()
}
build("checkIfLastModifiedNotNow", "--rerun-tasks") {
assertSuccessful()
}
}
}
@@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlatform
import java.io.File
import java.time.*
import java.util.concurrent.*
plugins {
id "org.jetbrains.kotlin.js" version "<pluginMarkerVersion>"
@@ -29,6 +30,28 @@ tasks.create("checkDownloadedFolder") {
}
}
tasks.create("checkIfLastModifiedNotNow") {
description = "check if last modified is not current date now"
dependsOn "build"
doLast {
println("check downloaded folder existance")
def downloadedFolder = new File(project.gradle.gradleUserHomeDir, nodeJsLocation)
if (!downloadedFolder.exists() || !downloadedFolder.isDirectory()) {
throw new InvalidUserDataException("Downloaded folder was not found")
}
def now = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
def lastModified = downloadedFolder.lastModified()
def lastModified1 = lastModified + TimeUnit.DAYS.toMillis(1);
def lastModified2 = lastModified - TimeUnit.DAYS.toMillis(1);
if (now < lastModified1 || now < lastModified2) {
throw new InvalidUserDataException("Last modified date was updated")
}
}
}
tasks.create("testCleanTask") {
description = "check clean task behaviour"
doLast {
@@ -2,6 +2,7 @@ pluginManagement {
repositories {
maven { url '<mavenLocalUrl>' }
gradlePluginPortal()
mavenCentral()
}
}