From 2c10f253c5c9b1a05261e6a69cec864e3504876f Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 24 Apr 2017 19:17:33 +0300 Subject: [PATCH] Fix node.js tests on Windows agents in Teamcity --- .../jetbrains/kotlin/js/test/BasicBoxTest.kt | 4 +-- js/js.translator/testData/package.json | 3 ++ js/js.translator/testData/test.js | 33 ++++++++++--------- node_utils.xml | 9 ++--- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt index 31af730f1fd..74d352d03db 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -176,7 +176,7 @@ abstract class BasicBoxTest( ignored: Boolean, testPackage: String? ): String { - val filesToLoad = files.map { FileUtil.getRelativePath(dir, File(it))!! }.map { "\"$it\"" } + val filesToLoad = files.map { FileUtil.getRelativePath(dir, File(it))!!.replace(File.separatorChar, '/') }.map { "\"$it\"" } val fqn = testPackage?.let { ".$it" } ?: "" val loadAndRun = "load([${filesToLoad.joinToString(",")}], '$moduleName')$fqn.box()" diff --git a/js/js.translator/testData/package.json b/js/js.translator/testData/package.json index 1f714e3c093..2ec8d68df11 100644 --- a/js/js.translator/testData/package.json +++ b/js/js.translator/testData/package.json @@ -5,5 +5,8 @@ "devDependencies" : { "mocha": "3.2.0", "mocha-teamcity-reporter": "1.1.1" + }, + "scripts": { + "test": "mocha --reporter mocha-teamcity-reporter" } } \ No newline at end of file diff --git a/js/js.translator/testData/test.js b/js/js.translator/testData/test.js index 2d28abc7e40..3b718a4fe24 100644 --- a/js/js.translator/testData/test.js +++ b/js/js.translator/testData/test.js @@ -1,7 +1,11 @@ "use strict"; +var path = require('path'); +var assert = require('assert'); +var fs = require('fs'); + (function () { - var kotlinJsLocation = process.env.KOTLIN_JS_LOCATION || __dirname + "/../../../dist/js/kotlin.js"; + var kotlinJsLocation = process.env.KOTLIN_JS_LOCATION || path.resolve(__dirname, "../../../dist/js/kotlin.js"); var Module = require('module'); var originalRequire = Module.prototype.require; @@ -13,10 +17,7 @@ }; })(); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); -var kotlinJsTestLocation = process.env.KOTLIN_JS_TEST_LOCATION || __dirname + "/../../../dist/js/kotlin-test.js"; +var kotlinJsTestLocation = process.env.KOTLIN_JS_TEST_LOCATION || path.resolve(__dirname, "../../../dist/js/kotlin-test.js"); var kotlin = require("kotlin"); var kotlinTest = require(kotlinJsTestLocation); @@ -25,15 +26,15 @@ var requireFromString = require('require-from-string'); var baseDir = "out"; var model = generateModel(baseDir); -exposeModel(model, "./" + baseDir); +exposeModel(model, path.resolve(baseDir)); -function exposeModel(model, path) { +function exposeModel(model, currentPath) { for (var property in model) { if (!model.hasOwnProperty(property)) { continue; } - var childPath = path + "/" + property; + var childPath = path.join(currentPath, property); var item = model[property]; describe(property, function(childPath, item) { return function() { @@ -52,18 +53,18 @@ function exposeModel(model, path) { } /** - * @param path String + * @param currentPath String * @returns String|{} */ -function generateModel(path) { - var stats = fs.statSync(path); +function generateModel(currentPath) { + var stats = fs.statSync(currentPath); if (stats.isDirectory()) { var result = {}; - var files = fs.readdirSync(path); + var files = fs.readdirSync(currentPath); var empty = true; for (var i = 0; i < files.length; ++i) { var child = files[i]; - var childModel = generateModel(path + "/" + child); + var childModel = generateModel(path.join(currentPath, child)); if (childModel !== void 0) { result[child] = childModel; empty = false; @@ -72,8 +73,8 @@ function generateModel(path) { return !empty ? result : void 0; } else if (stats.isFile()) { - if (path.endsWith(".node.js")) { - return path; + if (currentPath.endsWith(".node.js")) { + return currentPath; } else { return void 0; @@ -92,7 +93,7 @@ function runTest(testRunner, location) { text += 'module.exports = function(kotlin) {\n'; text += "var exports = void 0;"; for (var i = 0; i < fileNames.length; ++i) { - text += fs.readFileSync(basePath + "/" + fileNames[i]) + "\n"; + text += fs.readFileSync(path.resolve(basePath, fileNames[i])) + "\n"; } text += 'var resultModule = typeof emulatedModules != "undefined" ? emulatedModules.' + moduleName + ' : null;\n'; text += "resultModule = resultModule || this." + moduleName + ";\n"; diff --git a/node_utils.xml b/node_utils.xml index ff4965f82e9..165db4b00bd 100644 --- a/node_utils.xml +++ b/node_utils.xml @@ -44,9 +44,11 @@ + + @@ -122,9 +124,8 @@ - - - - + + +