Skip to content

Commit 47d1ddb

Browse files
committed
Builds out a fresh project for a build/release task
0 parents  commit 47d1ddb

File tree

12 files changed

+610
-0
lines changed

12 files changed

+610
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.js
2+
3+
node_modules
4+
buildAndReleaseTask/tests/*.log
5+
.taskkey
6+
*.vsix

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Icon
2+
3+
Meat Grinder by Laymik from the Noun Project

buildAndReleaseTask/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import tl = require('azure-pipelines-task-lib/task');
2+
3+
async function run() {
4+
try {
5+
const inputString: string | undefined = tl.getInput('samplestring', true);
6+
if (inputString == 'bad') {
7+
tl.setResult(tl.TaskResult.Failed, 'Bad input was given');
8+
return;
9+
}
10+
console.log('Hello', inputString);
11+
}
12+
catch (err) {
13+
tl.setResult(tl.TaskResult.Failed, err.message);
14+
}
15+
}
16+
17+
run();

buildAndReleaseTask/task.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/Microsoft/azure-pipelines-task-lib/master/tasks.schema.json",
3+
"id": "ed1c80dd-0444-415a-9a79-4cbd0251e8f2",
4+
"name": "cscfg-transform",
5+
"friendlyName": "Azure Cloud Services Config Transform",
6+
"description": "Transforms Azure Cloud Service cscfg files.",
7+
"helpMarkDown": "",
8+
"category": "Utility",
9+
"author": "rezStream",
10+
"version": {
11+
"Major": 0,
12+
"Minor": 1,
13+
"Patch": 0
14+
},
15+
"instanceNameFormat": "Echo $(samplestring)",
16+
"inputs": [
17+
{
18+
"name": "samplestring",
19+
"type": "string",
20+
"label": "Sample String",
21+
"defaultValue": "",
22+
"required": true,
23+
"helpMarkDown": "A sample string"
24+
}
25+
],
26+
"execution": {
27+
"Node10": {
28+
"target": "index.js"
29+
}
30+
}
31+
}

buildAndReleaseTask/tests/_suite.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as path from 'path';
2+
import * as assert from 'assert';
3+
import * as ttm from 'azure-pipelines-task-lib/mock-test';
4+
5+
describe('Sample task tests', function () {
6+
7+
before( function() {
8+
});
9+
10+
after(() => {
11+
});
12+
13+
it('should succeed with simple inputs', function(done: MochaDone) {
14+
this.timeout(1000);
15+
16+
let tp = path.join(__dirname, 'success.js');
17+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
18+
19+
tr.run();
20+
console.log(tr.succeeded);
21+
assert.equal(tr.succeeded, true, 'should have succeeded');
22+
assert.equal(tr.warningIssues.length, 0, "should have no warnings");
23+
assert.equal(tr.errorIssues.length, 0, "should have no errors");
24+
console.log(tr.stdout);
25+
assert.equal(tr.stdout.indexOf('Hello human') >= 0, true, "should display Hello human");
26+
done();
27+
});
28+
29+
it('it should fail if tool returns 1', function(done: MochaDone) {
30+
this.timeout(1000);
31+
32+
let tp = path.join(__dirname, 'failure.js');
33+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
34+
35+
tr.run();
36+
console.log(tr.succeeded);
37+
assert.equal(tr.succeeded, false, 'should have failed');
38+
assert.equal(tr.warningIssues, 0, "should have no warnings");
39+
assert.equal(tr.errorIssues.length, 1, "should have 1 error issue");
40+
assert.equal(tr.errorIssues[0], 'Bad input was given', 'error issue output');
41+
assert.equal(tr.stdout.indexOf('Hello bad'), -1, "Should not display Hello bad");
42+
43+
done();
44+
});
45+
46+
});

buildAndReleaseTask/tests/failure.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import ma = require('azure-pipelines-task-lib/mock-answer');
2+
import tmrm = require('azure-pipelines-task-lib/mock-run');
3+
import path = require('path');
4+
5+
let taskPath = path.join(__dirname, '..', 'index.js');
6+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
tmr.setInput('samplestring', 'bad');
9+
10+
tmr.run();

buildAndReleaseTask/tests/success.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import ma = require('azure-pipelines-task-lib/mock-answer');
2+
import tmrm = require('azure-pipelines-task-lib/mock-run');
3+
import path = require('path');
4+
5+
let taskPath = path.join(__dirname, '..', 'index.js');
6+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
tmr.setInput('samplestring', 'human');
9+
10+
tmr.run();

images/extension-icon.png

23.3 KB
Loading

0 commit comments

Comments
 (0)