[K/JS] Fix stdlib long path problem on Windows for ES modules tests

This commit is contained in:
Artem Kobzar
2022-10-14 13:29:36 +00:00
committed by Space Team
parent 0127c3a6c4
commit 6d888e8e31
2 changed files with 8 additions and 5 deletions
@@ -310,16 +310,16 @@ val TestModule.kind: ModuleKind
get() = directives.moduleKind get() = directives.moduleKind
fun String.augmentWithModuleName(moduleName: String): String { fun String.augmentWithModuleName(moduleName: String): String {
return if (moduleName.isPath()) { val normalizedName = moduleName.run { if (isWindows) minify() else this }
replaceAfterLast(File.separator, moduleName.replace("./", ""))
return if (normalizedName.isPath()) {
replaceAfterLast(File.separator, normalizedName.replace("./", ""))
} else { } else {
val suffix = when { val suffix = when {
endsWith(ESM_EXTENSION) -> ESM_EXTENSION endsWith(ESM_EXTENSION) -> ESM_EXTENSION
endsWith(REGULAR_EXTENSION) -> REGULAR_EXTENSION endsWith(REGULAR_EXTENSION) -> REGULAR_EXTENSION
else -> error("Unexpected file '$this' extension") else -> error("Unexpected file '$this' extension")
} }
val normalizedName = moduleName.run { if (isWindows) minify() else this }
return removeSuffix("_v5$suffix") + "-${normalizedName}_v5$suffix" return removeSuffix("_v5$suffix") + "-${normalizedName}_v5$suffix"
} }
} }
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.js.test.converters package org.jetbrains.kotlin.js.test.converters
import org.jetbrains.kotlin.cli.common.isWindows
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.safeName import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.safeName
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.TestServices
@@ -26,7 +27,9 @@ class JsIrModuleToPath(val testServices: TestServices, shouldProvidePaths: Boole
override operator fun get(key: K): V? { override operator fun get(key: K): V? {
return runIf(!isEmpty()) { return runIf(!isEmpty()) {
"./${getJsArtifactSimpleName(testServices, key.safeName)}_v5.mjs" "./${getJsArtifactSimpleName(testServices, key.safeName)}_v5.mjs".run {
if (isWindows) minify() else this
}
} }
} }
} }