Skip to content

Commit

Permalink
Removing mock-fs; fixing deps; fixing manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
colindembovsky committed Apr 21, 2017
1 parent 8068b95 commit 14816af
Show file tree
Hide file tree
Showing 59 changed files with 815 additions and 5,916 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ ModelManifest.xml

Tasks/**/*.js
test/**/*.js
test/**/working

coverage
test/instrumented
Expand Down
4 changes: 2 additions & 2 deletions Tasks/CoverageGate/coverageGate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as tl from 'vsts-task-lib/task';
import * as vstsInterfaces from 'vso-node-api/interfaces/common/VsoBaseInterfaces';
import * as webApi from 'vso-node-api/WebApi';
import * as webApi from 'vso-node-api/webApi';

async function run() {
try {
tl.debug("Starting Coverate Gate task");
tl.debug("Starting Coverage Gate task");

var tpcUri = tl.getVariable("System.TeamFoundationCollectionUri");
var teamProject = tl.getVariable("System.TeamProject");
Expand Down
4 changes: 2 additions & 2 deletions Tasks/CoverageGate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/colindembovsky/cols-agent-tasks",
"dependencies": {
"vso-node-api": "^5.1.1",
"vsts-task-lib": "^1.1.0"
"vso-node-api": "^6.2.2-preview",
"vsts-task-lib": "^2.0.2-preview"
}
}
2 changes: 1 addition & 1 deletion Tasks/CoverageGate/task.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "0b6f0167-8389-4db8-89c6-4ae7688cd15a",
"name": "CoverateGate",
"name": "CoverageGate",
"friendlyName": "Coverage Gate",
"description": "Adds a coverage trend summary section to the build report.",
"author": "Colin Dembovsky (colinsalmcorner.com)",
Expand Down
6 changes: 3 additions & 3 deletions Tasks/ReplaceTokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"homepage": "https://github.com/colindembovsky/cols-agent-tasks",
"devDependencies": {
"minimatch": "^2.0.10",
"shelljs": "^0.5.3",
"vsts-task-lib": "^0.9.6"
"minimatch": "^3.0.3",
"shelljs": "^0.7.7",
"vsts-task-lib": "^2.0.2-preview"
}
}
2 changes: 1 addition & 1 deletion Tasks/ReplaceTokens/replaceTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function run() {
globPattern = globPattern.replace(/\\/g, "/");
}

