* Implemented tests.

* Tslint

* Some refactoring.

* Added one more check.

* Added tests for several more methods.

* Renamed test suite.

* Added deletion of test files.
This commit is contained in:
Anna Kocheshkova 2018-04-12 16:22:51 +03:00 коммит произвёл Max
Родитель 19c12f4090
Коммит 51329157d8
7 изменённых файлов: 614 добавлений и 16 удалений

Просмотреть файл

@ -1,5 +1,8 @@
var glob = require('glob');
var mocha = require('gulp-mocha');
var gulp = require("gulp");
var del = require("del");
var gutil = require('gulp-util');
var tslint = require("gulp-tslint");
var libtslint = require("tslint");
var runSequence = require("run-sequence");
@ -65,10 +68,47 @@ gulp.task("build", function () {
}));
});
gulp.task("default", function (callback) {
runSequence("clean", "build", "tslint", callback);
gulp.task("run-tests", function (callback) {
var tsProject = ts.createProject("tsconfig.json");
tsProject.config.files = glob.sync('./test/**/*.ts');
var globalMochaSettings = {
clearRequireCache: true,
ignoreLeaks: false,
timeout: 5000,
slow: 200,
reporter: 'spec'
};
var testFiles = tsProject.config.files.slice();
for (var i = 0; i < testFiles.length; i++) {
testFiles[i] = testFiles[i].replace(/.ts$/i, '.js');
}
gulp.src(testFiles)
.pipe(mocha(globalMochaSettings))
.once('error', function (err) {
if (callback) {
callback(err);
callback = null;
}
})
.once('end', function () {
if (callback) {
callback();
callback = null;
}
});
});
gulp.task("debug", function (callback) {
runSequence("clean", "build", callback);
});
gulp.task("test", function (callback) {
runSequence("build", "run-tests", callback);
});
gulp.task("default", function (callback) {
runSequence("clean", "build", "tslint", "test", callback);
});

273
package-lock.json сгенерированный
Просмотреть файл

@ -32,6 +32,14 @@
"through2": "2.0.3"
}
},
"@sinonjs/formatio": {
"version": "2.0.0",
"resolved": "http://registry.npmjs.org/@sinonjs/formatio/-/formatio-2.0.0.tgz",
"integrity": "sha512-ls6CAMA6/5gG+O/IdsBcblvnd8qcO/l1TYoNeAzp3wcISOxlPXQEus0mLcdwazEkWjaBdaJ3TaxmNgCLWwvWzg==",
"requires": {
"samsam": "1.3.0"
}
},
"@types/caseless": {
"version": "0.12.1",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.1.tgz",
@ -122,6 +130,11 @@
"ansi-wrap": "0.1.0"
}
},
"ansi-font": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/ansi-font/-/ansi-font-0.0.2.tgz",
"integrity": "sha1-iQMBvVhBRi/TnAt3Ca/R9SUUMzE="
},
"ansi-gray": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ansi-gray/-/ansi-gray-0.1.1.tgz",
@ -411,8 +424,7 @@
"browser-stdout": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
"integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=",
"dev": true
"integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8="
},
"btoa": {
"version": "1.2.1",
@ -656,6 +668,27 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cross-spawn": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
"integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=",
"requires": {
"lru-cache": "4.1.2",
"shebang-command": "1.2.0",
"which": "1.3.0"
},
"dependencies": {
"lru-cache": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.2.tgz",
"integrity": "sha512-wgeVXhrDwAWnIF/yZARsFnMBtdFXOg1b8RIrhilp+0iDYN4mdQcNZElDZ0e4B64BhaxeQ5zN7PMyvu7we1kPeQ==",
"requires": {
"pseudomap": "1.0.2",
"yallist": "2.1.2"
}
}
}
},
"cryptiles": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz",
@ -715,6 +748,11 @@
"es5-ext": "0.10.40"
}
},
"dargs": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/dargs/-/dargs-5.1.0.tgz",
"integrity": "sha1-7H6lDHhWTNNsnV7Bj2Yyn63ieCk="
},
"dashdash": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
@ -1001,6 +1039,20 @@
"through": "2.3.8"
}
},
"execa": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-0.8.0.tgz",
"integrity": "sha1-2NdrvBtVIX7RkP1t1J08d07PyNo=",
"requires": {
"cross-spawn": "5.1.0",
"get-stream": "3.0.0",
"is-stream": "1.1.0",
"npm-run-path": "2.0.2",
"p-finally": "1.0.0",
"signal-exit": "3.0.2",
"strip-eof": "1.0.0"
}
},
"expand-brackets": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-0.1.5.tgz",
@ -1521,6 +1573,11 @@
"is-property": "1.0.2"
}
},
"get-stream": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz",
"integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ="
},
"get-value": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz",
@ -1819,8 +1876,7 @@
"growl": {
"version": "1.10.3",
"resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz",
"integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==",
"dev": true
"integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q=="
},
"gulp": {
"version": "3.9.1",
@ -2048,6 +2104,19 @@
}
}
},
"gulp-mocha": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/gulp-mocha/-/gulp-mocha-5.0.0.tgz",
"integrity": "sha512-NIjXZLqqcw9DXIEBcfm0sP1AUDlUJJeaK9EGCH2s6lSwo5NK/cEat0Vm7XelOkxZnWl0O5Za+aM6E4jyxWxTlw==",
"requires": {
"dargs": "5.1.0",
"execa": "0.8.0",
"mocha": "4.1.0",
"npm-run-path": "2.0.2",
"plugin-error": "0.1.2",
"through2": "2.0.3"
}
},
"gulp-remote-src": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/gulp-remote-src/-/gulp-remote-src-0.4.3.tgz",
@ -2545,8 +2614,7 @@
"has-flag": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=",
"dev": true
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE="
},
"has-gulplog": {
"version": "0.1.0",
@ -2630,8 +2698,7 @@
"he": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
"dev": true
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0="
},
"hoek": {
"version": "2.16.3",
@ -3075,6 +3142,11 @@
}
}
},
"just-extend": {
"version": "1.1.27",
"resolved": "https://registry.npmjs.org/just-extend/-/just-extend-1.1.27.tgz",
"integrity": "sha512-mJVp13Ix6gFo3SBAy9U/kL+oeZqzlYYYLQBwXVBlVzIsZwBqGREnOro24oC/8s8aox+rJhtZ2DiQof++IrkA+g=="
},
"jwa": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz",
@ -3190,6 +3262,11 @@
"lodash._root": "3.0.1"
}
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.includes": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
@ -3281,6 +3358,11 @@
"lodash.escape": "3.2.0"
}
},
"lolex": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/lolex/-/lolex-2.3.2.tgz",
"integrity": "sha512-A5pN2tkFj7H0dGIAM6MFvHKMJcPnjZsOMvR7ujCjfgW5TbV6H9vb1PgxLtHvjqNZTHsUolz+6/WEO0N1xNx2ng=="
},
"lru-cache": {
"version": "2.7.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz",
@ -3468,7 +3550,6 @@
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-4.1.0.tgz",
"integrity": "sha512-0RVnjg1HJsXY2YFDoTNzcc1NKhYuXKRrBAG2gDygmJJA136Cs2QlRliZG1mA0ap7cuaT30mw16luAeln+4RiNA==",
"dev": true,
"requires": {
"browser-stdout": "1.3.0",
"commander": "2.11.0",
@ -3485,14 +3566,12 @@
"commander": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
"dev": true
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ=="
},
"supports-color": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
"integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==",
"dev": true,
"requires": {
"has-flag": "2.0.0"
}
@ -3617,6 +3696,18 @@
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
},
"nise": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/nise/-/nise-1.3.2.tgz",
"integrity": "sha512-KPKb+wvETBiwb4eTwtR/OsA2+iijXP+VnlSFYJo3EHjm2yjek1NWxHOUQat3i7xNLm1Bm18UA5j5Wor0yO2GtA==",
"requires": {
"@sinonjs/formatio": "2.0.0",
"just-extend": "1.1.27",
"lolex": "2.3.2",
"path-to-regexp": "1.7.0",
"text-encoding": "0.6.4"
}
},
"node-fetch": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz",
@ -3657,6 +3748,14 @@
"once": "1.4.0"
}
},
"npm-run-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
"integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=",
"requires": {
"path-key": "2.0.1"
}
},
"oauth-sign": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz",
@ -3900,6 +3999,11 @@
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
},
"p-finally": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
},
"p-map": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/p-map/-/p-map-1.2.0.tgz",
@ -3978,6 +4082,11 @@
"resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz",
"integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM="
},
"path-key": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz",
"integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A="
},
"path-parse": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz",
@ -3996,6 +4105,21 @@
"resolved": "https://registry.npmjs.org/path-root-regex/-/path-root-regex-0.1.2.tgz",
"integrity": "sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0="
},
"path-to-regexp": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz",
"integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=",
"requires": {
"isarray": "0.0.1"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
}
}
},
"pause-stream": {
"version": "0.0.11",
"resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz",
@ -4087,6 +4211,11 @@
"resolved": "https://registry.npmjs.org/protocols/-/protocols-1.4.6.tgz",
"integrity": "sha1-+LsmPqG1/Xp2BNJri+Ob13Z4v4o="
},
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM="
},
"pump": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/pump/-/pump-2.0.1.tgz",
@ -4510,6 +4639,16 @@
"ret": "0.1.15"
}
},
"samsam": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/samsam/-/samsam-1.3.0.tgz",
"integrity": "sha512-1HwIYD/8UlOtFS3QO3w7ey+SdSDFE4HRNLZoZRYVQefrOY3l17epswImeB1ijgJFQJodIaHcwkp3r/myBjFVbg=="
},
"sandbox": {
"version": "0.8.6",
"resolved": "https://registry.npmjs.org/sandbox/-/sandbox-0.8.6.tgz",
"integrity": "sha1-0WnxhRNgTjJ8m/HMOYgbC+xO17Y="
},
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
@ -4546,11 +4685,77 @@
}
}
},
"shebang-command": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
"integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=",
"requires": {
"shebang-regex": "1.0.0"
}
},
"shebang-regex": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz",
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM="
},
"should": {
"version": "13.2.1",
"resolved": "https://registry.npmjs.org/should/-/should-13.2.1.tgz",
"integrity": "sha512-l+/NwEMO+DcstsHEwPHRHzC9j4UOE3VQwJGcMWSsD/vqpqHbnQ+1iSHy64Ihmmjx1uiRPD9pFadTSc3MJtXAgw==",
"requires": {
"should-equal": "2.0.0",
"should-format": "3.0.3",
"should-type": "1.4.0",
"should-type-adaptors": "1.1.0",
"should-util": "1.0.0"
}
},
"should-equal": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/should-equal/-/should-equal-2.0.0.tgz",
"integrity": "sha512-ZP36TMrK9euEuWQYBig9W55WPC7uo37qzAEmbjHz4gfyuXrEUgF8cUvQVO+w+d3OMfPvSRQJ22lSm8MQJ43LTA==",
"requires": {
"should-type": "1.4.0"
}
},
"should-format": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/should-format/-/should-format-3.0.3.tgz",
"integrity": "sha1-m/yPdPo5IFxT04w01xcwPidxJPE=",
"requires": {
"should-type": "1.4.0",
"should-type-adaptors": "1.1.0"
}
},
"should-type": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/should-type/-/should-type-1.4.0.tgz",
"integrity": "sha1-B1bYzoRt/QmEOmlHcZ36DUz/XPM="
},
"should-type-adaptors": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/should-type-adaptors/-/should-type-adaptors-1.1.0.tgz",
"integrity": "sha512-JA4hdoLnN+kebEp2Vs8eBe9g7uy0zbRo+RMcU0EsNy+R+k049Ki+N5tT5Jagst2g7EAja+euFuoXFCa8vIklfA==",
"requires": {
"should-type": "1.4.0",
"should-util": "1.0.0"
}
},
"should-util": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/should-util/-/should-util-1.0.0.tgz",
"integrity": "sha1-yYzaN0qmsZDfi6h8mInCtNtiAGM="
},
"sigmund": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
"integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA="
},
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
},
"simple-git": {
"version": "1.92.0",
"resolved": "https://registry.npmjs.org/simple-git/-/simple-git-1.92.0.tgz",
@ -4559,6 +4764,20 @@
"debug": "3.1.0"
}
},
"sinon": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/sinon/-/sinon-4.5.0.tgz",
"integrity": "sha512-trdx+mB0VBBgoYucy6a9L7/jfQOmvGeaKZT4OOJ+lPAtI8623xyGr8wLiE4eojzBS8G9yXbhx42GHUOVLr4X2w==",
"requires": {
"@sinonjs/formatio": "2.0.0",
"diff": "3.3.1",
"lodash.get": "4.4.2",
"lolex": "2.3.2",
"nise": "1.3.2",
"supports-color": "5.3.0",
"type-detect": "4.0.8"
}
},
"snapdragon": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
@ -4962,6 +5181,11 @@
"resolved": "https://registry.npmjs.org/strip-bom-string/-/strip-bom-string-1.0.0.tgz",
"integrity": "sha1-5SEekiQ2n7uB1jOi8ABE3IztrZI="
},
"strip-eof": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8="
},
"supports-color": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.3.0.tgz",
@ -5004,6 +5228,19 @@
}
}
},
"test": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/test/-/test-0.6.0.tgz",
"integrity": "sha1-WYasRF7Bd1QyJRLRBLoyyKY+k44=",
"requires": {
"ansi-font": "0.0.2"
}
},
"text-encoding": {
"version": "0.6.4",
"resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz",
"integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk="
},
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
@ -5217,6 +5454,11 @@
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
"optional": true
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="
},
"typescript": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz",
@ -5576,6 +5818,11 @@
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
},
"yallist": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI="
},
"yauzl": {
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.9.1.tgz",
@ -5596,4 +5843,4 @@
}
}
}
}
}

