From fa268c085d76d36a006dc4e518f0ccd28432c78a Mon Sep 17 00:00:00 2001 From: siddhap Date: Mon, 5 Jun 2017 20:42:43 +0530 Subject: [PATCH 1/7] commit for custom map support --- Tasks/VsTest/make.json | 2 +- Tasks/VsTest/models.ts | 2 ++ Tasks/VsTest/settingshelper.ts | 2 +- Tasks/VsTest/task.json | 2 +- Tasks/VsTest/task.loc.json | 2 +- Tasks/VsTest/taskinputparser.ts | 11 +++++++++++ 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Tasks/VsTest/make.json b/Tasks/VsTest/make.json index e7b90c3e607a..c2c5406a08f8 100644 --- a/Tasks/VsTest/make.json +++ b/Tasks/VsTest/make.json @@ -2,7 +2,7 @@ "externals": { "archivePackages": [ { - "url": "https://testselector.blob.core.windows.net/testselector/3843116/TestSelector.zip", + "url": "https://testselector.blob.core.windows.net/testselector/3922827/TestSelector.zip", "dest": "./" }, { diff --git a/Tasks/VsTest/models.ts b/Tasks/VsTest/models.ts index 09fa8fdc487a..c8324c0fc233 100644 --- a/Tasks/VsTest/models.ts +++ b/Tasks/VsTest/models.ts @@ -61,4 +61,6 @@ export interface TiaConfiguration { isPrFlow: string; context: string; useTestCaseFilterInResponseFile: string; + userMapFile: string; + disableEnablingDataCollector: boolean; } diff --git a/Tasks/VsTest/settingshelper.ts b/Tasks/VsTest/settingshelper.ts index 487ab9d76c27..5cc94953e523 100644 --- a/Tasks/VsTest/settingshelper.ts +++ b/Tasks/VsTest/settingshelper.ts @@ -122,7 +122,7 @@ export async function updateSettingsFileAsRequired(settingsFile: string, isParal } } - if (tiaConfig.tiaEnabled) { + if (tiaConfig.tiaEnabled && !tiaConfig.disableEnablingDataCollector) { let testImpactCollectorNode = null; parser.parseString(testImpactDataCollectorTemplate, function(err, data) { if (err) { diff --git a/Tasks/VsTest/task.json b/Tasks/VsTest/task.json index c7a3d373d4b6..c957714b08dc 100644 --- a/Tasks/VsTest/task.json +++ b/Tasks/VsTest/task.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 50 + "Patch": 53 }, "demands": [ "vstest" diff --git a/Tasks/VsTest/task.loc.json b/Tasks/VsTest/task.loc.json index fb2b30b80116..b00fc99c4179 100644 --- a/Tasks/VsTest/task.loc.json +++ b/Tasks/VsTest/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 50 + "Patch": 53 }, "demands": [ "vstest" diff --git a/Tasks/VsTest/taskinputparser.ts b/Tasks/VsTest/taskinputparser.ts index cff1185468db..5b2b1aec64a4 100644 --- a/Tasks/VsTest/taskinputparser.ts +++ b/Tasks/VsTest/taskinputparser.ts @@ -225,5 +225,16 @@ function getTiaConfiguration(): models.TiaConfiguration { if (releaseuri) { tiaConfiguration.context = 'CD'; } + + // User map file + tiaConfiguration.userMapFile = tl.getVariable('tia.usermapfile'); + + // disable editing settings file to switch on data collector + if (tl.getVariable('tia.disabledatacollector') && tl.getVariable('tia.disabledatacollector').toUpperCase() === 'TRUE') { + tiaConfiguration.disableEnablingDataCollector = true; + } else { + tiaConfiguration.disableEnablingDataCollector = false; + } + return tiaConfiguration; } \ No newline at end of file From 96d133eb3f804f5fef4d59713c1cf2d664722208 Mon Sep 17 00:00:00 2001 From: siddhap Date: Mon, 5 Jun 2017 20:43:21 +0530 Subject: [PATCH 2/7] added vstest.ts --- Tasks/VsTest/vstest.ts | 76 ++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/Tasks/VsTest/vstest.ts b/Tasks/VsTest/vstest.ts index be5a1bce25cb..e1e4801cd84d 100644 --- a/Tasks/VsTest/vstest.ts +++ b/Tasks/VsTest/vstest.ts @@ -113,7 +113,7 @@ function getVstestArguments(settingsFile: string, tiaEnabled: boolean): string[] argsArray.push('/Settings:' + settingsFile); utils.Helper.readFileContents(settingsFile, 'utf-8').then(function (settings) { tl.debug('Running VsTest with settings : '); - utils.Helper.printMultiLineLog(settings, (logLine) => {tl._outStream.write('##vso[task.debug]' + logLine);}); + utils.Helper.printMultiLineLog(settings, (logLine) => { tl._outStream.write('##vso[task.debug]' + logLine); }); }); } else { if (!tl.exist(settingsFile)) { // because this is filepath input build puts default path in the input. To avoid that we are checking this. @@ -133,8 +133,8 @@ function getVstestArguments(settingsFile: string, tiaEnabled: boolean): string[] argsArray.push('/logger:trx'); if (utils.Helper.isNullOrWhitespace(vstestConfig.pathtoCustomTestAdapters)) { if (systemDefaultWorkingDirectory && isTestAdapterPresent(vstestConfig.testDropLocation)) { - argsArray.push('/TestAdapterPath:\"' + systemDefaultWorkingDirectory + '\"'); - } + argsArray.push('/TestAdapterPath:\"' + systemDefaultWorkingDirectory + '\"'); + } } else { argsArray.push('/TestAdapterPath:\"' + vstestConfig.pathtoCustomTestAdapters + '\"'); } @@ -161,7 +161,7 @@ function isDebugEnabled(): boolean { function addVstestArgs(argsArray: string[], vstest: any) { argsArray.forEach(function (arr: any) { - vstest.arg(arr); + vstest.arg(arr); }); } @@ -241,7 +241,7 @@ function uploadTestResults(testResultsDirectory: string): Q.Promise { return defer.promise; } -function generateResponseFile(discoveredTests: string): Q.Promise { +function generateResponseFile(discoveredTests: string, testCaseFilterOutputFile: string): Q.Promise { const startTime = perf(); let endTime: number; let elapsedTime: number; @@ -257,6 +257,8 @@ function generateResponseFile(discoveredTests: string): Q.Promise { const selectortool = tl.tool(getTestSelectorLocation()); selectortool.arg('GetImpactedtests'); + + if (tiaConfig.context === 'CD') { // Release context. Passing Release Id. definitionRunId = tl.getVariable('Release.ReleaseId'); @@ -306,7 +308,8 @@ function generateResponseFile(discoveredTests: string): Q.Promise { 'context': tiaConfig.context, 'platform': platformInput, 'configuration': configurationInput, - 'useTestCaseFilterInResponseFile': useTestCaseFilterInResponseFile + 'useTestCaseFilterInResponseFile': useTestCaseFilterInResponseFile, + 'TestCaseFilterOutputFile' : testCaseFilterOutputFile ? testCaseFilterOutputFile : "" }, silent: null, failOnStdErr: null, @@ -328,7 +331,7 @@ function generateResponseFile(discoveredTests: string): Q.Promise { return defer.promise; } -function publishCodeChanges(): Q.Promise { +function publishCodeChanges(testCaseFilterFile: string): Q.Promise { const startTime = perf(); let endTime: number; let elapsedTime: number; @@ -394,7 +397,9 @@ function publishCodeChanges(): Q.Promise { 'rebaselimit': rebaseLimit, 'baselinefile': tiaConfig.baseLineBuildIdFile, 'context': tiaConfig.context, - 'filter': pathFilters + 'filter': pathFilters, + 'UserMapFile': tiaConfig.userMapFile ? tiaConfig.userMapFile : "", + 'testCaseFilterResponseFile': testCaseFilterFile ? testCaseFilterFile : "" }, silent: null, failOnStdErr: null, @@ -467,9 +472,9 @@ function executeVstest(testResultsDirectory: string, parallelRunSettingsFile: st return defer.promise; } -function getVstestTestsList(vsVersion: number): Q.Promise { +function getVstestTestsListInternal(vsVersion: number, testCaseFilter: string, outputFile: string): Q.Promise { const defer = Q.defer(); - const tempFile = path.join(os.tmpdir(), uuid.v1() + '.txt'); + const tempFile = outputFile; tl.debug('Discovered tests listed at: ' + tempFile); const argsArray: string[] = []; @@ -488,8 +493,8 @@ function getVstestTestsList(vsVersion: number): Q.Promise { argsArray.push('/ListFullyQualifiedTests'); argsArray.push('/ListTestsTargetPath:' + tempFile); - if (vstestConfig.testcaseFilter) { - argsArray.push('/TestCaseFilter:' + vstestConfig.testcaseFilter); + if (testCaseFilter) { + argsArray.push('/TestCaseFilter:' + testCaseFilter); } if (vstestConfig.pathtoCustomTestAdapters) { if (pathExistsAsDirectory(vstestConfig.pathtoCustomTestAdapters)) { @@ -527,13 +532,26 @@ function getVstestTestsList(vsVersion: number): Q.Promise { return defer.promise; } -function cleanFiles(responseFile: string, listFile: string): void { +function getVstestTestsList(vsVersion: number): Q.Promise { + const defer = Q.defer(); + const tempFile = path.join(os.tmpdir(), uuid.v1() + '.txt'); + tl.debug('Discovered tests listed at: ' + tempFile); + const argsArray: string[] = []; + + return getVstestTestsListInternal(vsVersion, vstestConfig.testcaseFilter, tempFile); +} + +function cleanFiles(responseFile: string, listFile: string, testCaseFilterFile: string, testCaseFilterOutput: string): void { tl.debug('Deleting the response file ' + responseFile); tl.rmRF(responseFile, true); tl.debug('Deleting the discovered tests file ' + listFile); tl.rmRF(listFile, true); tl.debug('Deleting the baseline build id file ' + tiaConfig.baseLineBuildIdFile); tl.rmRF(tiaConfig.baseLineBuildIdFile, true); + tl.debug('Deleting test case filter file ' + testCaseFilterFile); + tl.rmRF(testCaseFilterFile, true); + tl.debug('Deleting test case filter output file' + testCaseFilterOutput); + tl.rmRF(testCaseFilterOutput, true); } function deleteVstestDiagFile(): void { @@ -543,14 +561,28 @@ function deleteVstestDiagFile(): void { } } +function discoverTestFromFilteredFilter(vsVersion: number, testCaseFilterFile: string, testCaseFilterOutput: string) { + if (utils.Helper.pathExistsAsFile(testCaseFilterFile)) { + let filters = utils.Helper.readFileContentsSync(testCaseFilterFile, 'utf-8'); + getVstestTestsListInternal(vsVersion, filters, testCaseFilterOutput); + } +} + function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion: number): Q.Promise { const defer = Q.defer(); if (isTiaAllowed()) { - publishCodeChanges() + let testCaseFilterFile = ""; + let testCaseFilterOutput = ""; + if (tiaConfig.userMapFile) { + testCaseFilterFile = path.join(os.tmpdir(), uuid.v1() + '.txt'); + testCaseFilterOutput = path.join(os.tmpdir(), uuid.v1() + '.txt'); + } + publishCodeChanges(testCaseFilterFile) .then(function (status) { getVstestTestsList(vsVersion) .then(function (listFile) { - generateResponseFile(listFile) + discoverTestFromFilteredFilter(vsVersion, testCaseFilterFile, testCaseFilterOutput); + generateResponseFile(listFile, testCaseFilterOutput) .then(function (responseFile) { if (isEmptyResponseFile(responseFile)) { tl.debug('Empty response file detected. All tests will be executed.'); @@ -571,7 +603,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion defer.resolve(1); }) .finally(function () { - cleanFiles(responseFile, listFile); + cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput); tl.debug('Deleting the run id file' + tiaConfig.runIdFile); tl.rmRF(tiaConfig.runIdFile, true); }); @@ -580,7 +612,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion defer.resolve(code); }) .finally(function () { - cleanFiles(responseFile, listFile); + cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput); }); } else { responseContainsNoTests(responseFile) @@ -599,7 +631,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion defer.resolve(1); }) .finally(function () { - cleanFiles(responseFile, listFile); + cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput); tl.debug('Deleting the run id file' + tiaConfig.runIdFile); tl.rmRF(tiaConfig.runIdFile, true); }); @@ -623,7 +655,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion defer.resolve(1); }) .finally(function () { - cleanFiles(responseFile, listFile); + cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput); tl.debug('Deleting the run id file' + tiaConfig.runIdFile); tl.rmRF(tiaConfig.runIdFile, true); }); @@ -632,7 +664,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion defer.resolve(code); }) .finally(function () { - cleanFiles(responseFile, listFile); + cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput); }); }) .fail(function (err) { @@ -655,7 +687,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion defer.resolve(1); }) .finally(function () { - cleanFiles(responseFile, listFile); + cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput); tl.debug('Deleting the run id file' + tiaConfig.runIdFile); tl.rmRF(tiaConfig.runIdFile, true); }); @@ -663,7 +695,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion .fail(function (code) { defer.resolve(code); }).finally(function () { - cleanFiles(responseFile, listFile); + cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput); }); }) .fail(function (err) { From dadc25cf8cd79e49f3b22c0b096cf568a4ce5576 Mon Sep 17 00:00:00 2001 From: siddhap Date: Fri, 9 Jun 2017 13:27:58 +0530 Subject: [PATCH 3/7] fix check for empty response file --- Tasks/VsTest/vstest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/Tasks/VsTest/vstest.ts b/Tasks/VsTest/vstest.ts index 3eb9f18d57dd..c03089ec8589 100644 --- a/Tasks/VsTest/vstest.ts +++ b/Tasks/VsTest/vstest.ts @@ -946,7 +946,6 @@ function getTIALevel() { function responseContainsNoTests(filePath: string): Q.Promise { return utils.Helper.readFileContents(filePath, 'utf-8').then(function (resp) { - if (resp === '/Tests:' || resp === '/TestCaseFilter:') { return true; } else { From 13e49c96606b80078c73d267ccabc6ea1cca2502 Mon Sep 17 00:00:00 2001 From: siddhap Date: Fri, 9 Jun 2017 16:08:15 +0530 Subject: [PATCH 4/7] fix for empty response file --- Tasks/VsTest/vstest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/Tasks/VsTest/vstest.ts b/Tasks/VsTest/vstest.ts index c03089ec8589..367d6c57dcae 100644 --- a/Tasks/VsTest/vstest.ts +++ b/Tasks/VsTest/vstest.ts @@ -946,6 +946,7 @@ function getTIALevel() { function responseContainsNoTests(filePath: string): Q.Promise { return utils.Helper.readFileContents(filePath, 'utf-8').then(function (resp) { + if (resp === '/Tests:\"' || resp === '/Tests:' || resp === '/TestCaseFilter:') { return true; } else { From baa759b1eb12b012e399e4b7bb4d82d9b0a044fe Mon Sep 17 00:00:00 2001 From: siddhap Date: Mon, 12 Jun 2017 20:50:37 +0530 Subject: [PATCH 5/7] pr --- Tasks/VsTest/taskinputparser.ts | 2 +- Tasks/VsTest/vstest.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tasks/VsTest/taskinputparser.ts b/Tasks/VsTest/taskinputparser.ts index c01e488afc51..823391f89f8f 100644 --- a/Tasks/VsTest/taskinputparser.ts +++ b/Tasks/VsTest/taskinputparser.ts @@ -237,7 +237,7 @@ function getTiaConfiguration(): models.TiaConfiguration { tiaConfiguration.userMapFile = tl.getVariable('tia.usermapfile'); // disable editing settings file to switch on data collector - if (tl.getVariable('tia.disabledatacollector') && tl.getVariable('tia.disabledatacollector').toUpperCase() === 'TRUE') { + if (tl.getVariable('tia.disabletiadatacollector') && tl.getVariable('tia.disabletiadatacollector').toUpperCase() === 'TRUE') { tiaConfiguration.disableEnablingDataCollector = true; } else { tiaConfiguration.disableEnablingDataCollector = false; diff --git a/Tasks/VsTest/vstest.ts b/Tasks/VsTest/vstest.ts index 367d6c57dcae..3eb9f18d57dd 100644 --- a/Tasks/VsTest/vstest.ts +++ b/Tasks/VsTest/vstest.ts @@ -946,7 +946,7 @@ function getTIALevel() { function responseContainsNoTests(filePath: string): Q.Promise { return utils.Helper.readFileContents(filePath, 'utf-8').then(function (resp) { - if (resp === '/Tests:\"' || resp === '/Tests:' || resp === '/TestCaseFilter:') { + if (resp === '/Tests:' || resp === '/TestCaseFilter:') { return true; } else { From acc486f4a8d888e6b2dd4d0fde335ba82b0d8dec Mon Sep 17 00:00:00 2001 From: siddhap Date: Mon, 12 Jun 2017 20:51:58 +0530 Subject: [PATCH 6/7] commmit --- Tasks/VsTest/task.json | 4 ++-- Tasks/VsTest/task.loc.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tasks/VsTest/task.json b/Tasks/VsTest/task.json index 9ed6569c01d0..e1275a40dffe 100644 --- a/Tasks/VsTest/task.json +++ b/Tasks/VsTest/task.json @@ -1,4 +1,4 @@ -{ +{ "id": "EF087383-EE5E-42C7-9A53-AB56C98420F9", "name": "VSTest", "friendlyName": "Visual Studio Test", @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 57 + "Patch": 56 }, "demands": [ "vstest" diff --git a/Tasks/VsTest/task.loc.json b/Tasks/VsTest/task.loc.json index 59507b387e96..e5017f5cdf84 100644 --- a/Tasks/VsTest/task.loc.json +++ b/Tasks/VsTest/task.loc.json @@ -17,7 +17,7 @@ "version": { "Major": 2, "Minor": 0, - "Patch": 57 + "Patch": 56 }, "demands": [ "vstest" From 8eec62e1f7046b698d0b97002bc8a6c44eb25d7f Mon Sep 17 00:00:00 2001 From: siddhap Date: Mon, 12 Jun 2017 22:54:55 +0530 Subject: [PATCH 7/7] fixes --- Tasks/VsTest/vstest.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Tasks/VsTest/vstest.ts b/Tasks/VsTest/vstest.ts index 3eb9f18d57dd..6ae2f939d931 100644 --- a/Tasks/VsTest/vstest.ts +++ b/Tasks/VsTest/vstest.ts @@ -255,8 +255,6 @@ function generateResponseFile(discoveredTests: string, testCaseFilterOutputFile: const selectortool = tl.tool(getTestSelectorLocation()); selectortool.arg('GetImpactedtests'); - - if (tiaConfig.context === 'CD') { // Release context. Passing Release Id. definitionRunId = tl.getVariable('Release.ReleaseId'); @@ -307,7 +305,8 @@ function generateResponseFile(discoveredTests: string, testCaseFilterOutputFile: 'platform': platformInput, 'configuration': configurationInput, 'useTestCaseFilterInResponseFile': useTestCaseFilterInResponseFile, - 'TestCaseFilterOutputFile' : testCaseFilterOutputFile ? testCaseFilterOutputFile : "" + 'testCaseFilterOutputFile' : testCaseFilterOutputFile ? testCaseFilterOutputFile : "", + 'isCustomEngineEnabled' : String(!utils.Helper.isNullOrWhitespace(tiaConfig.userMapFile)) }, silent: null, failOnStdErr: null, @@ -396,7 +395,7 @@ function publishCodeChanges(testCaseFilterFile: string): Q.Promise { 'baselinefile': tiaConfig.baseLineBuildIdFile, 'context': tiaConfig.context, 'filter': pathFilters, - 'UserMapFile': tiaConfig.userMapFile ? tiaConfig.userMapFile : "", + 'userMapFile': tiaConfig.userMapFile ? tiaConfig.userMapFile : "", 'testCaseFilterResponseFile': testCaseFilterFile ? testCaseFilterFile : "" }, silent: null, @@ -946,7 +945,7 @@ function getTIALevel() { function responseContainsNoTests(filePath: string): Q.Promise { return utils.Helper.readFileContents(filePath, 'utf-8').then(function (resp) { - if (resp === '/Tests:' || resp === '/TestCaseFilter:') { + if (resp === '/Tests:"' || resp === '/Tests:' || resp === '/TestCaseFilter:') { return true; } else {