From 589062a9500d889a8d328ff91cc185e6ec1fd127 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Mon, 18 Nov 2013 16:29:02 +0400 Subject: [PATCH] WEB-10010 Karma Server failure - WebStorm 7 & Jasmine --- lib/intellijReporter.js | 14 ++++---------- lib/tree.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/intellijReporter.js b/lib/intellijReporter.js index 0f0ddf3..cbde791 100644 --- a/lib/intellijReporter.js +++ b/lib/intellijReporter.js @@ -6,10 +6,9 @@ var cli = require("./intellijCli.js") function getOrCreateBrowserNode(tree, browser) { var configFileNode = tree.configFileNode; - var browserNode = configFileNode.lookupMap[browser.id]; + var browserNode = configFileNode.findChildNodeByKey(browser.id); if (!browserNode) { - browserNode = configFileNode.addChild(browser.name, true, 'browser', null); - configFileNode.lookupMap[browser.id] = browserNode; + browserNode = configFileNode.addChildWithKey(browser.id, browser.name, true, 'browser', null); browserNode.writeStartMessage(); } return browserNode; @@ -35,11 +34,10 @@ function getOrCreateLowerSuiteNode(browserNode, suiteNames, write) { write(message + '\n'); continue; } - var nextNode = node.lookupMap[suiteName]; + var nextNode = node.findChildNodeByKey(suiteName); if (!nextNode) { var locationHint = intellijUtil.joinList(suiteNames, 0, i + 1, '.'); nextNode = node.addChild(suiteName, true, 'suite', locationHint); - node.lookupMap[suiteName] = nextNode; nextNode.writeStartMessage(); } node = nextNode; @@ -48,14 +46,10 @@ function getOrCreateLowerSuiteNode(browserNode, suiteNames, write) { } function createSpecNode(suiteNode, suiteNames, specName) { - var specNode = suiteNode.lookupMap[specName]; - if (specNode) { - throw Error("Spec node is already created"); - } var names = suiteNames.slice(); names.push(specName); var locationHint = intellijUtil.joinList(names, 0, names.length, '.'); - specNode = suiteNode.addChild(specName, false, 'test', locationHint); + var specNode = suiteNode.addChild(specName, false, 'test', locationHint); specNode.writeStartMessage(); return specNode; } diff --git a/lib/tree.js b/lib/tree.js index 76646bd..22f99a6 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -121,6 +121,18 @@ function TestSuiteNode(tree, id, parentNode, name, type, locationHint) { inherit(TestSuiteNode, Node); +/** + * Returns child node by its name. + * @param childKey unique string that identifies this node (it can be node's name) + * @returns {?Node} child node (null, if no child node with such name found) + */ +TestSuiteNode.prototype.findChildNodeByKey = function(childKey) { + if (Object.prototype.hasOwnProperty.call(this.lookupMap, childKey)) { + return this.lookupMap[childKey]; + } + return null; +}; + TestSuiteNode.prototype.getStartCommandName = function () { return 'testSuiteStarted'; }; @@ -138,6 +150,19 @@ TestSuiteNode.prototype.getFinishCommandName = function () { * @returns {TestSuiteNode | TestNode} */ TestSuiteNode.prototype.addChild = function (childName, isChildSuite, nodeType, locationHint) { + return this.addChildWithKey(childName, childName, isChildSuite, nodeType, locationHint); +}; + +/** + * + * @param {String} childKey unique string that identifies this node (sometimes childName isn't enough) + * @param {String} childName node name (e.g. browser name / suite name / spec name) + * @param {Boolean} isChildSuite true if child node can have children + * @param {String} nodeType child node type (e.g. 'config', 'browser') + * @param {String} locationHint navigation info + * @returns {TestSuiteNode | TestNode} + */ +TestSuiteNode.prototype.addChildWithKey = function (childKey, childName, isChildSuite, nodeType, locationHint) { if (this.isFinished) { throw Error('Child node could be created for finished node!'); } @@ -150,6 +175,9 @@ TestSuiteNode.prototype.addChild = function (childName, isChildSuite, nodeType, child = new TestNode(this.tree, childId, this, childName, nodeType, locationHint); } this.children.push(child); + if (isChildSuite) { + this.lookupMap[childKey] = child; + } return child; };