Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom map support #4467

Merged
merged 10 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tasks/VsTest/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "./"
},
{
Expand Down
2 changes: 2 additions & 0 deletions Tasks/VsTest/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ export interface TiaConfiguration {
isPrFlow: string;
context: string;
useTestCaseFilterInResponseFile: string;
userMapFile: string;
disableEnablingDataCollector: boolean;
}
2 changes: 1 addition & 1 deletion Tasks/VsTest/settingshelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions Tasks/VsTest/taskinputparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,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.disabletiadatacollector') && tl.getVariable('tia.disabletiadatacollector').toUpperCase() === 'TRUE') {
tiaConfiguration.disableEnablingDataCollector = true;
} else {
tiaConfiguration.disableEnablingDataCollector = false;
}

return tiaConfiguration;
}
69 changes: 50 additions & 19 deletions Tasks/VsTest/vstest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function uploadTestResults(testResultsDirectory: string): Q.Promise<string> {
return defer.promise;
}

function generateResponseFile(discoveredTests: string): Q.Promise<string> {
function generateResponseFile(discoveredTests: string, testCaseFilterOutputFile: string): Q.Promise<string> {
const startTime = perf();
let endTime: number;
let elapsedTime: number;
Expand Down Expand Up @@ -304,7 +304,9 @@ function generateResponseFile(discoveredTests: string): Q.Promise<string> {
'context': tiaConfig.context,
'platform': platformInput,
'configuration': configurationInput,
'useTestCaseFilterInResponseFile': useTestCaseFilterInResponseFile
'useTestCaseFilterInResponseFile': useTestCaseFilterInResponseFile,
'testCaseFilterOutputFile' : testCaseFilterOutputFile ? testCaseFilterOutputFile : "",
'isCustomEngineEnabled' : String(!utils.Helper.isNullOrWhitespace(tiaConfig.userMapFile))
},
silent: null,
failOnStdErr: null,
Expand All @@ -326,7 +328,7 @@ function generateResponseFile(discoveredTests: string): Q.Promise<string> {
return defer.promise;
}

function publishCodeChanges(): Q.Promise<string> {
function publishCodeChanges(testCaseFilterFile: string): Q.Promise<string> {
const startTime = perf();
let endTime: number;
let elapsedTime: number;
Expand Down Expand Up @@ -392,7 +394,9 @@ function publishCodeChanges(): Q.Promise<string> {
'rebaselimit': rebaseLimit,
'baselinefile': tiaConfig.baseLineBuildIdFile,
'context': tiaConfig.context,
'filter': pathFilters
'filter': pathFilters,
'userMapFile': tiaConfig.userMapFile ? tiaConfig.userMapFile : "",
'testCaseFilterResponseFile': testCaseFilterFile ? testCaseFilterFile : ""
},
silent: null,
failOnStdErr: null,
Expand Down Expand Up @@ -465,9 +469,9 @@ function executeVstest(testResultsDirectory: string, parallelRunSettingsFile: st
return defer.promise;
}

function getVstestTestsList(vsVersion: number): Q.Promise<string> {
function getVstestTestsListInternal(vsVersion: number, testCaseFilter: string, outputFile: string): Q.Promise<string> {
const defer = Q.defer<string>();
const tempFile = path.join(os.tmpdir(), uuid.v1() + '.txt');
const tempFile = outputFile;
tl.debug('Discovered tests listed at: ' + tempFile);
const argsArray: string[] = [];

Expand All @@ -486,8 +490,8 @@ function getVstestTestsList(vsVersion: number): Q.Promise<string> {

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)) {
Expand Down Expand Up @@ -525,13 +529,26 @@ function getVstestTestsList(vsVersion: number): Q.Promise<string> {
return defer.promise;
}

function cleanFiles(responseFile: string, listFile: string): void {
function getVstestTestsList(vsVersion: number): Q.Promise<string> {
const defer = Q.defer<string>();
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 {
Expand All @@ -541,14 +558,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<number> {
const defer = Q.defer<number>();
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.');
Expand All @@ -569,7 +600,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);
});
Expand All @@ -578,7 +609,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion
defer.resolve(code);
})
.finally(function () {
cleanFiles(responseFile, listFile);
cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput);
});
} else {
responseContainsNoTests(responseFile)
Expand All @@ -597,7 +628,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);
});
Expand All @@ -621,7 +652,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);
});
Expand All @@ -630,7 +661,7 @@ function runVStest(testResultsDirectory: string, settingsFile: string, vsVersion
defer.resolve(code);
})
.finally(function () {
cleanFiles(responseFile, listFile);
cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput);
});
})
.fail(function (err) {
Expand All @@ -653,15 +684,15 @@ 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);
});
})
.fail(function (code) {
defer.resolve(code);
}).finally(function () {
cleanFiles(responseFile, listFile);
cleanFiles(responseFile, listFile, testCaseFilterFile, testCaseFilterOutput);
});
})
.fail(function (err) {
Expand Down Expand Up @@ -914,7 +945,7 @@ function getTIALevel() {

function responseContainsNoTests(filePath: string): Q.Promise<boolean> {
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 {
Expand Down