Skip to content

Commit

Permalink
Migrate PublishTestResultsV1 to Node 10 (#16664)
Browse files Browse the repository at this point in the history
* Migrate to node10

* bump version

* Fix first test

* Migrate legasy tests to common tests

* Update minimumAgentVersion

* Update task.loc.json

* update version

Co-authored-by: Tatyana Kostromskaya (Akvelon) <[email protected]>
Co-authored-by: Tatyana Kostromskaya <[email protected]>
Co-authored-by: Max Podriezov <[email protected]>
  • Loading branch information
4 people authored Aug 19, 2022
1 parent b11b006 commit 0db1b9a
Show file tree
Hide file tree
Showing 20 changed files with 367 additions and 4,493 deletions.
67 changes: 64 additions & 3 deletions Tasks/PublishTestResultsV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Q = require('q');
import assert = require('assert');
import path = require('path');
const ff = require(path.join(__dirname, '..', 'find-files-legacy.js'));
import { MockTestRunner } from 'azure-pipelines-task-lib/mock-test';

describe('PublishTestResultsV1 Find files legacy suite', function () {
this.timeout(parseInt(process.env.TASK_TEST_TIMEOUT) || 20000);
Expand Down Expand Up @@ -100,29 +101,89 @@ describe('PublishTestResultsV1 Find files legacy suite', function () {

it('Search simple pattern (relative path)', (done) => {
let relativePath = path.relative(process.cwd(), path.join(__dirname, 'data', '*.log'));
let test = ff.findFiles(path.join('L0', '..' , relativePath));
let test = ff.findFiles(path.join('L0', '..', relativePath));
assert(test.length === 2);
assert(test[0] === posixFormat(path.join(data, 'a.log')));
assert(test[1] === posixFormat(path.join(data, 'b.log')));
done();
});

it('Search pattern seperated by semi-colon(delimiter)', (done) => {
let test = ff.findFiles(path.join(data, '*.log') + ";" +path.join(data, '*.txt'));
let test = ff.findFiles(path.join(data, '*.log') + ";" + path.join(data, '*.txt'));
assert(test.length === 4);
assert(test[0] === posixFormat(path.join(data, 'a.log')));
assert(test[1] === posixFormat(path.join(data, 'b.log')));
assert(test[2] === posixFormat(path.join(data, 'a.txt')));
assert(test[3] === posixFormat(path.join(data, 'b.txt')));
done();
});

it('Search pattern seperated by semi-colon(delimiter)', (done) => {
let test = ff.findFiles(path.join(data, 'a*') + ";-:" + path.join(data, 'a.txt'));
assert(test.length === 1);
assert(test[0] === posixFormat(path.join(data, 'a.log')));
done();
});

it('Publish test results with resultFiles filter that does not match with any files', function (done: Mocha.Done) {
const testPath = path.join(__dirname, 'L0FilterDoesNotMatchAnyFile.js')
const tr: MockTestRunner = new MockTestRunner(testPath);
tr.run();

assert(tr.stderr.length == 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.invokedToolCount == 0, 'should exit before running PublishTestResults');
done();
});

it('Publish test results with resultFiles filter that matches with some files', function (done: Mocha.Done) {
const testPath = path.join(__dirname, 'L0FilterMatchesSomeFile.js')
const tr: MockTestRunner = new MockTestRunner(testPath);
tr.run();

assert(tr.stderr.length == 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.search(/##vso\[results.publish type=JUnit;mergeResults=true;resultFiles=/) >= 0, 'should publish test results.');
done();
});

it('Publish test results with resultFiles as file path', function (done: Mocha.Done) {
const testPath = path.join(__dirname, 'L0ResultFilesAsFilePath.js')
const tr: MockTestRunner = new MockTestRunner(testPath);
tr.run();

assert(tr.stderr.length == 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.search(/##vso\[results.publish type=JUnit;resultFiles=/) >= 0, 'should publish test results.');
done();
});

it('Publish test results when test result files input is not provided', function (done: Mocha.Done) {
const testPath = path.join(__dirname, 'L0InputIsNotProvided.js')
const tr: MockTestRunner = new MockTestRunner(testPath);
tr.run();

assert(tr.stdout.length > 0, 'should have written to stderr');
assert(tr.stdout.indexOf('Input required: testResultsFiles') >= 0, 'wrong error message: "' + tr.stdout + '"');
assert(tr.failed, 'task should have failed');
assert(tr.invokedToolCount == 0, 'should exit before running PublishTestResults');

done();
});

it('Publish test results when test runner type input is not provided', function (done: Mocha.Done) {
const testPath = path.join(__dirname, 'L0TestRunnerTypeIsNotProvided.js')
const tr: MockTestRunner = new MockTestRunner(testPath);
tr.run();

assert(tr.stdout.length > 0, 'should have written to stdout');
assert(tr.stdout.indexOf('Input required: testRunner') >= 0, 'wrong error message: "' + tr.stdout + '"');
assert(tr.failed, 'task should have failed');
assert(tr.invokedToolCount == 0, 'should exit before running PublishTestResults');

done();
});

});

function posixFormat(p: string): string {
Expand Down
13 changes: 13 additions & 0 deletions Tasks/PublishTestResultsV1/Tests/L0FilterDoesNotMatchAnyFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path = require('path');
import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
import * as answers from './answers';

const taskPath = path.join(__dirname, '..', 'publishtestresults.js');
const tr: TaskMockRunner = new TaskMockRunner(taskPath);

tr.setInput('testRunner', 'JUnit');
tr.setInput('testResultsFiles', '/invalid/*pattern');

tr.setAnswers(answers.defaultAnswers);

tr.run();
15 changes: 15 additions & 0 deletions Tasks/PublishTestResultsV1/Tests/L0FilterMatchesSomeFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import path = require('path');
import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
import * as answers from './answers';

const taskPath = path.join(__dirname, '..', 'publishtestresults.js');
const tr: TaskMockRunner = new TaskMockRunner(taskPath);

let pattern = path.join(__dirname, 'data', '*.log');
tr.setInput('testRunner', 'JUnit');
tr.setInput('testResultsFiles', pattern);
tr.setInput('mergeTestResults', 'true');

tr.setAnswers(answers.defaultAnswers);

tr.run();
12 changes: 12 additions & 0 deletions Tasks/PublishTestResultsV1/Tests/L0InputIsNotProvided.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path = require('path');
import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
import * as answers from './answers';

const taskPath = path.join(__dirname, '..', 'publishtestresults.js');
const tr: TaskMockRunner = new TaskMockRunner(taskPath);

tr.setInput('testRunner', 'Junit');

tr.setAnswers(answers.defaultAnswers);

tr.run();
15 changes: 15 additions & 0 deletions Tasks/PublishTestResultsV1/Tests/L0ResultFilesAsFilePath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import path = require('path');
import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
import * as answers from './answers';

const taskPath = path.join(__dirname, '..', 'publishtestresults.js');
const tr: TaskMockRunner = new TaskMockRunner(taskPath);

let pattern = path.join(__dirname, 'data', 'a.log');

tr.setInput('testRunner', 'JUnit');
tr.setInput('testResultsFiles', pattern);

tr.setAnswers(answers.defaultAnswers);

tr.run();
13 changes: 13 additions & 0 deletions Tasks/PublishTestResultsV1/Tests/L0TestRunnerTypeIsNotProvided.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path = require('path');
import { TaskMockRunner } from 'azure-pipelines-task-lib/mock-run';
import * as answers from './answers';

const taskPath = path.join(__dirname, '..', 'publishtestresults.js');
const tr: TaskMockRunner = new TaskMockRunner(taskPath);

let pattern = path.join(__dirname, 'data', 'a.log');
tr.setInput('testResultsFiles', pattern);

tr.setAnswers(answers.defaultAnswers);

tr.run();
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
import { TaskLibAnswers } from 'azure-pipelines-task-lib/mock-answer';

export const defaultAnswers: TaskLibAnswers = <TaskLibAnswers>{
"find": {
"/someDir": [
"someDir/someFile2",
Expand All @@ -12,4 +14,4 @@
],
"/invalid/*pattern": []
}
}
};
Loading

0 comments on commit 0db1b9a

Please sign in to comment.