var files = tl.glob(globPattern);
var files = tl.find(globPattern);
if (!files || files.length === 0) {
var msg = `Could not find files with glob [${globPattern}].`;
if (os.platform() !== "win32") {
Expand Down
6 changes: 3 additions & 3 deletions Tasks/Tokenizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"homepage": "https://github.com/colindembovsky/cols-agent-tasks",
"devDependencies": {
"minimatch": "^2.0.10",
"shelljs": "^0.5.3",
"vsts-task-lib": "^0.9.6"
"minimatch": "^3.0.3",
"shelljs": "^0.7.7",
"vsts-task-lib": "^2.0.2-preview"
}
}
2 changes: 1 addition & 1 deletion Tasks/Tokenizer/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"type": "pickList",
"label": "Tokenize Type",
"defaultValue": "json",
"helpMarkDown": "Type of tokenization.",
"helpMarkDown": "Type of tokenization",
"required": true,
"options": {
"Json": "Json"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/Tokenizer/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function run() {
}

// get the files
let files = tl.glob(globPattern);
let files = tl.find(globPattern);
if (!files || files.length === 0) {
let msg = `Could not find files with glob [${globPattern}].`;
if (os.platform() !== "win32") {
Expand Down
6 changes: 3 additions & 3 deletions Tasks/VersionAssemblies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"homepage": "https://github.com/colindembovsky/cols-agent-tasks",
"devDependencies": {
"minimatch": "^2.0.10",
"shelljs": "^0.5.3",
"vsts-task-lib": "^0.9.6"
"minimatch": "^3.0.3",
"shelljs": "^0.7.7",
"vsts-task-lib": "^2.0.2-preview"
}
}
2 changes: 1 addition & 1 deletion Tasks/VersionAssemblies/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"variable": "Variable"
},
"required": true,
"helpMarkDown": "."
"helpMarkDown": "The source for the version number. Defaults to the build number, but can be a build variable."
},
{
"name": "customNumberVariable",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VersionAssemblies/versionAssemblies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function run() {
// replace \ with /
globPattern = globPattern.replace(/\\/g, "/");
}
let filesToReplace = tl.glob(globPattern);
let filesToReplace = tl.find(globPattern);

if (!filesToReplace || filesToReplace.length === 0) {
tl.warning("No files found");
Expand Down
2 changes: 1 addition & 1 deletion extension-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This extension contains helpful build and release Tasks.

1. **Coverage Gate**

This task allows you to fail a release (or build) based of coverage delta. [More...](https://github.com/colindembovsky/cols-agent-tasks/tree/master/Tasks/CoverateGate)
This task allows you to fail a release (or build) based of coverage delta. [More...](https://github.com/colindembovsky/cols-agent-tasks/tree/master/Tasks/CoverageGate)

## Release Notes

Expand Down
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var istanbul = require('gulp-istanbul');
var ts = require('gulp-typescript');

function reportErr(err) {
console.log('##vso[task.logissue type=error]' + err.message);
console.log('##vso[task.complete result=failed]Failed');
//console.log('##vso[task.logissue type=error]' + err.message);
//console.log('##vso[task.complete result=failed]Failed');
}

var tsProject = ts.createProject('tsconfig.json');
Expand Down
33 changes: 18 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,30 @@
},
"homepage": "https://github.com/colindembovsky/cols-agent-tasks",
"devDependencies": {
"@types/fs-extra": "0.0.37",
"@types/mocha": "^2.2.39",
"@types/node": "^7.0.5",
"@types/gulp-mocha": "^0.0.30",
"@types/mocha": "^2.2.41",
"@types/mockery": "^1.4.29",
"@types/node": "^7.0.13",
"@types/q": "^1.0.0",
"@types/shelljs": "^0.7.0",
"assert": "^1.4.1",
"fs-extra": "^0.30.0",
"gulp": "^3.9.1",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
"gulp-typescript": "^3.1.4",
"minimatch": "^2.0.10",
"mocha-junit-reporter": "^1.12.1",
"mock-fs": "^3.11.0",
"mockery": "^1.7.0",
"gulp-mocha": "^4.3.0",
"gulp-typescript": "^3.1.6",
"minimatch": "^3.0.3",
"mocha": "^3.2.0",
"mocha-junit-reporter": "^1.13.0",
"mockery": "^2.0.0",
"path": "^0.12.7",
"shelljs": "^0.5.3",
"typescript": "^2.1.6"
"shelljs": "^0.7.7",
"typescript": "^2.2.2"
},
"main": "index.js",
"dependencies": {
"process": "^0.11.1",
"q": "^1.4.1",
"vsts-task-lib": "^0.9.20"
"process": "^0.11.9",
"q": "^1.5.0",
"vso-node-api": "6.2.2-preview",
"vsts-task-lib": "^2.0.2-preview"
}
}
6 changes: 4 additions & 2 deletions test/_testsuite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path = require('path');
import assert = require('assert');
import fse = require('fs-extra');
import ttm = require('vsts-task-lib/mock-test');

const debug = false;
Expand Down Expand Up @@ -214,7 +213,10 @@ describe('versionAssemblies', function () {
assert(tr.failed, 'should have failed');
assert.equal(tr.warningIssues.length, 0, "should have no warnings");
assert.equal(tr.errorIssues.length, 1, "should have 1 error");
assert.equal(tr.errorIssues[0], "No matches for regex [\\d+\\.\\d+\\.\\d+\\.\\d+] found in file working\\AssemblyInfo.cs");
if (!tr.errorIssues[0].startsWith("No matches for regex [\\d+\\.\\d+\\.\\d+\\.\\d+] found in file") ||
!tr.errorIssues[0].endsWith("working\\AssemblyInfo.cs")) {
done("Incorrect error message");
}

done();
});
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-lessEqual0-fails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mocks.MockWebApi.covData = {
}
]
};
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-lessThan0-succeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mocks.MockWebApi.covData = {
}
]
};
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-negdelta-succeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mocks.MockWebApi.covData = {
}
]
};
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-noauth-fails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mocks.MockWebApi.covData = {
}
]
};
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-nodata-fails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let taskPath = path.join(rootDir, 'coverageGate.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// provide mocks
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-nodelta-fails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mocks.MockWebApi.covData = {
}
]
};
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-posdelta-succeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mocks.MockWebApi.covData = {
}
]
};
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
2 changes: 1 addition & 1 deletion test/coverageGate/test-username-succeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mocks.MockWebApi.covData = {
}
]
};
tmr.registerMock('vso-node-api/WebApi', mocks.MockWebApi);
tmr.registerMock('vso-node-api/webApi', mocks.MockWebApi);

