From c89d31a49d14f2238bc6672db08da697bbc57f1b Mon Sep 17 00:00:00 2001 From: Eli Doran Date: Mon, 12 Dec 2016 18:25:40 -0500 Subject: [PATCH] test: choose test path based on platform Credit: @elidoran Reviewed-By: @othiym23 PR-URL: https://github.com/npm/nopt/pull/77 --- test/basic.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/basic.js b/test/basic.js index 0e1f4c3..eb4857b 100644 --- a/test/basic.js +++ b/test/basic.js @@ -15,11 +15,26 @@ test("Empty String results in empty string, not true", function (t) { t.end() }) -test("~ path is resolved to $HOME", function (t) { +test("~ path is resolved to " + (isWin ? '%USERPROFILE%' : '$HOME'), function (t) { var path = require("path") - if (!process.env.HOME) process.env.HOME = "/tmp" - var parsed = nopt({key: path}, {}, ["--key=~/val"], 0) - t.same(parsed.key, path.resolve(process.env.HOME, "val")) + , the + + if (isWin) { + the = { + key: 'USERPROFILE', + dir: 'C:\\temp', + val: '~\\val' + } + } else { + the = { + key: 'HOME', + dir: '/tmp', + val: '~/val' + } + } + if (!process.env[the.key]) process.env[the.key] = v.dir + var parsed = nopt({key: path}, {}, ["--key=" + the.val], 0) + t.same(parsed.key, path.resolve(process.env[the.key], "val")) t.end() })