JS: add suffix '_test' to test module output files to avoid name conflicts (KT-16979)
Also stop setting AMD module ids explicitly.
This commit is contained in:
@@ -233,6 +233,13 @@ abstract class BasicBoxTest(
|
||||
"$KOTLIN_TEST_INTERNAL.endModule(\"${StringUtil.escapeStringCharacters(config.moduleId)}\");"
|
||||
FileUtil.writeToFile(outputFile, wrappedContent)
|
||||
}
|
||||
else if (config.moduleKind == ModuleKind.AMD || config.moduleKind == ModuleKind.UMD) {
|
||||
val content = FileUtil.loadFile(outputFile, true)
|
||||
val wrappedContent = "if (typeof $KOTLIN_TEST_INTERNAL !== \"undefined\") { " +
|
||||
"$KOTLIN_TEST_INTERNAL.setModuleId(\"${StringUtil.escapeStringCharacters(config.moduleId)}\"); }\n" +
|
||||
"$content\n"
|
||||
FileUtil.writeToFile(outputFile, wrappedContent)
|
||||
}
|
||||
|
||||
processJsProgram(translationResult.program, psiFiles)
|
||||
}
|
||||
|
||||
+3
-4
@@ -28,7 +28,7 @@ object ModuleWrapperTranslation {
|
||||
program: JsProgram, kind: ModuleKind
|
||||
): List<JsStatement> {
|
||||
return when (kind) {
|
||||
ModuleKind.AMD -> wrapAmd(moduleId, function, importedModules, program)
|
||||
ModuleKind.AMD -> wrapAmd(function, importedModules, program)
|
||||
ModuleKind.COMMON_JS -> wrapCommonJs(function, importedModules, program)
|
||||
ModuleKind.UMD -> wrapUmd(moduleId, function, importedModules, program)
|
||||
ModuleKind.PLAIN -> wrapPlain(moduleId, function, importedModules, program)
|
||||
@@ -54,7 +54,7 @@ object ModuleWrapperTranslation {
|
||||
JsNameRef("amd", defineName.makeRef()))
|
||||
val commonJsTest = JsAstUtils.typeOfIs(exportsName.makeRef(), program.getStringLiteral("object"))
|
||||
|
||||
val amdBody = JsBlock(wrapAmd(moduleId, factoryName.makeRef(), importedModules, program))
|
||||
val amdBody = JsBlock(wrapAmd(factoryName.makeRef(), importedModules, program))
|
||||
val commonJsBody = JsBlock(wrapCommonJs(factoryName.makeRef(), importedModules, program))
|
||||
val plainInvocation = makePlainInvocation(moduleId, factoryName.makeRef(), importedModules, program)
|
||||
|
||||
@@ -78,13 +78,12 @@ object ModuleWrapperTranslation {
|
||||
}
|
||||
|
||||
private fun wrapAmd(
|
||||
moduleId: String, function: JsExpression,
|
||||
function: JsExpression,
|
||||
importedModules: List<StaticContext.ImportedModule>, program: JsProgram
|
||||
): List<JsStatement> {
|
||||
val scope = program.scope
|
||||
val defineName = scope.declareName("define")
|
||||
val invocationArgs = listOf(
|
||||
program.getStringLiteral(moduleId),
|
||||
JsArrayLiteral(listOf(program.getStringLiteral("exports")) + importedModules.map { program.getStringLiteral(it.externalName) }),
|
||||
function
|
||||
)
|
||||
|
||||
+10
@@ -1,6 +1,8 @@
|
||||
|
||||
var emulatedModules = { kotlin: kotlin };
|
||||
var module = { exports: {} };
|
||||
var currentModuleId;
|
||||
|
||||
|
||||
// TODO don't expose by default when run test with AMD module kind
|
||||
function require(moduleId) {
|
||||
@@ -14,11 +16,19 @@ var $kotlin_test_internal$ = {
|
||||
},
|
||||
endModule : function(moduleId) {
|
||||
emulatedModules[moduleId] = module.exports;
|
||||
},
|
||||
setModuleId: function(moduleId) {
|
||||
currentModuleId = moduleId;
|
||||
}
|
||||
};
|
||||
|
||||
// TODO expose only when run test with AMD or UMD module kind
|
||||
function define(moduleId, dependencies, body) {
|
||||
if (Array.isArray(moduleId)) {
|
||||
body = dependencies;
|
||||
dependencies = moduleId;
|
||||
moduleId = currentModuleId;
|
||||
}
|
||||
var resolvedDependencies = [];
|
||||
emulatedModules[moduleId] = {};
|
||||
for (var i = 0; i < dependencies.length; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user