// set variables
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = "http://localhost:8080/tfs/defaultcollection";
Expand Down
63 changes: 34 additions & 29 deletions test/replaceTokens/test-atTokens.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,66 @@
import ma = require('vsts-task-lib/mock-answer');
import tmrm = require('vsts-task-lib/mock-run');
import path = require('path');
import fse = require('fs-extra');
import mockfs = require('mock-fs');
import fs = require('fs');

let rootDir = path.join(__dirname, '..', 'instrumented');
let taskPath = path.join(rootDir, 'replaceTokens.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// set up a tmp file for the test
var workingFolder = path.join(__dirname, "working");
if (!fs.existsSync(workingFolder)) {
fs.mkdirSync(workingFolder);
}
var tmpFile = path.join(workingFolder, "appsettings.config");

// provide answers for task mock
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"checkPath": {
"working": true
},
"glob": {
"working\\*.config" : [ path.join("working", "file.config") ]
"find": {
"working\\*.config" : [ tmpFile ]
}
};
tmr.setAnswers(a);

// mock the fs
let _mockfs = mockfs.fs({
"working/file.config": `
fs.writeFile(tmpFile, `
<configuration>
<appSettings>
<add key="AtSym" value="@@CUSTOM_BUILDMAJORNUM@@.@@CUSTOM_BUILDMINORNUM@@.@@CUSTOM_BUILDPATCHNUM@@" />
</appSettings>
</configuration>
`});
tmr.registerMock('fs', _mockfs);
`,
(err) => {

// set inputs
tmr.setInput('sourcePath', "working");
tmr.setInput('filePattern', '*.config');
tmr.setInput('tokenRegex', '@@(\\w+)@@');
// set inputs
tmr.setInput('sourcePath', "working");
tmr.setInput('filePattern', '*.config');
tmr.setInput('tokenRegex', '@@(\\w+)@@');

// set variables
process.env["CUSTOM_BUILDMAJORNUM"] = "1";
process.env["CUSTOM_BUILDMINORNUM"] = "2";
process.env["CUSTOM_BUILDPATCHNUM"] = "3";
// set variables
process.env["CUSTOM_BUILDMAJORNUM"] = "1";
process.env["CUSTOM_BUILDMINORNUM"] = "2";
process.env["CUSTOM_BUILDPATCHNUM"] = "3";

tmr.run();
tmr.run();

// validate the replacement
let actual = (<any>_mockfs).readFileSync('working/file.config', 'utf-8');
// validate the replacement
let actual = fs.readFileSync(tmpFile, 'utf-8');

var expected = `
var expected = `
<configuration>
<appSettings>
<add key="AtSym" value="1.2.3" />
</appSettings>
</configuration>
`;

if (actual !== expected) {
console.log(actual);
console.error("Replacement failed.");
} else {
console.log("Replacement succeeded!")
}
`;

if (actual.trim() !== expected.trim()) {
console.log(actual);
console.error("Replacement failed.");
} else {
console.log("Replacement succeeded!")
}
});

0 comments on commit 14816af

Please sign in to comment.