-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
54 lines (51 loc) · 1.45 KB
/
test.js
File metadata and controls
54 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
var tape = require('tape')
var os = require('os')
var tmpdir = require('./index')
var nodeMajor = parseInt(/^v(\d+)/.exec(process.version)[1], 10)
function sandbox (vars) {
delete process.env.TEMP
delete process.env.TMPDIR
delete process.env.TMP
delete process.env.SystemRoot
delete process.env.windir
for (var key in vars) {
process.env[key] = vars[key]
}
return tmpdir()
}
tape('returns a module', function (t) {
t.equals(typeof tmpdir, 'function')
if (nodeMajor >= 4) {
t.equals(tmpdir, os.tmpdir)
}
t.end()
})
if (process.platform === 'win32') {
tape('environment order', function (t) {
t.equals(sandbox({ TEMP: 'a', TMP: 'b' }), 'a')
t.equals(sandbox({ TMP: 'b', SystemRoot: 'c' }), 'b')
t.equals(sandbox({ SystemRoot: 'c', windir: 'd' }), 'c\\temp')
t.equals(sandbox({ windir: 'd' }), 'd\\temp')
t.end()
})
tape('suffix slice', function (t) {
t.equals(sandbox({ TMP: '\\' }), '\\')
t.equals(sandbox({ TMP: '\\tmp\\' }), '\\tmp')
t.equals(sandbox({ TMP: '\\tmp:\\' }), '\\tmp:\\')
t.end()
})
} else {
tape('environment order', function (t) {
t.equals(sandbox({ TMPDIR: 'a', TMP: 'b' }), 'a')
t.equals(sandbox({ TMP: 'b', TEMP: 'c' }), 'b')
t.equals(sandbox({ TEMP: 'c' }), 'c')
t.equals(sandbox({}), '/tmp')
t.end()
})
tape('suffix slice', function (t) {
t.equals(sandbox({ TMP: '/' }), '/')
t.equals(sandbox({ TMP: '/tmp/' }), '/tmp')
t.end()
})
}