Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update detector/test to mock process.platform

  • Loading branch information...
commit 4ddb7ea8ac88edfbb83c8008caf388664b505179 1 parent db294b1
@willscott willscott authored
Showing with 16 additions and 5 deletions.
  1. +11 −2 lib/detector.js
  2. +5 −3 test/detector.test.js
View
13 lib/detector.js
@@ -22,7 +22,7 @@ var detector = module.exports;
var normalize = function(path) {
var last = path[path.length - 1];
- if (process.platform !== "win32") {
+ if (detector.platform() !== "win32") {
if (last !== '/') {
path += '/';
}
@@ -49,9 +49,18 @@ detector.tmp = function() {
var temp = process.env.TMPDIR
|| process.env.TMP
|| process.env.TEMP
- || (process.platform === "win32" ? "c:\\windows\\temp\\" : "/tmp/")
+ || (detector.platform() === "win32" ? "c:\\windows\\temp\\" : "/tmp/")
return normalize(temp);
};
+/**
+ * Returns the platform. Allows Tests to verify all behaviors.
+ *
+ * @returns {String} platform.
+ */
+detector.platform = function() {
+ return process.platform;
+};
+
detector._normalize = normalize;
View
8 test/detector.test.js
@@ -21,9 +21,11 @@ describe('detector', function() {
detector.tmp().should.eql(tmp);
});
it('should normalize windows paths correctly', function () {
- var platform_noConflict = process.platform;
+ var platform_noConflict = detector.platform;
- process.platform = 'win32';
+ detector.platform = function() {
+ return 'win32';
+ };
detector._normalize('c:\\windows\\foo\\bar\\')
.should.eql('c:\\windows\\foo\\bar\\/');
detector._normalize('c:/windows/foo/bar/')
@@ -32,7 +34,7 @@ describe('detector', function() {
.should.eql('c:/windows/foo/bar/');
detector._normalize('c:\\windows\\foo\\bar')
.should.eql('c:\\windows\\foo\\bar/');
- process.platform = platform_noConflict;
+ detector.platform = platform_noConflict;
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.