You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.4 KiB
69 lines
1.4 KiB
const path = require('path');
|
|
|
|
|
|
/**
|
|
* @param {string} testFilePath
|
|
* @return {string}
|
|
*/
|
|
const createNameForFileNode = testFilePath => path.basename(testFilePath);
|
|
|
|
/**
|
|
* @typedef {import('../../../../../JavaScriptLanguage/resources/helpers/base-test-reporter/intellij-tree.js').Tree} BaseReporterTestsTree
|
|
*/
|
|
|
|
class FileNodes {
|
|
/**
|
|
* @type {Object<string, TestSuiteNode>}
|
|
* @private
|
|
* */
|
|
_suitesByFilePaths = {};
|
|
/**
|
|
* @type {TestSuiteNode|null}
|
|
* @private
|
|
*/
|
|
_lastFileNode = null;
|
|
|
|
/**
|
|
* @param {BaseReporterTestsTree} tree
|
|
*/
|
|
constructor(tree) {
|
|
/**
|
|
* @type {BaseReporterTestsTree}
|
|
* @private
|
|
*/
|
|
this._tree = tree;
|
|
}
|
|
|
|
/**
|
|
* @param {string} testFilePath
|
|
* @return {TestSuiteNode}
|
|
*/
|
|
getFor(testFilePath) {
|
|
let fileNode = this._suitesByFilePaths[testFilePath];
|
|
|
|
if (!fileNode) {
|
|
fileNode = this._tree.root.addTestSuiteChild(createNameForFileNode(testFilePath), 'file', testFilePath);
|
|
this._suitesByFilePaths[testFilePath] = fileNode;
|
|
fileNode.start();
|
|
}
|
|
|
|
if (this._lastFileNode && this._lastFileNode !== fileNode) {
|
|
this._lastFileNode.finish(false);
|
|
}
|
|
this._lastFileNode = fileNode;
|
|
|
|
return fileNode;
|
|
}
|
|
|
|
finishLast() {
|
|
if (this._lastFileNode && !this._lastFileNode.isFinished()) {
|
|
this._lastFileNode.finish(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
FileNodes,
|
|
createNameForFileNode,
|
|
};
|