Просмотреть файл

@ -194,7 +194,7 @@
"watch": "tsc -watch -p ./",
"lint": "tslint --project tsconfig.json -e src/*.d.ts -t verbose",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
"test": "./node_modules/.bin/mocha --reporter spec"
},
"devDependencies": {
"@types/mocha": "^2.2.42",
@ -210,6 +210,7 @@
"git-url-parse": "^8.2.0",
"gradle-to-js": "^1.1.0",
"gulp": "^3.9.1",
"gulp-mocha": "^5.0.0",
"gulp-sourcemaps": "^2.6.4",
"gulp-tslint": "^8.1.3",
"gulp-typescript": "^4.0.1",
@ -227,9 +228,13 @@
"properties": "^1.2.1",
"run-sequence": "^2.2.1",
"rx-lite": "^4.0.8",
"sandbox": "^0.8.6",
"semver": "^5.5.0",
"should": "^13.2.1",
"simple-git": "^1.92.0",
"sinon": "^4.5.0",
"temp": "^0.8.3",
"test": "^0.6.0",
"tslint": "^5.9.1",
"tslint-microsoft-contrib": "^5.0.3",
"xml2js": "^0.4.19"

237
test/fsProfileStorage.ts Normal file
Просмотреть файл

@ -0,0 +1,237 @@
import should = require('should');
import sinon = require('sinon');
import FsProfileStorage from '../src/helpers/fsProfileStorage';
import { FSUtils } from '../src/helpers/fsUtils';
import { VstsProfile } from '../src/helpers/interfaces';
import { ConsoleLogger } from '../src/log/consoleLogger';
describe('FsProfileStorage', function () {
let path;
let fs;
let sandbox: sinon.SinonSandbox;
const fakeFilePath = "./file.json";
const mockFilePath = "./mock/profilesMock.json";
const mockFilePathMalformed = "./mock/profilesMockMalformed.json";
const mockFilePathMalformedDuplicateUserIds = "./mock/profilesMockMalformedUserIds.json";
before(() => {
sandbox = sinon.sandbox.create();
path = require("path");
fs = require('fs');
});
afterEach(() => {
sandbox.restore();
});
describe('#init', () => {
let profiles: VstsProfile[];
let vstsProfileStorage: FsProfileStorage<VstsProfile>;
before(() => {
profiles = require(mockFilePath);
});
after(() => {
// Delete the file created during testing.
const absolutePath = path.resolve("test/" + fakeFilePath);
fs.unlink(absolutePath);
});
it('should create empty storage', async () => {
const absolutePath = path.resolve("test/" + fakeFilePath);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
vstsProfileStorage.init();
const existsStorage: boolean = await FSUtils.exists(absolutePath);
should.equal(existsStorage, true);
});
it('should load profiles', async () => {
const absolutePath = path.resolve("test/" + mockFilePath);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
await vstsProfileStorage.init();
const expectedActiveProfile = profiles.filter(profile => profile.isActive)[0];
const activeProfile = vstsProfileStorage.activeProfile;
should.deepEqual(activeProfile, expectedActiveProfile);
});
it('should throw error if more than one active profile', async () => {
const absolutePath = path.resolve("test/" + mockFilePathMalformed);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
return new Promise(function (resolve, reject) {
vstsProfileStorage.init().catch(error => {
should.exist(error);
resolve();
}).then(() => {
reject("the function should throw");
});
});
});
});
describe('#save', () => {
let vstsProfileStorage: FsProfileStorage<VstsProfile>;
let profiles: VstsProfile[];
const fakeProfile: VstsProfile = {
userId: "fake",
userName: "123",
displayName: "123",
isActive: true,
tenantName: ""
};
let saveProfilesStub: sinon.stub;
before(() => {
profiles = require(mockFilePath);
});
beforeEach(async () => {
const absolutePath = path.resolve("test/" + mockFilePath);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
saveProfilesStub = sandbox.stub(vstsProfileStorage, 'saveProfiles');
saveProfilesStub.resolves();
await vstsProfileStorage.init();
});
after(() => {
sandbox.restore();
});
it('should make profile active', async () => {
await vstsProfileStorage.save(fakeProfile);
const activeProfile = vstsProfileStorage.activeProfile;
should.deepEqual(activeProfile, fakeProfile);
saveProfilesStub.calledOnce.should.be.true();
});
it('should preserve active state on re-login', async () => {
const deleteSpy: sinon.spy = sandbox.spy(vstsProfileStorage, "delete");
const currentActiveProfile = profiles.filter(profile => profile.isActive)[0];
await vstsProfileStorage.save(currentActiveProfile);
deleteSpy.calledOnce.should.be.true();
const activeProfile = vstsProfileStorage.activeProfile;
should.deepEqual(activeProfile, currentActiveProfile);
saveProfilesStub.calledTwice.should.be.true();
});
});
describe('#delete', () => {
let vstsProfileStorage: FsProfileStorage<VstsProfile>;
let profiles: VstsProfile[];
let saveProfilesStub: sinon.stub;
before(() => {
profiles = require(mockFilePath);
});
beforeEach(async () => {
const absolutePath = path.resolve("test/" + mockFilePath);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
saveProfilesStub = sandbox.stub(vstsProfileStorage, 'saveProfiles');
saveProfilesStub.resolves();
await vstsProfileStorage.init();
});
after(() => {
sandbox.restore();
});
it('should delete active profile', async () => {
const activeProfile = profiles.filter(profile => profile.isActive)[0];
const deletedProfile = await vstsProfileStorage.delete(activeProfile.userId);
const currentActiveProfile = vstsProfileStorage.activeProfile;
should.deepEqual(currentActiveProfile, null);
should.deepEqual(deletedProfile, activeProfile);
saveProfilesStub.calledOnce.should.be.true();
});
it('should delete non-active profile and preserve the active one', async () => {
const nonActiveProfile = profiles.filter(profile => !profile.isActive)[0];
const activeProfile = profiles.filter(profile => profile.isActive)[0];
const deletedProfile = await vstsProfileStorage.delete(nonActiveProfile.userId);
const currentActiveProfile = vstsProfileStorage.activeProfile;
should.deepEqual(activeProfile, currentActiveProfile);
should.deepEqual(deletedProfile, nonActiveProfile);
saveProfilesStub.calledOnce.should.be.true();
});
it('should not delete the profile thats not exist', async () => {
const deletedProfile = await vstsProfileStorage.delete("fakeUserId");
should.equal(deletedProfile, null);
saveProfilesStub.called.should.be.false();
});
});
describe('#get', () => {
let vstsProfileStorage: FsProfileStorage<VstsProfile>;
let profiles: VstsProfile[];
let malformedProfiles: VstsProfile[];
before(() => {
profiles = require(mockFilePath);
malformedProfiles = require(mockFilePathMalformedDuplicateUserIds);
});
beforeEach(async () => {
const absolutePath = path.resolve("test/" + mockFilePath);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
await vstsProfileStorage.init();
});
after(() => {
sandbox.restore();
});
it('should return null if profile not found', async () => {
const foundProfile = await vstsProfileStorage.get("fakeUserId");
should.deepEqual(foundProfile, null);
});
it('should throw if more than one profile found', async () => {
const absolutePath = path.resolve("test/" + mockFilePathMalformedDuplicateUserIds);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
await vstsProfileStorage.init();
const duplicateProfile: VstsProfile = malformedProfiles[0];
return new Promise(function (resolve, reject) {
vstsProfileStorage.get(duplicateProfile.userId).catch(error => {
should.exist(error);
resolve();
}).then(() => {
reject("the function should throw");
});
});
});
it('should return valid profile', async () => {
const profile = profiles[0];
const foundProfile = await vstsProfileStorage.get(profile.userId);
should.deepEqual(foundProfile, profile);
});
});
describe('#list', () => {
let vstsProfileStorage: FsProfileStorage<VstsProfile>;
let profiles: VstsProfile[];
before(() => {
profiles = require(mockFilePath);
});
beforeEach(async () => {
const absolutePath = path.resolve("test/" + mockFilePath);
vstsProfileStorage = new FsProfileStorage(absolutePath, new ConsoleLogger());
await vstsProfileStorage.init();
});
after(() => {
sandbox.restore();
});
it('should list profiles', async () => {
const listedProfiles: VstsProfile[] = await vstsProfileStorage.list();
should.deepEqual(listedProfiles, profiles);
});
});
});

Просмотреть файл

@ -0,0 +1,23 @@
[
{
"userId": "a0021bd2-9be1-4904-b4c6-16ce9c797779",
"userName": "user1",
"displayName": "User",
"email": "v-user@microsoft.com",
"isActive": false
},
{
"userId": "a1b7cd43-5f03-40b6-8f1e-e986165cec7c",
"userName": "user2",
"displayName": "User Second",
"email": "user@gmail.com",
"isActive": false
},
{
"userId": "365a2fe6-bf2a-4418-ae2e-1738950bd4fb",
"userName": "user3",
"displayName": "User Third",
"email": "user@mail.ru",
"isActive": true
}
]

Просмотреть файл

@ -0,0 +1,23 @@
[
{
"userId": "a0021bd2-9be1-4904-b4c6-16ce9c797779",
"userName": "user1",
"displayName": "User",
"email": "v-user@microsoft.com",
"isActive": false
},
{
"userId": "a1b7cd43-5f03-40b6-8f1e-e986165cec7c",
"userName": "user2",
"displayName": "User Second",
"email": "user@gmail.com",
"isActive": true
},
{
"userId": "365a2fe6-bf2a-4418-ae2e-1738950bd4fb",
"userName": "user3",
"displayName": "User Third",
"email": "user@mail.ru",
"isActive": true
}
]

Просмотреть файл

@ -0,0 +1,23 @@
[
{
"userId": "a0021bd2-9be1-4904-b4c6-16ce9c797779",
"userName": "user1",
"displayName": "User",
"email": "v-user@microsoft.com",
"isActive": false
},
{
"userId": "a0021bd2-9be1-4904-b4c6-16ce9c797779",
"userName": "user2",
"displayName": "User Second",
"email": "user@gmail.com",
"isActive": false
},
{
"userId": "365a2fe6-bf2a-4418-ae2e-1738950bd4fb",
"userName": "user3",
"displayName": "User Third",
"email": "user@mail.ru",
"isActive": true
}
]