<commit_before>'use strict';

require('node-define');

const RETRIES_COUNT = 5;

const fs = require('fs');
const path = require('path');
const async = require('async');

function getConnectorTestFilePath(connector) {
	var testFileName = path.basename(connector.js[0]);
	return path.join(__dirname, 'connectors', testFileName);
}

function getConnectorsList() {
	var connectors = require('../core/connectors');
	var uniqueConnectors = [];
	return connectors.filter(function(item) {
		var testFilePath = getConnectorTestFilePath(item);
		if (!fs.existsSync(testFilePath)) {
			return false;
		}

		if (uniqueConnectors.indexOf(testFilePath) !== -1) {
			return false;
		}
		uniqueConnectors.push(testFilePath);
		return true;
	}).sort(function(a, b) {
		return a.label.localeCompare(b.label);
	});
}

function getConnectorsToTest() {
	var connectors = getConnectorsList();
	var connectorsArgs = process.argv.slice(2);
	if (connectorsArgs.length > 0) {
		var invalidConnectors = [];

		connectors = connectors.filter(function(item) {
			var connectorFileName = path.basename(item.js[0], '.js');
			var fileNameIndex = connectorsArgs.indexOf(connectorFileName);
			if (fileNameIndex !== -1) {
				connectorsArgs.splice(fileNameIndex, 1);
				return true;
			}
			return false;
		});

		invalidConnectors = invalidConnectors.concat(connectorsArgs);
		if (invalidConnectors.length > 0) {
			console.warn('Unknown connectors: ' + invalidConnectors.join(', '));
		}
	}

	return connectors;
}

function getTestDescription(connector) {
	var connectorLabel = connector.label;
	if (global.DEBUG) {
		return 'Connector: ' + connectorLabel;
	} else {
		if (connectorLabel.length > 20) {
			connectorLabel = connectorLabel.substring(0, 20) + '…';
		}
		return '[' + connectorLabel + ']';
	}
}

function prepareTest(connector, driver, connectorSpec) {
	var testDescription = getTestDescription(connector);
	describe(testDescription, function() {
		if (!global.DEBUG) {
			this.retries(RETRIES_COUNT);
		}

		var connectorFilePath = getConnectorTestFilePath(connector);
		require(connectorFilePath)(driver, connectorSpec, connector);
	});
}

function runConnectorsTests() {
	var connectors = getConnectorsToTest();
	if (connectors.length > 0) {
		var driver = require('./helpers/webdriver-wrapper');
		var connectorSpec = require('./components/connector-spec.js');
<commit_msg>Use connector filename as test description<commit_after>'use strict';

require('node-define');

const RETRIES_COUNT = 5;

const fs = require('fs');
const path = require('path');
const async = require('async');

function getConnectorTestFilePath(connector) {
	var testFileName = path.basename(connector.js[0]);
	return path.join(__dirname, 'connectors', testFileName);
}

function getConnectorsList() {
	var connectors = require('../core/connectors');
	var uniqueConnectors = [];
	return connectors.filter(function(item) {
		var testFilePath = getConnectorTestFilePath(item);
		if (!fs.existsSync(testFilePath)) {
			return false;
		}

		if (uniqueConnectors.indexOf(testFilePath) !== -1) {
			return false;
		}
		uniqueConnectors.push(testFilePath);
		return true;
	}).sort(function(a, b) {
		return a.label.localeCompare(b.label);
	});
}

function getConnectorsToTest() {
	var connectors = getConnectorsList();
	var connectorsArgs = process.argv.slice(2);
	if (connectorsArgs.length > 0) {
		var invalidConnectors = [];

		connectors = connectors.filter(function(item) {
			var connectorFileName = path.basename(item.js[0], '.js');
			var fileNameIndex = connectorsArgs.indexOf(connectorFileName);
			if (fileNameIndex !== -1) {
				connectorsArgs.splice(fileNameIndex, 1);
				return true;
			}
			return false;
		});

		invalidConnectors = invalidConnectors.concat(connectorsArgs);
		if (invalidConnectors.length > 0) {
			console.warn('Unknown connectors: ' + invalidConnectors.join(', '));
		}
	}

	return connectors;
}

function getTestDescription(connector) {
	var filename = path.basename(connector.js[0], '.js');
	if (global.DEBUG) {
		return `Connector: ${filename}`;
	} else {
		return `[${filename}]`;
	}
}

function prepareTest(connector, driver, connectorSpec) {
	var testDescription = getTestDescription(connector);
	describe(testDescription, function() {
		if (!global.DEBUG) {
			this.retries(RETRIES_COUNT);
		}

		var connectorFilePath = getConnectorTestFilePath(connector);
		require(connectorFilePath)(driver, connectorSpec, connector);
	});
}

function runConnectorsTests() {
	var connectors = getConnectorsToTest();
	if (connectors.length > 0) {
		var driver = require('./helpers/webdriver-wrapper');
		var connectorSpec = require('./components/connector-spec.js');

{'fraction_non_alphanumeric': 0.1402452140245214, 'fraction_numerical': 0.005592600559260056, 'mean_word_length': 5.102362204724409, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5154115', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1409, 'n_words': 289}