/
ncp-error-perm.test.js
52 lines (40 loc) · 1.4 KB
/
ncp-error-perm.test.js
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
'use strict'
// file in reference: https://github.com/jprichardson/node-fs-extra/issues/56
const fs = require('fs')
const os = require('os')
const fse = require('../../..')
const ncp = require('../../copy')
const path = require('path')
const assert = require('assert')
/* global afterEach, beforeEach, describe, it */
// skip test for windows
// eslint-disable globalReturn */
// if (os.platform().indexOf('win') === 0) return
// eslint-enable globalReturn */
describe('ncp / error / dest-permission', () => {
const TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'ncp-error-dest-perm')
const src = path.join(TEST_DIR, 'src')
const dest = path.join(TEST_DIR, 'dest')
// when we are root, then we will be able to create the subdirectory even if
// we don't have the permissions to do so, so no point in running this test
if (os.platform().indexOf('win') === 0 || os.userInfo().uid === 0) return
beforeEach(done => {
fse.emptyDir(TEST_DIR, err => {
assert.ifError(err)
done()
})
})
afterEach(done => fse.remove(TEST_DIR, done))
it('should return an error', done => {
const someFile = path.join(src, 'some-file')
fse.outputFileSync(someFile, 'hello')
fse.mkdirsSync(dest)
fs.chmodSync(dest, 0o444)
const subdest = path.join(dest, 'another-dir')
ncp(src, subdest, err => {
assert(err)
assert.strictEqual(err.code, 'EACCES')
done()
})
})
})