KJS: introduce $kotlin_test_internal$ to expose some helper functions in the tests

This commit is contained in:
Zalim Bashorov
2017-01-17 22:46:56 +03:00
parent bbd69a05dc
commit ca2930600a
5 changed files with 22 additions and 13 deletions
@@ -22,5 +22,7 @@
}
global.define = define;
global.require = require;
global.$kotlin_test_internal$ = {
require : require
};
})(this);
@@ -228,9 +228,9 @@ abstract class BasicBoxTest(
if (config.moduleKind == ModuleKind.COMMON_JS) {
val content = FileUtil.loadFile(outputFile, true)
val wrappedContent = "__beginModule__();\n" +
val wrappedContent = "$KOTLIN_TEST_INTERNAL.beginModule();\n" +
"$content\n" +
"__endModule__(\"${StringUtil.escapeStringCharacters(config.moduleId)}\");"
"$KOTLIN_TEST_INTERNAL.endModule(\"${StringUtil.escapeStringCharacters(config.moduleId)}\");"
FileUtil.writeToFile(outputFile, wrappedContent)
}
@@ -337,5 +337,7 @@ abstract class BasicBoxTest(
private val NO_MODULE_SYSTEM_PATTERN = Pattern.compile("^// *NO_JS_MODULE_SYSTEM", Pattern.MULTILINE)
private val NO_INLINE_PATTERN = Pattern.compile("^// *NO_INLINE *$", Pattern.MULTILINE)
private val SKIP_NODE_JS = Pattern.compile("^// *SKIP_NODE_JS *$", Pattern.MULTILINE)
const val KOTLIN_TEST_INTERNAL = "\$kotlin_test_internal\$"
}
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.js.test.rhino;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.js.test.BasicBoxTest;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
@@ -70,7 +71,7 @@ public class RhinoFunctionResultChecker implements RhinoResultChecker {
StringBuilder sb = new StringBuilder();
if (withModuleSystem) {
sb.append("require('").append(moduleId).append("')");
sb.append(BasicBoxTest.KOTLIN_TEST_INTERNAL).append(".require('").append(moduleId).append("')");
}
else if (moduleId.contains(".")) {
sb.append("this['").append(moduleId).append("']");
@@ -1,4 +1,4 @@
__beginModule__();
$kotlin_test_internal$.beginModule();
module.exports = function(param) {
switch (typeof param) {
case "number":
@@ -9,4 +9,4 @@ module.exports = function(param) {
return "c";
}
};
__endModule__("lib");
$kotlin_test_internal$.endModule("lib");
+11 -7
View File
@@ -2,18 +2,22 @@
var emulatedModules = { kotlin: kotlin };
var module = { exports: {} };
// TODO don't expose by default when run test with AMD module kind
function require(moduleId) {
return emulatedModules[moduleId];
}
function __beginModule__() {
module.exports = {};
}
function __endModule__(moduleId) {
emulatedModules[moduleId] = module.exports;
}
var $kotlin_test_internal$ = {
require: require,
beginModule : function () {
module.exports = {};
},
endModule : function(moduleId) {
emulatedModules[moduleId] = module.exports;
}
};
// TODO expose only when run test with AMD or UMD module kind
function define(moduleId, dependencies, body) {
var resolvedDependencies = [];
emulatedModules[moduleId] = {};