-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathenotsup.spec.js
More file actions
46 lines (42 loc) · 1.29 KB
/
enotsup.spec.js
File metadata and controls
46 lines (42 loc) · 1.29 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
const fs = require('fs');
const glob = require('../');
const path = require('path');
describe('enotsup', () => {
beforeEach(() => {
process.chdir(__dirname + '/fixtures');
const readdir = fs.readdir;
spyOn(fs, 'readdir').and.callFake(function (p, opts, cb) {
if (allowedDirs.indexOf(path.resolve(p)) === -1 && !p.match(/[\\\/]node_modules[\\\/]/)) {
setTimeout(() => {
sawAsyncENOTSUP = true;
er = new Error('ENOTSUP: Operation not supported');
er.path = path;
er.code = 'ENOTSUP';
return cb(er);
})
} else {
readdir.call(fs, p, opts, cb);
}
});
});
let sawAsyncENOTSUP = false;
const fixtureDir = path.resolve(__dirname, 'fixtures');
const allowedDirs = [
path.resolve(fixtureDir),
path.resolve(fixtureDir, 'a'),
path.resolve(fixtureDir, 'a', 'abcdef'),
path.resolve(fixtureDir, 'a', 'abcfed'),
path.resolve(fixtureDir, 'a', 'abcdef', 'g'),
path.resolve(fixtureDir, 'a', 'abcfed', 'g')
];
const pattern = 'a/**/h';
it(pattern, done => {
glob('.', {pattern}, (er, res) => {
expect(er).toBeFalsy();
expect(sawAsyncENOTSUP).toBeTruthy();
res.sort();
expect(res).toEqual([ 'a/abcdef/g/h', 'a/abcfed/g/h' ]);
done();
});
});
});