mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
Add an ability to run/debug ir tests inside node.js (even from IDEA)
This commit is contained in:
13
.idea/runConfigurations/run_IR_test_in_node_js.xml
generated
Normal file
13
.idea/runConfigurations/run_IR_test_in_node_js.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="run IR test in node.js" type="js.build_tools.npm">
|
||||
<package-json value="$PROJECT_DIR$/js/js.translator/testData/package.json" />
|
||||
<command value="run" />
|
||||
<scripts>
|
||||
<script value="runIrTestInNode" />
|
||||
</scripts>
|
||||
<arguments value="$FilePath$" />
|
||||
<node-interpreter value="project" />
|
||||
<envs />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
3
js/js.translator/testData/package.json
vendored
3
js/js.translator/testData/package.json
vendored
@@ -8,6 +8,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"runOnTeamcity": "mocha --reporter mocha-teamcity-reporter",
|
||||
"test": "mocha"
|
||||
"test": "mocha",
|
||||
"runIrTestInNode" : "node $NODE_DEBUG_OPTION runIrTestInNode.js"
|
||||
}
|
||||
}
|
||||
|
||||
46
js/js.translator/testData/runIrTestInNode.js
vendored
Normal file
46
js/js.translator/testData/runIrTestInNode.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
// Note right now it works only for IR tests.
|
||||
// With IDEA 2018.3 or later you can just activate required js and run "run IR test in node.js" configuration.
|
||||
|
||||
// Add to this array your path to test files or provide it as argument.
|
||||
var anotherFiles = [""];
|
||||
|
||||
var vm = require('vm');
|
||||
var fs = require('fs');
|
||||
|
||||
// Change working dir to root of project
|
||||
var testDataPathFromRoot = "js/js.translator/testData";
|
||||
var cwd = process.cwd();
|
||||
if (cwd.endsWith(testDataPathFromRoot)) {
|
||||
process.chdir(cwd.substr(0, cwd.length - testDataPathFromRoot.length));
|
||||
}
|
||||
|
||||
var runtimeFiles = ["js/js.translator/testData/out/irBox/testRuntime.js"];
|
||||
var filesFromArgs = process.argv.slice(2);
|
||||
|
||||
// TODO autodetect common js files and other js files
|
||||
// Filter out all except existing js files and transform all paths to absolute
|
||||
var files = [].concat(runtimeFiles, filesFromArgs, anotherFiles)
|
||||
.map(function(path) {
|
||||
if (fs.existsSync(path) && fs.statSync(path).isFile()) {
|
||||
return fs.realpathSync(path)
|
||||
}
|
||||
|
||||
return "";
|
||||
})
|
||||
.filter(function(path) {
|
||||
return path.endsWith(".js")
|
||||
});
|
||||
|
||||
// Evaluate files and run box function
|
||||
|
||||
var sandbox = {};
|
||||
vm.createContext(sandbox);
|
||||
|
||||
files.forEach(function(path) {
|
||||
var code = fs.readFileSync(path, 'utf8');
|
||||
vm.runInContext(code, sandbox, {
|
||||
filename: path
|
||||
})
|
||||
});
|
||||
|
||||
console.log(vm.runInContext("box()", sandbox));
|
||||
Reference in New Issue
Block a user