From 9d88920b3ede02d81c886724205cec4408d9cec4 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 30 May 2016 13:24:55 -0400 Subject: [PATCH] Continued replacement of process.env.HOME* with os.homedir() Signed-off-by: Rick Waldron --- lib/tessel/deploy.js | 5 ++--- test/unit/deployment/javascript.js | 7 +------ test/unit/preferences.js | 9 +++++++++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/tessel/deploy.js b/lib/tessel/deploy.js index a08b6643..707be424 100644 --- a/lib/tessel/deploy.js +++ b/lib/tessel/deploy.js @@ -1,4 +1,5 @@ // System Objects +var os = require('os'); var path = require('path'); // Third Party Dependencies @@ -13,8 +14,6 @@ var Preferences = require('../preferences'); var provision = require('./provision'); // jshint ignore:line var Tessel = require('./tessel'); -var isWindows = process.platform.startsWith('win'); - // Used to store local functionality and allow // exporting those definitions for testing. var exportables = {}; @@ -225,7 +224,7 @@ exportables.findProject = function(opts) { return new Promise((resolve, reject) => { var single = opts.single; var file = opts.entryPoint; - var home = process.env[isWindows ? 'USERPROFILE' : 'HOME']; + var home = os.homedir(); var checkConfiguration = false; var isDirectory = false; diff --git a/test/unit/deployment/javascript.js b/test/unit/deployment/javascript.js index e010b8f9..3bccd10b 100644 --- a/test/unit/deployment/javascript.js +++ b/test/unit/deployment/javascript.js @@ -1553,12 +1553,9 @@ exports['deploy.findProject'] = { home: function(test) { test.expect(1); - var key = /^win/.test(process.platform) ? 'USERPROFILE' : 'HOME'; - var real = process.env[key]; var fake = path.normalize('/fake/test/home/dir'); - process.env[key] = fake; - + this.homedir = sandbox.stub(os, 'homedir').returns(fake); this.lstatSync = sandbox.stub(fs, 'lstatSync', (file) => { return { isDirectory: () => { @@ -1569,8 +1566,6 @@ exports['deploy.findProject'] = { }); this.realpathSync = sandbox.stub(fs, 'realpathSync', (arg) => { - process.env[key] = real; - // Ensure that "~" was transformed test.equal(arg, path.normalize('/fake/test/home/dir/foo')); test.done(); diff --git a/test/unit/preferences.js b/test/unit/preferences.js index e5ba0da3..dbab4f3a 100644 --- a/test/unit/preferences.js +++ b/test/unit/preferences.js @@ -38,6 +38,15 @@ exports['Preferences.load'] = { test.done(); }); }, + + homedir: function(test) { + test.expect(1); + + Preferences.load().then(() => { + test.ok(this.exists.firstCall.args[0].startsWith(os.homedir())); + test.done(); + }); + } }; exports['Preferences.read'] = {