Skip to content

Commit a7310bf

Browse files
committed
(vsix) add unit tests support for Vsix
1 parent 9734163 commit a7310bf

File tree

8 files changed

+596
-106
lines changed

8 files changed

+596
-106
lines changed

build/pack.cake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ Task("Test")
8686
};
8787

8888
Parallel.Invoke(options, actions.ToArray());
89-
90-
var workDir = "./src/GitVersionVsixTask";
91-
var npmSettings = new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "test" };
92-
npmSettings.Arguments.Add($"--reporter-options mochaFile={MakeAbsolute(new FilePath($"{testResultsPath}vsix.results.xml"))}");
93-
NpmRunScript(npmSettings);
9489
}
90+
91+
var workDir = "./src/GitVersionVsixTask";
92+
var npmSettings = new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "test" };
93+
npmSettings.Arguments.Add($"--reporter-options mochaFile={MakeAbsolute(new FilePath($"{testResultsPath}vsix.results.xml"))}");
94+
NpmRunScript(npmSettings);
9595
})
9696
.ReportError(exception =>
9797
{

src/GitVersionVsixTask/GitVersion.ts

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import tl = require('azure-pipelines-task-lib/task');
2-
import tr = require('azure-pipelines-task-lib/toolrunner');
3-
import path = require('path');
4-
import os = require('os');
1+
import * as path from 'path';
2+
import * as os from 'os';
3+
4+
import * as tl from 'azure-pipelines-task-lib/task';
5+
import * as tr from 'azure-pipelines-task-lib/toolrunner';
56

67
export class GitVersionTask {
78
execOptions: tr.IExecOptions;
@@ -15,31 +16,26 @@ export class GitVersionTask {
1516
additionalArguments: string;
1617
targetPath: string;
1718
sourcesDirectory: string;
18-
currentDirectory: string;
19-
workingDirectory: string;
2019
gitVersionPath: string;
2120
runtime: string;
2221

2322
constructor() {
24-
this.preferBundledVersion = tl.getBoolInput('preferBundledVersion') || true;
23+
24+
this.targetPath = tl.getInput('targetPath');
2525

2626
this.useConfigFile = tl.getBoolInput('useConfigFile');
2727
this.configFilePath = tl.getInput('configFilePath');
2828

2929
this.updateAssemblyInfo = tl.getBoolInput('updateAssemblyInfo');
3030
this.updateAssemblyInfoFilename = tl.getInput('updateAssemblyInfoFilename');
3131

32-
this.additionalArguments = tl.getInput('additionalArguments');
33-
this.targetPath = tl.getInput('targetPath');
34-
this.runtime = tl.getInput('runtime') || "core";
32+
this.preferBundledVersion = tl.getBoolInput('preferBundledVersion');
33+
this.runtime = tl.getInput('runtime') || 'core';
3534
this.gitVersionPath = tl.getInput('gitVersionPath');
3635

37-
this.sourcesDirectory = tl.getVariable("Build.SourcesDirectory");
36+
this.additionalArguments = tl.getInput('additionalArguments');
3837

39-
this.currentDirectory = __dirname;
40-
this.workingDirectory = !this.targetPath
41-
? this.sourcesDirectory
42-
: path.join(this.sourcesDirectory, this.targetPath);
38+
this.sourcesDirectory = tl.getVariable('Build.SourcesDirectory').replace(/\\/g, '/');
4339

4440
this.execOptions = {
4541
cwd: undefined,
@@ -55,9 +51,10 @@ export class GitVersionTask {
5551

5652
public async execute() {
5753
try {
54+
let workingDirectory = this.getWorkingDirectory(this.targetPath);
5855
let exe = this.getExecutable();
5956
exe.arg([
60-
this.workingDirectory,
57+
workingDirectory,
6158
"/output",
6259
"buildserver",
6360
"/nofetch"]);
@@ -67,7 +64,7 @@ export class GitVersionTask {
6764
exe.arg(["/config", this.configFilePath]);
6865
}
6966
else {
70-
throw 'GitVersion configuration file not found at ' + this.configFilePath;
67+
throw new Error('GitVersion configuration file not found at ' + this.configFilePath);
7168
}
7269
}
7370

@@ -77,7 +74,7 @@ export class GitVersionTask {
7774
exe.arg(this.updateAssemblyInfoFilename);
7875
}
7976
else {
80-
throw 'AssemblyInfoFilename file not found at ' + this.updateAssemblyInfoFilename;
77+
throw new Error('AssemblyInfoFilename file not found at ' + this.updateAssemblyInfoFilename);
8178
}
8279
}
8380

@@ -87,14 +84,14 @@ export class GitVersionTask {
8784

8885
const result = await exe.exec(this.execOptions);
8986
if (result) {
90-
tl.setResult(tl.TaskResult.Failed, "An error occured during GitVersion execution")
87+
tl.setResult(tl.TaskResult.Failed, "An error occured during GitVersion execution");
9188
} else {
92-
tl.setResult(tl.TaskResult.Succeeded, "GitVersion executed successfully")
89+
tl.setResult(tl.TaskResult.Succeeded, "GitVersion executed successfully");
9390
}
9491
}
9592
catch (err) {
9693
tl.debug(err.stack);
97-
tl.setResult(tl.TaskResult.Failed, err);
94+
tl.setResult(tl.TaskResult.Failed, err, true);
9895
}
9996
}
10097

@@ -124,13 +121,37 @@ export class GitVersionTask {
124121
}
125122

126123
public getExecutablePath(exeName:string) {
127-
if (this.gitVersionPath){
128-
return this.gitVersionPath;
129-
} else if (this.preferBundledVersion) {
130-
return path.join(this.currentDirectory, this.runtime, exeName);
124+
let exePath;
125+
if (this.preferBundledVersion) {
126+
let currentDirectory = __dirname;
127+
exePath = path.join(currentDirectory, this.runtime, exeName);
128+
} else {
129+
if (tl.filePathSupplied('gitVersionPath') && tl.exist(this.gitVersionPath) && tl.stats(this.gitVersionPath).isFile()) {
130+
exePath = this.gitVersionPath;
131+
} else{
132+
throw new Error('GitVersion executable not found at ' + this.gitVersionPath);
133+
}
134+
}
135+
136+
return exePath.replace(/\\/g, '/');
137+
}
138+
139+
public getWorkingDirectory(targetPath: string) {
140+
let workDir;
141+
142+
if (!targetPath){
143+
workDir = this.sourcesDirectory;
144+
} else {
145+
if (tl.exist(targetPath) && tl.stats(targetPath).isDirectory()) {
146+
workDir = path.join(this.sourcesDirectory, targetPath);
147+
}
148+
else {
149+
throw new Error('Directory not found at ' + targetPath);
150+
}
131151
}
152+
return workDir.replace(/\\/g, '/');
132153
}
133154
}
134155

135-
var exe = new GitVersionTask();
136-
exe.execute().catch((reason) => tl.setResult(tl.TaskResult.Failed, reason));
156+
var task = new GitVersionTask();
157+
task.execute().catch((reason) => tl.setResult(tl.TaskResult.Failed, reason));

src/GitVersionVsixTask/GitVersionTask/task.json

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,83 +25,85 @@
2525
}],
2626
"instanceNameFormat": "GitVersion",
2727
"inputs": [{
28-
"name": "runtime",
29-
"type": "radio",
30-
"label": "Runtime",
31-
"defaultValue": "core",
32-
"required": true,
33-
"options": {
34-
"core": "dotnet core",
35-
"full": "dotnet fullframework (or mono)"
28+
"name": "runtime",
29+
"type": "radio",
30+
"label": "Runtime",
31+
"defaultValue": "core",
32+
"required": true,
33+
"options": {
34+
"core": "dotnet core",
35+
"full": "dotnet fullframework (or mono)"
36+
},
37+
"helpMarkDown": "Specify the runtime used for running the tool"
38+
}, {
39+
"name": "preferBundledVersion",
40+
"type": "boolean",
41+
"label": "Prefer bundled GitVersion",
42+
"defaultValue": "true",
43+
"required": false,
44+
"helpMarkDown": "If checked it will prefer the bundled version over a version found in path"
45+
}, {
46+
"name": "gitVersionPath",
47+
"type": "string",
48+
"label": "Path to GitVersion",
49+
"defaultValue": "",
50+
"required": false,
51+
"helpMarkDown": "Optionally supply the path to GitVersion",
52+
"visibleRule": "preferBundledVersion = true"
3653
},
37-
"helpMarkDown": "Specify the runtime used for running the tool"
38-
}, {
39-
"name": "preferBundledVersion",
40-
"type": "boolean",
41-
"label": "Prefer bundled GitVersion",
42-
"defaultValue": "true",
43-
"required": false,
44-
"helpMarkDown": "If checked it will prefer the bundled version over a version found in path"
45-
}, {
46-
"name": "useConfigFile",
47-
"type": "boolean",
48-
"label": "Specify Configuration file",
49-
"defaultValue": "false",
50-
"required": false,
51-
"helpMarkDown": "Whether to use a custom configuration file"
52-
}, {
53-
"name": "configFilePath",
54-
"type": "filePath",
55-
"label": "Configuration file",
56-
"defaultValue": "",
57-
"required": false,
58-
"helpMarkDown": "Optional path to config file (defaults to GitVersion.yml)",
59-
"visibleRule": "useConfigFile = true"
60-
}, {
61-
"name": "updateAssemblyInfo",
62-
"type": "boolean",
63-
"label": "Update AssemblyInfo files",
64-
"defaultValue": "false",
65-
"required": false,
66-
"helpMarkDown": "Whether to update versions in the AssemblyInfo files"
67-
}, {
68-
"name": "updateAssemblyInfoFilename",
69-
"type": "string",
70-
"label": "Update Assembly File",
71-
"defaultValue": "",
72-
"required": false,
73-
"helpMarkDown": "Update versions in specified file",
74-
"visibleRule": "updateAssemblyInfo = true"
75-
}, {
76-
"name": "gitVersionPath",
77-
"type": "string",
78-
"label": "Path to GitVersion",
79-
"defaultValue": "",
80-
"required": false,
81-
"helpMarkDown": "Optionally supply the path to GitVersion",
82-
"groupName": "gitversionDetails"
83-
}, {
84-
"name": "targetPath",
85-
"type": "string",
86-
"label": "Working directory path",
87-
"defaultValue": "",
88-
"required": false,
89-
"helpMarkDown": "Optionally supply the path to the working directory",
90-
"groupName": "gitversionDetails"
91-
}, {
92-
"name": "additionalArguments",
93-
"type": "string",
94-
"label": "Additional GitVersion arguments",
95-
"defaultValue": "",
96-
"required": false,
97-
"helpMarkDown": "Additional arguments to send to GitVersion",
98-
"groupName": "additional"
99-
}],
54+
{
55+
"name": "useConfigFile",
56+
"type": "boolean",
57+
"label": "Specify Configuration file",
58+
"defaultValue": "false",
59+
"required": false,
60+
"helpMarkDown": "Whether to use a custom configuration file"
61+
}, {
62+
"name": "configFilePath",
63+
"type": "filePath",
64+
"label": "Configuration file",
65+
"defaultValue": "",
66+
"required": false,
67+
"helpMarkDown": "Optional path to config file (defaults to GitVersion.yml)",
68+
"visibleRule": "useConfigFile = true"
69+
}, {
70+
"name": "updateAssemblyInfo",
71+
"type": "boolean",
72+
"label": "Update AssemblyInfo files",
73+
"defaultValue": "false",
74+
"required": false,
75+
"helpMarkDown": "Whether to update versions in the AssemblyInfo files"
76+
}, {
77+
"name": "updateAssemblyInfoFilename",
78+
"type": "string",
79+
"label": "Update Assembly File",
80+
"defaultValue": "",
81+
"required": false,
82+
"helpMarkDown": "Update versions in specified file",
83+
"visibleRule": "updateAssemblyInfo = true"
84+
}, {
85+
"name": "targetPath",
86+
"type": "string",
87+
"label": "Working directory path",
88+
"defaultValue": "",
89+
"required": false,
90+
"helpMarkDown": "Optionally supply the path to the working directory",
91+
"groupName": "gitversionDetails"
92+
}, {
93+
"name": "additionalArguments",
94+
"type": "string",
95+
"label": "Additional GitVersion arguments",
96+
"defaultValue": "",
97+
"required": false,
98+
"helpMarkDown": "Additional arguments to send to GitVersion",
99+
"groupName": "additional"
100+
}
101+
],
100102
"execution": {
101103
"Node": {
102104
"target": "GitVersion.js",
103105
"argumentFormat": "",
104106
"workingDirectory": "."
105107
}
106108
}
107-
}
109+
}

src/GitVersionVsixTask/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"build": "tsc && tsc --p tests/tsconfig.json && copy-node-modules . GitVersionTask",
9-
"test": "mocha tests/_suite.js --reporter mocha-junit-reporter",
9+
"test": "mocha tests/test-suite.js",
1010
"package": "tfx extension create --manifest-globs vss-extension.json"
1111
},
1212
"author": "",

0 commit comments

Comments
 (0)