Commit e92255d1 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Define config de test sólo para el task pedido

Evita procesamiento y comprobaciones innecesarias (y que bloquean el uso
normal de algunas tareas) a la hora de definir la configuración de tests
para diferentes tipos de pruebas y objetivos de ejecución, requiriendo y
procesando sólo aquellos recursos necesarios para la tarea de testeo que
ha solicitado el usuario.
parent 32645629
Loading
Loading
Loading
Loading
+113 −98
Original line number Diff line number Diff line
@@ -14,32 +14,19 @@ module.exports = function(grunt) {
			testPath = grunt.config('redmicConfig.testPath'),
			outputPath = 'test_reports',

			ownServerHost = grunt.option('ownServerHost') || '',
			ownServerPort = parseInt(grunt.option('ownServerPort'), 10) || 9000,
			ownSocketPort = parseInt(grunt.option('ownSocketPort'), 10),
			ownTunnelPort = parseInt(grunt.option('ownTunnelPort'), 10),
			browser = grunt.option('browser') || 'chrome',
			headless = grunt.option('headless') || false,
			grep = grunt.option('grep'),
			serverUrl = grunt.option('serverUrl'),
			role = grunt.option('role'),
			user = grunt.option('user'),
			pass = grunt.option('pass'),
			remoteHost = grunt.option('remoteHost'),
			remotePort = grunt.option('remotePort'),
			suitesGroups = grunt.option('suitesGroups'),
			suites = grunt.option('suites'),
			functionalSuites = grunt.option('functionalSuites'),
			coverage = grunt.option('coverage'),
			seleniumVersion = grunt.option('seleniumVersion'),
			chromeDriverVersion = grunt.option('chromeDriverVersion'),
			chromeBrowserVersion = grunt.option('chromeBrowserVersion'),
			firefoxDriverVersion = grunt.option('firefoxDriverVersion'),
			firefoxBrowserVersion = grunt.option('firefoxBrowserVersion'),

			currOutputDirName = gruntTaskName + '_on-port_' + ownServerPort,
			configDirName = '.config-' + ownServerPort,

			configPath = path.join(rootPath, outputPath, configDirName),
			reportersOutputPath = path.join(rootPath, outputPath, currOutputDirName),
			absoluteTestPath = path.join(rootPath, testPath),
@@ -49,12 +36,6 @@ module.exports = function(grunt) {
		grunt.file['delete'](reportersOutputPath);
		grunt.file.mkdir(reportersOutputPath);

		if (!coverage && coverage === undefined) {
			coverage = [
				path.join(srcPath, '**', '*.js')
			];
		}

		var commonReporters = [{
			name: 'runner'
		},{
@@ -67,33 +48,20 @@ module.exports = function(grunt) {
			options: {
				filename: path.join(reportersOutputPath, 'runner.xml')
			}
			}],
		}];

			unitReporters = [{
				name: 'lcov',
				options: {
					directory: reportersOutputPath,
					filename: 'lcov.info'
				}
			},{
				name: 'htmlcoverage',
				options: {
					directory: reportersOutputPath
		var testPaths = {
			unit: {
				local: path.join(absoluteTestPath, 'intern-unit-local'),
				remote: path.join(absoluteTestPath, 'intern-unit-remote')
			},
			functional: {
				local: path.join(absoluteTestPath, 'intern-functional-local'),
				remote: path.join(absoluteTestPath, 'intern-functional-remote')
			}
			}].concat(commonReporters),

			functionalReporters = [].concat(commonReporters),

			testUnitLocalPath = path.join(absoluteTestPath, 'intern-unit-local'),
			testUnitRemotePath = path.join(absoluteTestPath, 'intern-unit-remote'),
			testFunctionalLocalPath = path.join(absoluteTestPath, 'intern-functional-local'),
			testFunctionalRemotePath = path.join(absoluteTestPath, 'intern-functional-remote'),

			ipGetterPath = path.join(absoluteTestPath, 'IpGetter'),
			IpGetter = require(ipGetterPath)(),
			localIp = IpGetter.getIp(),
		};

			testParams = {
		var testParams = {
			srcPath: srcPath,
			testPath: testPath,
			ownServerPort: ownServerPort,
@@ -107,23 +75,85 @@ module.exports = function(grunt) {
			seleniumVersion: seleniumVersion,
			chromeBrowserVersion: chromeBrowserVersion,
			firefoxBrowserVersion: firefoxBrowserVersion
			},
			localTestParams = {
		};

		var testTargetName, testTargetConfig, testTypeName, testTypeConfig;

		var localTargetName = 'local';
		if (gruntTaskName.includes(localTargetName)) {
			var chromeDriverVersion = grunt.option('chromeDriverVersion'),
				firefoxDriverVersion = grunt.option('firefoxDriverVersion');

			testTargetName = localTargetName;
			testTargetConfig = {
				chromeDriverVersion: chromeDriverVersion,
				firefoxDriverVersion: firefoxDriverVersion
			},
			remoteTestParams = {
			};
		}

		var remoteTargetName = 'remote';
		if (gruntTaskName.includes(remoteTargetName)) {
			var ownServerHost = grunt.option('ownServerHost') || '',
				remoteHost = grunt.option('remoteHost'),
				remotePort = grunt.option('remotePort');

			var ipGetterPath = path.join(absoluteTestPath, 'IpGetter'),
				IpGetter = require(ipGetterPath)();

			testTargetName = remoteTargetName;
			testTargetConfig = {
				ownServerHost: ownServerHost,
				remoteHost: remoteHost,
				remotePort: remotePort,
				localIp: localIp
			},
			testUnitParams = deepmerge(testParams, {
				localIp: IpGetter.getIp()
			};
		}

		var unitTypeName = 'unit';
		if (gruntTaskName.includes(unitTypeName)) {
			var suites = grunt.option('suites'),
				coverage = grunt.option('coverage');

			var coveragePaths;
			if (!coverage && coverage === undefined) {
				coveragePaths = [
					path.join(srcPath, '**', '*.js')
				];
			}

			var unitReporters = [{
				name: 'lcov',
				options: {
					directory: reportersOutputPath,
					filename: 'lcov.info'
				}
			},{
				name: 'htmlcoverage',
				options: {
					directory: reportersOutputPath
				}
			}].concat(commonReporters);

			testTypeName = unitTypeName;
			testTypeConfig = deepmerge(testParams, {
				reporters: unitReporters,
				suites: suites,
				coverage: coverage
			}),
			testFunctionalParams = deepmerge(testParams, {
				coverage: coveragePaths
			});
		}

		var functionalTypeName = 'functional';
		if (gruntTaskName.includes(functionalTypeName)) {
			var serverUrl = grunt.option('serverUrl'),
				role = grunt.option('role'),
				user = grunt.option('user'),
				pass = grunt.option('pass'),
				functionalSuites = grunt.option('functionalSuites');

			var functionalReporters = [].concat(commonReporters);

			testTypeName = functionalTypeName;
			testTypeConfig = deepmerge(testParams, {
				serverUrl: serverUrl,
				role: role,
				user: user,
@@ -132,33 +162,18 @@ module.exports = function(grunt) {
				functionalSuites: functionalSuites,
				reportersOutputPath: reportersOutputPath,
				dojoBaseUrlPrefix: '.'
			}),

			testUnitLocalOptions = require(testUnitLocalPath)(
				deepmerge(testUnitParams, localTestParams)),

			testUnitRemoteOptions = require(testUnitRemotePath)(
				deepmerge(testUnitParams, remoteTestParams)),
			});
		}

			testFunctionalLocalOptions = require(testFunctionalLocalPath)(
				deepmerge(testFunctionalParams, localTestParams)),
		var testTaskName = ['test', testTypeName, testTargetName].join('-'),
			testDefinitionPath = testPaths[testTypeName][testTargetName],
			testTaskOptions = require(testDefinitionPath)(deepmerge.all([
				testParams, testTypeConfig, testTargetConfig
			])),
			internGruntConfig = {};

			testFunctionalRemoteOptions = require(testFunctionalRemotePath)(
				deepmerge(testFunctionalParams, remoteTestParams));
		internGruntConfig[testTaskName] = { options: testTaskOptions };

		grunt.config('intern', {
			'test-unit-local': {
				options: testUnitLocalOptions
			},
			'test-functional-local': {
				options: testFunctionalLocalOptions
			},
			'test-unit-remote': {
				options: testUnitRemoteOptions
			},
			'test-functional-remote': {
				options: testFunctionalRemoteOptions
			}
		});
		grunt.config('intern', internGruntConfig);
	});
};