diff options
author | Yazhong Liu <yorkiefixer@gmail.com> | 2014-01-10 11:47:40 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-02-17 05:16:55 +0400 |
commit | 8ebe852c8f185f76eec00b24796bd96a1d76be4d (patch) | |
tree | 1b365395cb27d4c986af3b063ff3def8226c6901 /test | |
parent | d4f6f3ff83bd14fb60d3ac6392cb8eb6b1c55ce1 (diff) |
more legible error message in config.get/set
Test added by @isaacs
Closes #4458
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/npm-api-not-loaded-error.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/tap/npm-api-not-loaded-error.js b/test/tap/npm-api-not-loaded-error.js new file mode 100644 index 000000000..3fd073110 --- /dev/null +++ b/test/tap/npm-api-not-loaded-error.js @@ -0,0 +1,47 @@ +var test = require("tap").test +var npm = require("../..") +var path = require("path") +var rimraf = require("rimraf") +var npmrc = path.join(__dirname, "npmrc") +var fs = require("fs") + +test("setup", function (t) { + fs.writeFileSync(npmrc, "foo = bar\n", "ascii") + t.end() +}) + +test("calling set/get on config pre-load should throw", function (t) { + var threw = true + try { + npm.config.get("foo") + threw = false + } catch (er) { + t.equal(er.message, "npm.load() required") + } finally { + t.ok(threw, "get before load should throw") + } + + var threw = true + try { + npm.config.set("foo", "bar") + threw = false + } catch (er) { + t.equal(er.message, "npm.load() required") + } finally { + t.ok(threw, "set before load should throw") + } + + npm.load({ userconfig: npmrc }, function (er) { + if (er) + throw er + t.equal(npm.config.get("foo"), "bar") + npm.config.set("foo", "baz") + t.equal(npm.config.get("foo"), "baz") + t.end() + }) +}) + +test("cleanup", function (t) { + rimraf.sync(npmrc) + t.end() +}) |