Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Required callbacks for user & hostname #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions osenv.js
Expand Up @@ -24,10 +24,10 @@ function memo (key, lookup, fallback) {
}
exports[key] = function (cb) {
if (cb) process.nextTick(cb.bind(null, null, val))
return val
else if (!fallback) return val
}
if (cb && !falling) process.nextTick(cb.bind(null, null, val))
return val
if (!cb && !fallback) return val
}
}

Expand Down
14 changes: 11 additions & 3 deletions test/unix.js
Expand Up @@ -26,9 +26,9 @@ process.env.SHELL = 'zsh'
tap.test('basic unix sanity test', function (t) {
var osenv = require('../osenv.js')

t.equal(osenv.user(), process.env.USER)
t.equal(osenv.user(), undefined)
t.equal(osenv.hostname(), undefined)
t.equal(osenv.home(), process.env.HOME)
t.equal(osenv.hostname(), process.env.HOSTNAME)
t.same(osenv.path(), process.env.PATH.split(':'))
t.equal(osenv.prompt(), process.env.PS1)
t.equal(osenv.tmpdir(), process.env.TMPDIR)
Expand Down Expand Up @@ -67,5 +67,13 @@ tap.test('basic unix sanity test', function (t) {
var osenv = require('../osenv.js')
t.equal(osenv.shell(), 'bash')

t.end()
osenv.user(function (err, user) {
t.equal(err, null)
t.equal(user, process.env.USER)
osenv.hostname(function (err, hostname) {
t.equal(err, null)
t.equal(hostname, process.env.HOSTNAME)
t.end()
})
})
})
15 changes: 11 additions & 4 deletions test/windows.js
Expand Up @@ -28,10 +28,9 @@ process.env.ComSpec = 'some-com'
tap.test('basic windows sanity test', function (t) {
var osenv = require('../osenv.js')

t.equal(osenv.user(),
process.env.USERDOMAIN + '\\' + process.env.USERNAME)
t.equal(osenv.user(), undefined)
t.equal(osenv.hostname(), undefined)
t.equal(osenv.home(), process.env.USERPROFILE)
t.equal(osenv.hostname(), process.env.COMPUTERNAME)
t.same(osenv.path(), process.env.Path.split(';'))
t.equal(osenv.prompt(), process.env.PROMPT)
t.equal(osenv.tmpdir(), process.env.TMPDIR)
Expand Down Expand Up @@ -70,5 +69,13 @@ tap.test('basic windows sanity test', function (t) {
var osenv = require('../osenv.js')
t.equal(osenv.shell(), 'cmd')

t.end()
osenv.user(function (err, user) {
t.equal(err, null)
t.equal(user, process.env.USERDOMAIN + '\\' + process.env.USERNAME)
osenv.hostname(function (err, hostname) {
t.equal(err, null)
t.equal(hostname, process.env.COMPUTERNAME)
t.end()
})
})
})