osSpec.js
3.3 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var expect = require('expect.js')
var os = require('os')
var osCopy = {}
var osShim
var isWin = process.platform === 'win32'
var tmpVar = isWin ? 'TEMP' : 'TMPDIR'
var tmpDir = process.env[tmpVar]
var isNode10 = (/0\.10\./).test(process.versions.node)
var shimAPI = [ 'tmpdir', 'endianness', 'platform', 'arch', 'EOL' ]
describe('os', function () {
before(function () {
if (isNode10) {
shimAPI.forEach(function (prop) {
osCopy[prop] = os[prop]
os[prop] = undefined
})
}
})
before(function () {
osShim = require('../lib/os')
})
after(function () {
if (isNode10) {
// restore members references
shimAPI.forEach(function (prop) {
os[prop] = osCopy[prop]
})
}
})
it('should be an object', function () {
expect(osShim).to.be.an('object')
})
it('should be a clone object', function () {
expect(osShim).to.not.equal(os)
})
describe('API', function () {
describe('tmpdir()', function () {
before(function () {
process.env[tmpVar] = '/custom/tmp'
})
after(function () {
process.env[tmpVar] = tmpDir
})
it('should be expose the method', function () {
expect(osShim.tmpdir).to.be.a('function')
})
it('should use the exposed shim method', function () {
expect(osShim.tmpdir).to.not.be.equal(os.tmpdir)
})
it('should have the proper temporary directory path', function () {
expect(osShim.tmpdir()).to.be.equal('/custom/tmp')
})
})
describe('endianness()', function () {
it('should be expose the method', function () {
expect(osShim.endianness).to.be.a('function')
})
it('should use the exposed shim method', function () {
expect(osShim.endianness).to.not.be.equal(os.endianness)
})
it('should return the proper endian value', function () {
expect(osShim.endianness()).to.be.an('string')
expect(osShim.endianness()).to.match(/LE|BE/)
})
})
describe('EOL', function () {
it('should be expose the method', function () {
expect(osShim.EOL).to.be.a('string')
})
it('should use the exposed shim method', function () {
expect(osShim.EOL).to.not.be.equal(os.EOL)
})
it('should return the proper EOL value', function () {
if (isWin) {
expect(osShim.EOL).to.be.equal('\n\r')
} else {
expect(osShim.EOL).to.be.equal('\n')
}
})
})
describe('platform()', function () {
it('should be expose the method', function () {
expect(osShim.platform).to.be.a('function')
})
it('should use the exposed shim method', function () {
expect(osShim.platform).to.not.be.equal(os.platform)
})
it('should return the proper EOL value', function () {
expect(osShim.platform()).to.be.equal(process.platform)
})
})
describe('arch()', function () {
it('should be expose the method', function () {
expect(osShim.arch).to.be.a('function')
})
it('should use the exposed shim method', function () {
expect(osShim.arch).to.not.be.equal(os.arch)
})
it('should return the proper EOL value', function () {
expect(osShim.arch()).to.be.equal(process.arch)
})
})
})
})